3 ms·
I don't have a dialect of Lisp. I work on a translator from a subset of Common Lisp to JavaScript (http://common-lisp.net/project/parenscript/ http://common-lis
by sedachv 16y ago
I don't have a dialect of Lisp. I work on a translator from a subset of Common Lisp to JavaScript (http://common-lisp.net/project/parenscript/ http://common-lisp.net/project/parenscript/). In particular, this subset does not have car/cdr, or any other list manipulation functions. No one has ever complained about this.
This is map:
(defun map (fn arr)
"Call FN on each element in ARR and return the returned values in a new array."
;; In newer versions of ECMAScript, this may call Array.map, too
(let ((idx 0)
(result (array)))
(dolist (el arr)
(setf (aref result idx) (fn el))
(setf idx (1+ idx)))
(return result)))
This is reduce:
(defun reduce (func list &optional init) ;; the use of init here is actually a bit broken wrt null
(let* ((acc))
(do* ((i (if init -1 0) (1+ i))
(acc (if init init (elt list 0)) (func acc (elt list i))))
((>= i (1- (length list)))))
(return acc)))
What would a linked list data structure provide? Incompatibility with all other JavaScript code and a mandatory runtime library?
Thanks for introducing me to Nu btw. What makes you say that it is not a Lisp?
- dahlia 16y agoLisphp's map/filter/reduce functions are implemented in the same manner that Parentscript does. This is map: http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5dbc675806d8fd2c5c/Lisphp/Runtime/List.php#L98 http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5... This is filter: http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5dbc675806d8fd2c5c/Lisphp/Runtime/List.php#L129 http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5... This is fold: http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5dbc675806d8fd2c5c/Lisphp/Runtime/List.php#L142 http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5... Lisphp respect the iterator protocol of PHP instead of Lisp tradition in the practical reason.