Well, comparing your 'Lisp' interpreter against 'perl-lisp' in CPAN (lisp), I have to say that your's is a more complete implementation, and I think the more correct one. On this simple script:
>(set 'a (list 1 2 3)) Both return: (1 2 3) #Right! >(cdr a) perl-lisp returns: 3 #Wrong! Lisp returns: (2 3) #Right!
So yours wins here. I think this is because perl-lisp implements lists (1 2 3) as an array instead of an actual linked list (even though when you use 'cons' it seems to construct a proper list), so there is no real way for it to return what its supposed to. Sure, it (perl-lisp) could either shift the array, or take a list slice (which copies the array), but neither is a correct implementation of a list.

Sorry to say, though, that neither lisp's will execute my favorite Lisp function:
(defun transpose (x) (apply 'mapcar (cons 'list x)) Which on this input: (transpose '((1 2 3) (4 5 6) (7 8 9) (10 11 12))) Should product this output: ((1 4 7 10) (2 5 8 11) (3 6 9 12))
This is because neither lisp's implement the apply function, perl-lisp doesn't implement the mapcar function, and I don't think your Lisp correctly implements mapcar, because mapcar should accept any number of lists following the function, but yours only accepts one, and I think (not sure here, its been awhile since I've really done lisp) that you should have to quote the function passed in. (Every once in a while, I've thought that perl should have a mapcar function also :)

Neither have an append function, either. I would think that appending lists is something a list processing language ought to be able to do :-)
One thing in perl-lisp's favor, it does have a setq function, which your's lacks, but of course is a trivial thing and should be easy to implement if you wanted to :)

One more thing you might want to consider is using h2xs to create a normal installable perl module (where you can make/make test/make install), with some tests, like the CPAN modules, and then consider putting this on CPAN.

I've been looking at the syntax for Common Lisp and it seems I was wrong about mapcar. In Common Lisp it does only take one list argument, so this implementation of mapcar is not an incorrect one, just not a very good one (as is Common Lisp's).

In reply to RE: Lisp-In-Perl by runrig
in thread Lisp-In-Perl by jazzturk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.