News for hackers. Stuff that matters.
Re:Lisphp is a Lisp dialect written in PHP. by sedachv on Tuesday July 06, 2010 @11:46PM (#1493245)
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/). 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?

Re:Lisphp is a Lisp dialect written in PHP. by dahlia on Wednesday July 07, 2010 @06:48AM (#1493864)
Lisphp's map/filter/reduce functions are implemented in the same manner that Parentscript does.

This is map: http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5...

This is filter: http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5...

This is fold: http://github.com/dahlia/lisphp/blob/81849070ac7ff13948786b5...

Lisphp respect the iterator protocol of PHP instead of Lisp tradition in the practical reason.