[Coco] Basic Lisp

J Arcane jarcane at gmail.com
Sat Nov 15 08:59:50 EST 2014


Hey, no worries. Lisp can be a bit weird to get one's head around. To try
another angle, I guess the closest in BASIC is DEF FN. I've often seen DEF
FN used in a similar way to how Lambda is usually used, defining a math
function on the fly in a spot where it's needed. The main difference is 1)
lambdas aren't limited to just math (everything is a function in Lisps,
unlike BASIC's sub/fn split), and 2) lambdas don't have to be named, but
can exist and be applied in place as needed.

This isn't often obviously useful in other languages other than as a time
saver (when you know you'll just never use the function anywhere but in
this spot), but it comes into form best in Lisp, because Lisp has functions
that call other functions to do things.

The classic example is map, which is given a function and a list, and then
does the function to each item on the list. So if I want to square
everything on a list, I might just do (map (lambda (x) (* x x)) '(1 2 3
4)), rather than explicitly defining a square function that I only want to
use in this one spot.

On Fri, Nov 14, 2014 at 6:38 PM, Richard E Crislip <rcrislip at neo.rr.com>
wrote:

> On Wed, 12 Nov 2014 17:46:15 +0200
> J Arcane <jarcane at gmail.com> wrote:
>
> > The lambda is the anonymous function; basically the building block of
> > the math on which Lisp is based, but also seriously handy because it
> > allows you to define functions on the fly and even store them in
> > variables (all functions can be stored and passed as values in Lisp).
> > Perhaps one of the more ludicrous examples of this I've ever coded
> > personally was a virtual machine where the functions to simulate the
> > opcodes were actually stored in the same hash-table that referenced
> > them!
> >
> ><snip>
>
> Thank you for trying to explain it to me. Looks like I'll have to do
> some research on this. I was especially interested in this because I
> recently ran across it and what I read on Wikipedia left me in a fog
> too. This is by no means a judgment on your explanation, it is a
> judgment on my ignorance. Believe it or not, I ran across it in a text
> I was teaching <sigh>. Fortunately I did not have to dwell on it, but I
> HATE chewing muffins in front of students 8-S.
>
> Thanks again
>
> Richard
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list