From: Dirt
Subject: [Q]: Help with lambda
Date: 
Message-ID: <eog69sk5bh7n5tqq7dp0igc8q6va7pt0kt@4ax.com>
Hello,
  I wrote the following lamda expression below:

( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6  ) )

This function seems to work fine when I use CLisp for Windows.
However, when I type the same expression into GCL on my unix box, I
get the following error:

>>( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6 ) )

Error: The function LAMBDA is undefined.
Fast links are on: do (si::use-fast-links nil) for debugging
Error signalled by EVALHOOK.
Backtrace: system:universal-error-handler > evalhook > MAPCAR

I don't understand where I am going wrong.  Anyhelp would be great.
Thanks alot,
 
Dirt

From: His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated
Subject: Re: [Q]: Help with lambda
Date: 
Message-ID: <w4oiu0c389s.fsf@nemesis.irtnog.org>
>>>>> "D" == Dirt  <····@inam3.com> writes:

    D> ( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6 ) )

Dirt, you really need to stop formatting your expressions so
unreadably.  A better way to write this out (both in email and in a
source file) might be as follows:

(mapcar (lambda (x) (/ (- x 32) 1.8)) '(4 5 6))

or

(mapcar (lambda (x)
	  (/ (- x 32) 1.8))
	'(4 5 6))

It's easier to notice the level of indentation than to count parens,
as long as parens are properly matched and the indentation is (1)
consistent and (2) follows the nesting level.

In any case, on to your question.

    D> This function seems to work fine when I use CLisp for
    D> Windows. However, when I type the same expression into GCL on
    D> my unix box, I get the following error:

    D> Error: The function LAMBDA is undefined.

For some reason, the LAMBDA macro is not implemented on GCL (I have
version 2.3 installed on my Slackware box).  Here's the LAMBDA entry
from the HyperSpec (which you should be aware of; see
http://www.harlequin.com/support/books/HyperSpec/ for the front page,
then check out the symbol search page at
http://www.harlequin.com/support/books/HyperSpec/FrontMatter/Symbol-Index.html):

>Macro LAMBDA 
>
>Syntax:
>
>
>lambda lambda-list [[declaration* | documentation]] form* => function
>
>
>
>Arguments and Values:
>
>
>lambda-list---an ordinary lambda list.
>
>declaration---a declare expression; not evaluated.
>
>documentation---a string; not evaluated.
>
>form---a form.
>
>function---a function.
>
>
>Description:
>
>
>Provides a shorthand notation for a function special form involving a
>lambda expression such that:
>
>
> (lambda lambda-list [[declaration* | documentation]] form*)
> ==  (function (lambda lambda-list [[declaration* | documentation]] form*))
> ==  #'(lambda lambda-list [[declaration* | documentation]] form*)

The best thing to do is to always quote (either via FUNCTION or via
#', as show above) your LAMBDA expressions.  I've found the extra
visual cue that says "here is a function" to be most helpful when
reading through my code.

That said, the following form works in my version of GCL.  HTH.

(mapcar #'(lambda (x)
	    (/ (- x 32) 1.8))
	'(4 5 6))

P.S. If you initially learned "Lisp" by learning Scheme, you must
unlearn the notion that there is a single name space for everything.
In Common Lisp, a symbol may be bound to BOTH a function AND a value;
whether you use #' (FUNCTION) or ' (QUOTE) determines which kind of
binding you want.

-- 
JOHN CAGE (strapped to table): Do you really expect me to conduct this
 antiquated tonal system? 
LEONARD BERNSTEIN: No, Mr. Cage, I expect you to die!
From: Dirt
Subject: Re: [Q]: Help with lambda
Date: 
Message-ID: <8co69s806m4c9kact3nlg4dgrsc67388sg@4ax.com>
sorry about my formatting. i am just doing it the way I was shown in
class. i was told to place a space between the parens for
"readability" ill try and be more compliant in the future.
Thanks,
  Dirt

On 29 Jan 2000 15:58:07 -0500, "His Holiness the Reverend Doktor
Xenophon Fenderson, the Carbon(d)ated" <········@irtnog.org> wrote:

>>>>>> "D" == Dirt  <····@inam3.com> writes:
>
>    D> ( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6 ) )
>
>Dirt, you really need to stop formatting your expressions so
>unreadably.  A better way to write this out (both in email and in a
>source file) might be as follows:
>
>(mapcar (lambda (x) (/ (- x 32) 1.8)) '(4 5 6))
>
>or
>
>(mapcar (lambda (x)
>	  (/ (- x 32) 1.8))
>	'(4 5 6))
>
>It's easier to notice the level of indentation than to count parens,
>as long as parens are properly matched and the indentation is (1)
>consistent and (2) follows the nesting level.
>
>In any case, on to your question.
>
>    D> This function seems to work fine when I use CLisp for
>    D> Windows. However, when I type the same expression into GCL on
>    D> my unix box, I get the following error:
>
>    D> Error: The function LAMBDA is undefined.
>
>For some reason, the LAMBDA macro is not implemented on GCL (I have
>version 2.3 installed on my Slackware box).  Here's the LAMBDA entry
>from the HyperSpec (which you should be aware of; see
>http://www.harlequin.com/support/books/HyperSpec/ for the front page,
>then check out the symbol search page at
>http://www.harlequin.com/support/books/HyperSpec/FrontMatter/Symbol-Index.html):
>
>>Macro LAMBDA 
>>
>>Syntax:
>>
>>
>>lambda lambda-list [[declaration* | documentation]] form* => function
>>
>>
>>
>>Arguments and Values:
>>
>>
>>lambda-list---an ordinary lambda list.
>>
>>declaration---a declare expression; not evaluated.
>>
>>documentation---a string; not evaluated.
>>
>>form---a form.
>>
>>function---a function.
>>
>>
>>Description:
>>
>>
>>Provides a shorthand notation for a function special form involving a
>>lambda expression such that:
>>
>>
>> (lambda lambda-list [[declaration* | documentation]] form*)
>> ==  (function (lambda lambda-list [[declaration* | documentation]] form*))
>> ==  #'(lambda lambda-list [[declaration* | documentation]] form*)
>
>The best thing to do is to always quote (either via FUNCTION or via
>#', as show above) your LAMBDA expressions.  I've found the extra
>visual cue that says "here is a function" to be most helpful when
>reading through my code.
>
>That said, the following form works in my version of GCL.  HTH.
>
>(mapcar #'(lambda (x)
>	    (/ (- x 32) 1.8))
>	'(4 5 6))
>
>P.S. If you initially learned "Lisp" by learning Scheme, you must
>unlearn the notion that there is a single name space for everything.
>In Common Lisp, a symbol may be bound to BOTH a function AND a value;
>whether you use #' (FUNCTION) or ' (QUOTE) determines which kind of
>binding you want.
From: Jeff Dalton
Subject: Layout of Lisp code, was Re: [Q]: Help with lambda
Date: 
Message-ID: <x2vh4a3zx3.fsf_-_@barra.aiai.ed.ac.uk>
Dirt <····@inam3.com> writes:

> sorry about my formatting. i am just doing it the way I was shown in
> class. i was told to place a space between the parens for
> "readability"

Oh no, not again!

For course work on that course, you may want to do things the way you
were shown, but over the decades since Lisp was invented, Lisp
programmers have worked out some pretty good ways to lay out code.
One of the key ideas is to de-emphasise parens - for instance, to
*not* put close parens on lines of their own as if they were "end"s in
Pascal or "}"s in C.

Another key idea is to indent so that the indentation indicates the
nesting and it becommes unnecessary to pay attention to individual
parens when reading code.  (Beginners often wonder how Lisp
programmers deal with all those parens.  The answer is that
they largely ignore them when reading and have an editor's help
when writing.)

Anyway, the extra spaces around parens tend to make them stand out
more (contrary to the first "key idea" mentioned above), and for that,
or perhaps some other reason, the extra spaces are not part of the
usual syntax used by experienced Lisp programmers.

Note that Lisp indentation requires alignment of "like under like"
rather then the simpler C / Pascal / etc formula of n spaces for
each level of nesting (where n is typically 4 but might be 2 or 8).

The best way to get a feel for it is to look at the code in a good
textbook such as Norvig's Paradigms of AI Programming.

-- jd
From: Pierre R. Mai
Subject: Re: [Q]: Help with lambda
Date: 
Message-ID: <87d7qk5yl4.fsf@orion.dent.isdn.cs.tu-berlin.de>
Dirt <····@inam3.com> writes:

> Hello,
>   I wrote the following lamda expression below:
> 
> ( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6  ) )

First of all:  _Please_ write the expression like this:

(mapcar (lambda (x) (/ (- x 32) 1.8)) '(4 5 6))

This way, you'll probably get many more useful responses, since it is
extremely tiresome to try to read CL code that does not follow the
canonical style.  For background information on coding style and
indentation issues, head over to dejanews.com, and read some of the
postings[1] where the reasons behind this have been expounded again and
again.  Thanks. :)

> This function seems to work fine when I use CLisp for Windows.
> However, when I type the same expression into GCL on my unix box, I
> get the following error:

GCL is probably missing the lambda macro, which was introduced in
the ANSI CL standard, but wasn't included in ClTl IIRC.  There are a
couple of other important things that GCL is missing, so I'd suggest
that you use another Lisp implementation on Unix, if possible.  Either
CLISP (http://clisp.cons.org/) or CMUCL (http://www.cons.org/cmucl/
and see http://www.telent.net/lisp/howto.html) or the free versions
from Franz (http://www.franz.com/) or Harlequin/Xanalys
(http://www.harlequin.com/ or http://www.xanalys.com/) will be better
suited.

That said, writing your expression like the following (which, by
habit, I always do) will let it work on all platforms:

(mapcar #'(lambda (x) (/ (- x 32) 1.8)) '(4 5 6))

This is indeed the same as

(mapcar (function (lambda (x) (/ (- x 32) 1.8)) '(4 5 6)))

which again is the expansion of the lambda macro on systems that have
such a macro definition, i.e. 

(macroexpand '(lambda (x) (/ (- x 32) 1.8)))

will yield

(function (lambda (x) (/ (- x 32) 1.8)))

Regs, Pierre.

Footnotes: 
[1]  Read the threads which contain the messages with the following
     Message-ID's for starters: 
     ··············@orion.dent.isdn.cs.tu-berlin.de,
     ··············@orion.dent.isdn.cs.tu-berlin.de,
     ···············@world.std.com

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
From: Joe Marshall
Subject: Re: Help with lambda
Date: 
Message-ID: <ujJk4.4741$1N6.8330@dfw-read.news.verio.net>
(mapcar #'(lambda (x) (/ (- x 32) 1.8)) '(4 5 6))  or
(mapcar (function (lambda (x) (/ (- x 32) 1.8))) '(4 5 6))

should work on both.

Way back when in the old days...
you had to specify FUNCTION, or use the reader macro #'
which expands to FUNCTION.  These days, I believe that
if you just use (LAMBDA ..) it implies (function (lambda...))
but I'm so used to the old way I still put in the #'
and I guess GCL wants it that way, too.


Dirt <····@inam3.com> wrote in message
·······································@4ax.com...
> Hello,
>   I wrote the following lamda expression below:
>
> ( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6  ) )
>
> This function seems to work fine when I use CLisp for Windows.
> However, when I type the same expression into GCL on my unix box, I
> get the following error:
>
> >>( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6 ) )
>
> Error: The function LAMBDA is undefined.
> Fast links are on: do (si::use-fast-links nil) for debugging
> Error signalled by EVALHOOK.
> Backtrace: system:universal-error-handler > evalhook > MAPCAR
>
> I don't understand where I am going wrong.  Anyhelp would be great.
> Thanks alot,
>
> Dirt
From: Dirt
Subject: Re: Help with lambda
Date: 
Message-ID: <61p69scno13aevfrh21oh9o6lv3cc60fb2@4ax.com>
Thanks Joe,
  That is exactly what the problem was. 
Dirt


On Sat, 29 Jan 2000 16:53:28 -0500, "Joe Marshall"
<·········@alum.mit.edu> wrote:

>(mapcar #'(lambda (x) (/ (- x 32) 1.8)) '(4 5 6))  or
>(mapcar (function (lambda (x) (/ (- x 32) 1.8))) '(4 5 6))
>
>should work on both.
>
>Way back when in the old days...
>you had to specify FUNCTION, or use the reader macro #'
>which expands to FUNCTION.  These days, I believe that
>if you just use (LAMBDA ..) it implies (function (lambda...))
>but I'm so used to the old way I still put in the #'
>and I guess GCL wants it that way, too.
>
>
>Dirt <····@inam3.com> wrote in message
>·······································@4ax.com...
>> Hello,
>>   I wrote the following lamda expression below:
>>
>> ( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6  ) )
>>
>> This function seems to work fine when I use CLisp for Windows.
>> However, when I type the same expression into GCL on my unix box, I
>> get the following error:
>>
>> >>( mapcar ( lambda (x) ( / ( - x 32 ) 1.8 ) ) '( 4 5 6 ) )
>>
>> Error: The function LAMBDA is undefined.
>> Fast links are on: do (si::use-fast-links nil) for debugging
>> Error signalled by EVALHOOK.
>> Backtrace: system:universal-error-handler > evalhook > MAPCAR
>>
>> I don't understand where I am going wrong.  Anyhelp would be great.
>> Thanks alot,
>>
>> Dirt
>