Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: PERLISP meditations by remiah
in thread PERLISP meditations by protist

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-26 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found