go ahead... be a heretic PerlMonks

### Comment on

 Need Help??

I watched an MIT lecture on youtube demonstrating some of the abstraction power of LISP. Then I tried my hand at duplicating the functionality in Perl. Below I will post the LISP code, and the Perl equivalent.

LISP

```(DEFINE (SUM TERM A NEXT B)
(IF (> A B)
0
(+ (TERM A)
(SUM TERM
(NEXT A)
NEXT
B))))

(DEFINE (SUM-INT A B)
(DEFINE (IDENTITY X) X)
(SUM INDENTITY A 1+ B))

(DEFINE (SUM-SQ A B)
(SUM SQUARE A 1+ B))

(DEFINE (SQUARE A) (* A A))

(SUM-INT 3 5)

(SUM-SQ 3 5)

Perl

```#!/usr/bin/perl
use warnings;
use strict;
use feature "state";

sub sum # TERM A NEXT B
{
state \$sum;
my (\$TERM, \$A, \$NEXT, \$B) = @_;
if (\$A>\$B){
my \$temp=\$sum;
\$sum=0;
return \$temp ;
}
\$sum+=&{\$TERM}(\$A);
sum( \$TERM, &{\$NEXT}(\$A) ,\$NEXT, \$B);
}

sub identity{
shift;
}

sub square{
((shift)**2);
}

sub sumint { sum(\&identity,shift,sub {((shift)+1)},shift)}

sub sumsq { sum(\&square,shift,sub {((shift)+1)},shift)}

#a normal sum from 3-5
print sumint(3,5) . "\n";
#a sum of squares from 3-5
print sumsq(3,5) . "\n";

In reply to 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":

• 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.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, 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: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-05-25 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (191 votes). Check out past polls.

Notices?