Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

More Lisp-In-Perl

by runrig (Abbot)
on Nov 08, 2000 at 01:16 UTC ( #40423=CUFP: print w/ replies, xml ) Need Help??

This was inspired by Lisp-In-Perl and my slight disappointment in both it and perl-lisp on CPAN. I've come up with my own implementation of Lisp-like linked-lists and functions/methods, so I could do what neither of the other lisps could, namely:
(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))
The perl version of this (which currently works!) goes like this:
use LISP qw(cons); # Create linked list (Not an array!) my $list = LISP->new([[1,2,3,4],[5,6,7,8],[9,10,11,12]]); print $list->string; # Prints ((1 2 3 4) (5 6 7 8) (9 10 11 12)) my $mapcarf = LISP->new(\&LISP::Lambda::mapcar); my $listf = LISP->new($list->can('list')); # We probably ought to go for closure on mapcarf and listf # But this is OK for now my $transpose = sub {$mapcarf->apply(cons($listf, shift))}; $list=$transpose->($list); print $list->string; # Prints ((1 5 9) (2 6 10) (3 7 11) (4 8 12)) $list=$transpose->($list); print $list->string; # Prints ((1 2 3 4) (5 6 7 8) (9 10 11 12))
It's only a matter of time before I get a full-blown lisp2perl compiler (I think). I'm looking for input on what I've got so far. Shall I post the whole thing(about 600 lines) or just upload it to CPAN?

Comment on More Lisp-In-Perl
Select or Download Code
Replies are listed 'Best First'.
RE: More Lisp-In-Perl
by KM (Priest) on Nov 08, 2000 at 01:33 UTC
    Why don't you provide a link for us to see it on your own webspace? IMO, 600 lines is a lot to post here (basically a pain to read) and don't "just" upload something to CPAN if you simply want input. I'd be interested in a link though, as well as what your module(s) does which the other ones do not, and how you have tried to collaborate with the other Lisp-ish module authors to make sure noone is making Yet Another Lisp Module :-)

    Cheers,
    KM

      Well, seeing that I don't currently have any webspace or access to upload to any public ftp site, but I do already have an account on CPAN (and can delete files if I need to), I went ahead and uploaded the file to my directory here. You'll need a PAUSE account to get to it until it makes its way around to public servers (I think thats how it works).

      This is neither a Lisp compiler nor interpreter yet, and it may be YALM, but I was dissatisfied by the other modules for such basic reasons that I thought an entirely new module was warranted.

      The module in Lisp-In-Perl was ok, but implemented lists in a way that requires its own garbage collector, which though novel, is sort of absurd when perl can take out the garbage on its own. And the perl-lisp distribution on CPAN implemented lists using arrays, which made using Lisp list functions impossible.

      And I just wanted to create a more OO way of manipulating the lists. Also I wanted to experiment with autoloading, where I came up with this recursive autoloading routine (which is but one of the things I am looking for input on):
      sub AUTOLOAD { return if $AUTOLOAD =~ /::DESTROY$/; # Autoload cadr, caddr, etc. if ($AUTOLOAD =~ /::c([ad]+)([ad])r$/) { no strict 'refs'; my $meth1 = "c$1r"; my $meth2 = "c$2r"; *{$AUTOLOAD} = sub { shift->$meth2->$meth1 }; goto &$AUTOLOAD; } carp $AUTOLOAD =~ /(.*)::(.*)$/ ? qq!Couldn't load sub/method "$2" via package "$1"! : "Couldn't load subroutine $AUTOLOAD"; }
      Update: It seems to have made its way to CPAN and can be found here. I'm thinking that maybe I should rename it as it might conflict with perl-lisp, because I forgot that some OS's are case-insensitive when it comes to file names.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2015-07-31 10:55 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 (276 votes), past polls