News for hackers. Stuff that matters.
Re:Lisphp is a Lisp dialect written in PHP. by sedachv on Monday July 05, 2010 @12:50PM (#1488586)
Since Lisphp is a new dialect, you don't need to worry about backward-compatibility. You should get rid of car/cdr entirely. There is no inherent reason for using linked lists for anything - even s-expressions. For example, no one has ever complained about the lack of car/cdr in Parenscript (although to be fair, Parenscript is not homoiconic, just a translator from CL to JS). Having a good backquote-comma templating syntax is more valuable.

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.

Re:Lisphp is a Lisp dialect written in PHP. by jacquesm on Monday July 05, 2010 @12:54PM (#1488595)
I think it's actually quite neat that it tries to stay close to the lisp code that you see in examples and books about lisp.
Re:Lisphp is a Lisp dialect written in PHP. by sedachv on Monday July 05, 2010 @03:19PM (#1488882)
What's the point of sacrificing something like platform integration for car/cdr? Anyone who is going to want to use Lisphp for real work is not going to have a problem writing their code to use arrays. Anyone who thinks that car/cdr is more valuable than platform integration is not going to use Lisphp for real work. And everyone else will come by and say "Lisphp has those weird car/cdr and it can't even work with PHP libraries without glue code, Lisp is a toy."
Re:Lisphp is a Lisp dialect written in PHP. by KirinDave on Monday July 05, 2010 @04:28PM (#1489028)
Call them what you want. First/car & rest/cdr are the classic tool for writing code that iterates across datasets.
Re:Lisphp is a Lisp dialect written in PHP. by sedachv on Monday July 05, 2010 @11:03PM (#1489818)
Recursion, map, and fold can be used for iteration. car/cdr is just one way to access elements of a sequence.
Re:Lisphp is a Lisp dialect written in PHP. by KirinDave on Tuesday July 06, 2010 @02:44AM (#1490193)
Think about what you just said and why it's not a valid rebuttal. I know you know better.

Hint: via recursion, how do you advance along a sequence in a collection-agnostic way?

Re:Lisphp is a Lisp dialect written in PHP. by sedachv on Tuesday July 06, 2010 @11:35AM (#1491264)
So now iterators mean car/cdr is "classic" so it should be present in all Lisp dialects from here to eternity?
Re:Lisphp is a Lisp dialect written in PHP. by KirinDave on Tuesday July 06, 2010 @12:37PM (#1491486)
Again, you can call them "first" and "rest" if you like.

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.

Re:Lisphp is a Lisp dialect written in PHP. by sedachv on Tuesday July 06, 2010 @04:11PM (#1492202)
So all those other programming languages that come with arrays and not linked lists are completely useless? Mildly useless? Only kind of useless? Or is it the case that it really doesn't matter?
Re:Lisphp is a Lisp dialect written in PHP. by KirinDave on Tuesday July 06, 2010 @05:05PM (#1492377)
Most of them DO provide a way to do this. For example, Ruby is array based but provides a way to do this through enum. The lispish way is first/rest. Clojure, a lisp with very novel data structures, does this just fine even with associative arrays and vectors. It introduces a seq abstraction to support it.

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?

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.

Re:Lisphp is a Lisp dialect written in PHP. by jrockway on Monday July 05, 2010 @08:03PM (#1489488)
There is no inherent reason for using linked lists for anything

Uh, constant-time insertions?

Re:Lisphp is a Lisp dialect written in PHP. by sedachv on Monday July 05, 2010 @11:01PM (#1489814)
Did you read the parent post?