Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: PERLISP meditations

by remiah (Hermit)
on Oct 03, 2012 at 22:25 UTC ( #997141=note: print w/ replies, xml ) Need Help??


in reply to PERLISP meditations

Hello, protist.

This is second time I saw the name 'High Order Perl'. It took me much time to remember the days with common lisp, but I tried anyway. I wonder what does mit classes uses for lisp? It seems different from common lisp...

Tested with clisp.

(defun sum_from_to(TERM from NEXT to) (IF (> from to) 0 (+ (funcall TERM from) (sum_from_to TERM (funcall NEXT from) NEXT to)))) (defun addone (c) (+ 1 c)) (defun self(x) x) (defun square (A) (* A A)) (defun sum-int (A B) (sum_from_to #'self A #'addone B)) (defun sum-sq(A B) (sum_from_to #'square A #'addone B)) (print (sum-int 3 5)) (print (sum-sq 3 5))
And exact same migration from list to perl would work.
#!/usr/bin/perl use strict; use warnings; use feature qw(say); sub sum_from_to{ my ($TERM, $from, $NEXT, $to)=@_; if( $from > $to ){ 0; } else { $TERM->($from) + sum_from_to( $TERM, $NEXT->($from), $NEXT, $to ); } } sub addone{ return 1 + $_[0]} sub self{ return $_[0]} sub square{ return $_[0] * $_[0]} sub sum_int { my($A,$B)=@_; sum_from_to( \&self, $A, \&addone, $B); } sub sum_sq { my($A,$B)=@_; sum_from_to( \&square, $A, \&addone, $B); } say sum_int(3,5); say sum_sq(3,5);
regards.


Comment on Re: PERLISP meditations
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2015-07-08 07:19 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 (96 votes), past polls