[Added map and map-into attila.lendvai@gmail.com**20060705182351] hunk ./src/js.lisp 1068 + +(defjsmacro map-into (function array) + "Call FUNCTION on each element in ARRAY, replace element with the return value." + ;; be friendly to both (map-into 'foo array) and (map-into foo array) calls + (when (and (listp function) + (eq 'quote (first function))) + (setf function (eval function))) + (with-unique-js-names (arrvar idx fn) + `((lambda () + (let ((,arrvar ,array) + (,fn ,function)) + (do ((,idx 0 (1+ ,idx))) + ((>= ,idx (slot-value ,arrvar 'length))) + (setf (aref ,arrvar ,idx) (,fn (aref ,arrvar ,idx))))) + (return array))))) + +(defjsmacro map (function array) + "Call FUNCTION on each element in ARRAY and return the returned values in a new array." + ;; be friendly to both (map 'foo array) and (map foo array) calls + (when (and (listp function) + (eq 'quote (first function))) + (setf function (eval function))) + (with-unique-js-names (arrvar result idx fn) + `((lambda () + (let ((,arrvar ,array) + (,fn ,function) + (,result (make-array (slot-value ,arrvar 'length)))) + (do ((,idx 0 (1+ ,idx))) + ((>= ,idx (slot-value ,arrvar 'length))) + (setf (aref ,result ,idx) (,fn (aref ,arrvar ,idx))))) + (return ,result)))))