Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Lisp-In-Perl

by jazzturk (Novice)
on Oct 27, 2000 at 08:18 UTC ( #38772=CUFP: print w/ replies, xml ) Need Help??

I just finished writing a dynamically-scoped Lisp interpreter in Perl. Don't hate me. I couldn't help myself. URI is in my .sig below:

James Bailie http://jazzturkey.net

Comment on Lisp-In-Perl
RE: Lisp-In-Perl
by merlyn (Sage) on Oct 27, 2000 at 10:44 UTC
RE: Lisp-In-Perl
by elwarren (Curate) on Oct 30, 2000 at 04:57 UTC
    This is just wrong :-)

    LISP=Lisp InSide Perl
    LISP=Lisp Isn't Supposed to be in Perl
    PERL=Perl Even Runs Lisp
RE: Lisp-In-Perl
by runrig (Abbot) on Oct 31, 2000 at 00:55 UTC
    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).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://38772]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2015-07-02 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (40 votes), past polls