Someone wrote a post I agree about this.
http://groups.google.com/group/lisphp
Join us if you are interested in this project!
$env['echo'] = new Lisphp_Runtime_PHPFunction(create_function('', '
$args = func_get_args();
foreach ($args as $arg) echo $arg;
'));
after: $env = Lisphp_Environment::full(); (car (cdr (cdr (cdr list))))
you should just do: (at list 3)The bigger problem is in code that consumes the lists item by item, every time an extra copy of the remainder of the list will be made, there it is much harder to work around this.
Very neat code by the way, thanks a ton for making this.
I'll be playing around with it for a bit, I've written a chunk of code for a small site a while ago in a 'functional' PHP style (as in, no assignments except at the highest level), I'll see if I can convert that project to your lisp dialect and get it to work.
You should even get rid of a custom type for Lisphp sequences and use PHP arrays directly. Ditto all other datatypes. Then if you use PHP's calling convention you should be able to call PHP code directly without needing USE and FROM, and more importantly PHP code can do the same to Lisphp with minimal pain. That way writing Lisphp libraries for others to use becomes viable.
Hint: via recursion, how do you advance along a sequence in a collection-agnostic way?
It is the ability to decompose an arbitrary sequential data structure efficiently that is important. It's not important because of any historical bias; it's important because it is incredibly useful.
If you can't support first/rest in an efficient manner, it is a bad sign.
It's important when you need to write your own iteration primitives. Map, fold, etc are all well and good, but sometimes they won't do because the iteration may require some unusual steps.
In your particular dialect of lisp, what does the code for writing map or fold look like? The one that doesn't copy memory egregiously, that is. And how bad must the performance of javascript linked lists be to scare you away from them so damn hard, anyways?
Or perhaps, what you're supporting is a "lispish" language that isn't really something we should directly compare to lisp, in the vein of Nu?
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?
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.
http://dahlia.ruree.net/try-lisphp/
Well, of course, it uses a sandbox environment.
[Edit:
Question: Why does it have T, NIL, #T and #F? what roles do these symbols play in the language; which ones are canonical truth values, which ones signify list termination, and which ones signify the empty value? This is the perennial Lisp question.]
Is this a jab at the Lisp tradition of compiled sublanguages?
A lame, wasteful little script to print out a TODO list ;-)
(defun map-print (item list)
(mapcar (lambda (x)
(format t "~a in ~a~%" item x)) list))
(defun permute (list)
(mapcar (lambda (x)
(map-print x list)) list))
(defun languages ()
(destructuring-bind (response headers body)
(trivial-http:http-get "http://mahmud.arablug.org/languages.txt")
(when (= response 200)
(loop for line = (read-line body nil nil)
while line
collecting line))))
(permute (languages))Do you want to see “bad” stack traces? Try Erlang. There is a language with truly obtuse stack traces.