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.
Uh, constant-time insertions?