From: ·········@gmail.com
Subject: Using a lambda as a function
Date: 
Message-ID: <1123702616.199883.167470@g14g2000cwa.googlegroups.com>
In Scheme, the following code works:

  (let ((x (lambda (x) x)))
    (x 3))      ;  => 3

This doesn't work in Lisp.  Is funcall the normal way to do the
equivalent?

From: Joe Marshall
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <pssllfyh.fsf@ccs.neu.edu>
·········@gmail.com writes:

> In Scheme, the following code works:
>
>   (let ((x (lambda (x) x)))
>     (x 3))      ;  => 3
>
> This doesn't work in Lisp.  Is funcall the normal way to do the
> equivalent?

   (let ((x (lambda (y) y)))
     (funcall x 3))      ;  => 3

X is bound in the variable namespace
From: Marco Antoniotti
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <%dtKe.26$DJ5.67240@typhoon.nyu.edu>
Now, this has been bugging me for some time.

Why can't we have it the Scheme way?

(let ((f (lambda (x) 42)))
    (f 42))

Given the above code, the symbol F must be searched for a functional 
value in its function cell, if no valid function can be found this way, 
why not search its regular binding as a variable or its value cell 
instead of just signalling UNDEFINED-FUNCTION?

Cheers
--
Marco







Joe Marshall wrote:
> ·········@gmail.com writes:
> 
> 
>>In Scheme, the following code works:
>>
>>  (let ((x (lambda (x) x)))
>>    (x 3))      ;  => 3
>>
>>This doesn't work in Lisp.  Is funcall the normal way to do the
>>equivalent?
> 
> 
>    (let ((x (lambda (y) y)))
>      (funcall x 3))      ;  => 3
> 
> X is bound in the variable namespace
> 
From: Joe Marshall
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <hddxld4m.fsf@ccs.neu.edu>
Marco Antoniotti <·······@cs.nyu.edu> writes:

> Now, this has been bugging me for some time.
>
> Why can't we have it the Scheme way?
>
> (let ((f (lambda (x) 42)))
>     (f 42))
>
> Given the above code, the symbol F must be searched for a functional
> value in its function cell, if no valid function can be found this
> way, why not search its regular binding as a variable or its value
> cell instead of just signalling UNDEFINED-FUNCTION?

Then the behavior will mysteriously change if someone defines F.
From: Marco Antoniotti
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <2SIKe.27$DJ5.65980@typhoon.nyu.edu>
Joe Marshall wrote:
> Marco Antoniotti <·······@cs.nyu.edu> writes:
> 
> 
>>Now, this has been bugging me for some time.
>>
>>Why can't we have it the Scheme way?
>>
>>(let ((f (lambda (x) 42)))
>>    (f 42))
>>
>>Given the above code, the symbol F must be searched for a functional
>>value in its function cell, if no valid function can be found this
>>way, why not search its regular binding as a variable or its value
>>cell instead of just signalling UNDEFINED-FUNCTION?
> 
> 
> Then the behavior will mysteriously change if someone defines F.

Yes.  But no more no less than when somebody re-defines a function 
elsewhere without the proper underwear :)

The problem with the code above is that the "name" F may loose its 
"lexical" properties.  E.g.

(flet ((f (x) pi))
    (let ((f (lambda (x) 42)))
       (f nil)))

Even in this simple case the interpretation of F requires a more 
complicated procedure than just "look at the code".

Cheers
--
Marco
From: Barry Margolin
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <barmar-85EE5F.18580710082005@comcast.dca.giganews.com>
In article <··················@typhoon.nyu.edu>,
 Marco Antoniotti <·······@cs.nyu.edu> wrote:

> Now, this has been bugging me for some time.
> 
> Why can't we have it the Scheme way?
> 
> (let ((f (lambda (x) 42)))
>     (f 42))
> 
> Given the above code, the symbol F must be searched for a functional 
> value in its function cell, if no valid function can be found this way, 
> why not search its regular binding as a variable or its value cell 
> instead of just signalling UNDEFINED-FUNCTION?

Because we didn't want the behavior to be so confusing.  Maclisp had an 
option to do this, but it was almost never enabled.  If you want to bind 
a function name, use FLET or LABELS, don't use LET.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: R. Mattes
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <pan.2005.08.10.21.04.40.359177@mh-freiburg.de>
On Wed, 10 Aug 2005 16:13:46 -0400, Marco Antoniotti wrote:

> Now, this has been bugging me for some time.
> 
> Why can't we have it the Scheme way?
> 
> (let ((f (lambda (x) 42)))
>     (f 42))
> 
> Given the above code, the symbol F must be searched for a functional 
> value in its function cell, if no valid function can be found this way, 
> why not search its regular binding as a variable or its value cell 
> instead of just signalling UNDEFINED-FUNCTION?
> 
> Cheers
> --
> Marco
> 
> 
> 
> 
> 
> 
> 
> Joe Marshall wrote:
>> ·········@gmail.com writes:
>> 
>> 
>>>In Scheme, the following code works:
>>>
>>>  (let ((x (lambda (x) x)))
>>>    (x 3))      ;  => 3
>>>
>>>This doesn't work in Lisp.  Is funcall the normal way to do the
>>>equivalent?
>> 
>> 
>>    (let ((x (lambda (y) y)))
>>      (funcall x 3))      ;  => 3
>> 
>> X is bound in the variable namespace
>>

Hmm, but you can do:

 (sef x (lambda (n) (* 2 n)))

 (setf (symbol-function 'x) (lambda (n) (* 3 n)))

What's the value of:
 
 (x 2)


 Cheers

   Ralf Mattes
  



 
From: Geoffrey Summerhayes
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <OBAKe.8809$6d4.1181425@news20.bellglobal.com>
"R. Mattes" <··@mh-freiburg.de> wrote in message ···································@mh-freiburg.de...
>
> Hmm, but you can do:
>
> (sef x (lambda (n) (* 2 n)))
>
> (setf (symbol-function 'x) (lambda (n) (* 3 n)))
>
> What's the value of:
>
> (x 2)
>

That's easy, it's 6.
As Marco stipulated the function slot takes precedence so that

(defun foo (list) (list list))

still behaves the same way.

The real problem is in a function like

(defun bar (fn x) (fn x))

which works just fine until someone does a (defun fn ...)

Unfortunately the two cases are similar enough that there
isn't really a good way to distinguish between them w/o
something like FUNCALL, especially in view of cases like

(defun baz (fn list) (list (fn list)))

if you want it to behave like

(defun baz (fn list)
  (cl:list (funcall fn list)))

Of course, there's always switching to a strict naming convention
for functional arguments.

(defun bar (-fn- x) (-fn- x))

I'll stick with typing FUNCALL ...

--
Geoff 
From: Kent M Pitman
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <uslxh83ny.fsf@nhplace.com>
"Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:

> > Hmm, but you can do:
> >
> > (sef x (lambda (n) (* 2 n)))
> >
> > (setf (symbol-function 'x) (lambda (n) (* 3 n)))
> >
> > What's the value of:
> >
> > (x 2)
> 
> That's easy, it's 6.
> As Marco stipulated the function slot takes precedence so that
 
No, that's not right.  The function namespace does not "take precedence",
it is "unconditionally used instead" in the situation of the "operator 
position" (i.e., the car of a compound form).  There is no ambiguity
about this.

> (defun foo (list) (list list))
> 
> still behaves the same way.
>
> The real problem is in a function like
> 
> (defun bar (fn x) (fn x))
> 
> which works just fine until someone does a (defun fn ...)

No, it doesn't.  Maybe in some hypothetical Lisp, but not in Common Lisp. 
 (defun bar (fn x) (fn x))
is undefined unless there is a definition of FN globally.  It will
never funcall FN.  If you know of an implementation that calls FN
in this case, it is in error.

> Unfortunately the two cases are similar enough that there
> isn't really a good way to distinguish between them w/o
> something like FUNCALL, especially in view of cases like
> 
> (defun baz (fn list) (list (fn list)))
> 
> if you want it to behave like
> 
> (defun baz (fn list)
>   (cl:list (funcall fn list)))
 
I can't make sense of this.

> Of course, there's always switching to a strict naming convention
> for functional arguments.
> 
> (defun bar (-fn- x) (-fn- x))
> 
> I'll stick with typing FUNCALL ...

You should. There is no other way to receive an argument to a function
than as a variable in the value namespace, and FUNCALL is needed to call
any computed function (including one that is "computed" by accessing the
value namespace).
From: Geoffrey Summerhayes
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <55BKe.8333$yH2.373484@news20.bellglobal.com>
"Kent M Pitman" <······@nhplace.com> wrote in message ··················@nhplace.com...
> "Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:
>> (defun foo (list) (list list))
>>
>> still behaves the same way.
>>
>> The real problem is in a function like
>>
>> (defun bar (fn x) (fn x))
>>
>> which works just fine until someone does a (defun fn ...)
>
> No, it doesn't.  Maybe in some hypothetical Lisp, but not in Common Lisp.
> (defun bar (fn x) (fn x))
> is undefined unless there is a definition of FN globally.  It will
> never funcall FN.  If you know of an implementation that calls FN
> in this case, it is in error.
>

Sorry, it IS a hypothetical Lisp I'm discussing. Marco's suggestion
that EVAL be extended so that if the function value was undefined
but the 'regular' value was a function it would be called thereby
eliminating the need for FUNCALL.

--
Geoff 
From: Kent M Pitman
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <uu0hwu8gg.fsf@nhplace.com>
"Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:

> "Kent M Pitman" <······@nhplace.com> wrote in 
> message ··················@nhplace.com...
>
> > "Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:
> >> (defun foo (list) (list list))
> >> still behaves the same way.
> >> The real problem is in a function like
> >> (defun bar (fn x) (fn x))
> >> which works just fine until someone does a (defun fn ...)
> >
> > No, it doesn't.  Maybe in some hypothetical Lisp, but not in
> > Common Lisp.  (defun bar (fn x) (fn x)) is undefined unless there
> > is a definition of FN globally.  It will never funcall FN.  If you
> > know of an implementation that calls FN in this case, it is in
> > error.
> 
> Sorry, it IS a hypothetical Lisp I'm discussing. Marco's suggestion
> that EVAL be extended so that if the function value was undefined
> but the 'regular' value was a function it would be called thereby
> eliminating the need for FUNCALL.

Ah.  That makes sense.

The trouble with this hypothetical, though, is that there's a design
principle in Lisp that pervades a great many things and that's the
idea of "modular compilation".  You simply can't know if the
definition is present because ordinary function calls may be compiled
in any order.  The test for "undefined" is done at the end of loading
all modules in a compilation unit, not at the time a reference is
first seen.  Only macros (and the equivalent, such as defsetf
expressions or compiler macros or symbol macros) that get processed at
compilation time are required to be present when compilation occurs.
Consequently, it is just meaningless to make this distinction.  If you
made this change, it would be practically equivalent to changing that
removed the right of users to make forward references to functions
without some sort of declaration.
From: Marcus Breiing
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <ldjuf08x6bogr@breiing.com>
* Kent M Pitman

> If you made this change, it would be practically equivalent to
> changing that removed the right of users to make forward references
> to functions without some sort of declaration.

We could hope to get around this problem by deferring the decision
until runtime, i.e. we'd compile every (fun args...) where fun is
lexically value-bound but not lexically function-bound into something
like

(if (fboundp 'fun) (fun args...) (funcall fun args...))

(This is what I spontaneously assumed how the original proposal would
work.)

However, we now would want to tell maintainance programmers about all
the function names they are *not* supposed to define from now on,
because doing so could break our code in strange ways.  We could do
this informally, but I guess soon someone would come up with a scheme
to make the compiler check this. For example, you say

        (defun-never foo)

and from now till death of your image, your Lisp prevents you from
defun'ing FOO.  OK, we're safe.

Then, going back, we see that we can omit the runtime-check for
DEFUN-NEVER'd symbols.  And since we prefer safe code - especially so
when it's also faster than unsafe code - we probably will now
_require_ a DEFUN-NEVER for every FOO we want our little trick to work
with.  Here's the prototype:

(defmacro defun-never (symbol)
   `(defmacro ,symbol (&rest args)
        `(funcall ,',symbol ,@args)))

So...

CL-USER> (defun-never foo)
FOO
CL-USER> (let ((foo #'+)) (foo 1 2))
3
CL-USER> 

;-)

Marcus
From: Edi Weitz
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <u64ud2g7b.fsf@agharta.de>
On Thu, 11 Aug 2005 05:03:00 GMT, Kent M Pitman <······@nhplace.com> wrote:

> No, that's not right.

> No, it doesn't.

> I can't make sense of this.

> [...]

You should read the whole thread before you're trying to lecture
people.  Also, note the word "stipulate" in the email you replied to.

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Kent M Pitman
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <ur7d0u4hi.fsf@nhplace.com>
Edi Weitz <········@agharta.de> writes:

> On Thu, 11 Aug 2005 05:03:00 GMT, Kent M Pitman <······@nhplace.com> wrote:
> 
> > No, that's not right.
> 
> > No, it doesn't.
> 
> > I can't make sense of this.
> 
> > [...]
> 
> You should read the whole thread before you're trying to lecture
> people.  Also, note the word "stipulate" in the email you replied to.
> 
> Cheers,
> Edi.
> 
> -- 
> 
> Lisp is not dead, it just smells funny.
> 
> Real email: (replace (subseq ·········@agharta.de" 5) "edi")

You know, you're right.  Shame on me.

Now that I am thus rebuked, I realize that there was no chance that
some newbie reading these remarks would have done so out of context.
Rather than be confused, I now realize that such a hypothetical person
would have instead just carefully read back upthread and de-confused
himself or herself rather than lazily become confused by reading
Geoffrey's message in isolation and being confused by its use of the
declarative tense where I might have though the conditional tense
to be clearer.  Clearly, I was worried for nothing that such a 
misunderstanding could occur.  As you so rightly make clear to me,
misunderstandings are impossible on newsgroups and so one should never
risk overstating a point or risking redundancy in order to make sure
we're all on the same page technically.

Thanks, too, for showing me that my remarks were unambiguously a
"lecture" and not just a helpful hint that sought to use simple and
clear words to avoid confusing any newbies that might be reading on.
Your strong example of how to use tone in an unambiguously helpful way
that cannot be misinterpreted as itself an inappropriate lecture is
extremely instructive to me in how I should have proceeded.

Having been now thus made aware of the inappropriate nature of my
post, and indeed my entire posting style, I suddenly realize I have no
time to really read this newsgroup in the overall workflow style that
is unambiguously intended to be approached.  So I'll just withdraw for
a while.  My schedule in the next couple of weeks is pretty busy and I
wouldn't want to risk that another hastily dashed off post will be
misinterpreted as a lecture.  Better to not post at all than to risk
that...

Thanks again for this very constructive and useful suggestion.
Be well in the interim.
 --Kent

--
Non email: (replace (let ((subseq (floor pi)))
                      (map 'string 'identity "pitman" ·@" "nhplace.com"
                           (subseq (subseq (subseq "subseq" subseq) subseq)
                                   (search "search" "search")
                                   (search "subseq" "search"))))
                    "silence")
From: Ole Arndt
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <gnus.m3ll38f7hj.fsf@sugarshark.com>
Kent M Pitman <······@nhplace.com> writes:

> Thanks, too, for showing me that my remarks were unambiguously a
> "lecture" and not just a helpful hint that sought to use simple and
> clear words to avoid confusing any newbies that might be reading on.

Be assured that at least one newbie to CL learned something while
reading your "lecture", your search for "simple and clear words" was
obviously successful.

Ole
-- 
Ole Arndt                     http://www.sugarshark.com
From: R. Mattes
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <pan.2005.08.11.12.19.32.596527@mh-freiburg.de>
On Thu, 11 Aug 2005 00:36:59 -0400, Geoffrey Summerhayes wrote:

> 
> "R. Mattes" <··@mh-freiburg.de> wrote in message ···································@mh-freiburg.de...
>>
>> Hmm, but you can do:
>>
>> (sef x (lambda (n) (* 2 n)))
>>
>> (setf (symbol-function 'x) (lambda (n) (* 3 n)))
>>
>> What's the value of:
>>
>> (x 2)
>>
> 
> That's easy, it's 6.
> As Marco stipulated the function slot takes precedence so that
> 
> (defun foo (list) (list list))
> 
> still behaves the same way.

Sorry, i think my reply was too short. Marco's hypothetical Lisp
opens up a can of worms. What might sound simple on a first look
might become a nightmare soon. While the precedence order Marco
gives (first "look up" the symbol function then the symbol value)
looks fine in the simple cases  one wounders how more complex
ones are handled. For example, will symbol-function take precedence
over locally bound symbol values?

 (defun bork (x) (* x x))

 (defun moep (x)
   (let ((bork (lambda (x) (* 42 x))))
     (bork x))

 (bork 23)

 ???

What about dynamic bindings? 


> 
> I'll stick with typing FUNCALL ...

Me too.

 Cheers Ralf Mattes
From: Karl A. Krueger
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <dddpqp$du4$1@baldur.whoi.edu>
·········@gmail.com wrote:
> In Scheme, the following code works:
> 
>  (let ((x (lambda (x) x)))
>    (x 3))      ;  => 3
> 
> This doesn't work in Lisp.  Is funcall the normal way to do the
> equivalent?

Maybe you don't need FUNCALL -- you need FLET:

	(flet ((x (x) x))
	   (x 3))

... does what it seems you want.

-- 
Karl A. Krueger <········@example.edu> { s/example/whoi/ }
From: drewc
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <Q3uKe.176340$5V4.117443@pd7tw3no>
·········@gmail.com wrote:
> In Scheme, the following code works:
> 
>   (let ((x (lambda (x) x)))
>     (x 3))      ;  => 3
> 
> This doesn't work in Lisp.  Is funcall the normal way to do the
> equivalent?
> 

Yes, you'd use funcall to call a function stored in the value cell of a 
symbol. In Common Lisp, any given symbol can have both a function and a 
value bound to it (this is the lisp-1 vs. lisp-2 thing), and they exist 
in separate namespaces (symbols in CL also have a plist cell). Perhaps 
the following REPL session will help to enlighten.

CL-USER> (inspect 'x)

The object is a SYMBOL.
0. Name: "X"
1. Package: #<PACKAGE "COMMON-LISP-USER">
2. Value: "unbound"
3. Function: "unbound"
4. Plist: NIL
 > q

As you can see, the function/value cells are unbound and the plist cell 
is the empty list.

; No value
CL-USER> (defparameter x 3)
X
CL-USER> (defun x (x) x)
X
CL-USER> (x x)
3
CL-USER> (inspect 'x)

The object is a SYMBOL.
0. Name: "X"
1. Package: #<PACKAGE "COMMON-LISP-USER">
2. Value: 3
3. Function: #<FUNCTION X>
4. Plist: NIL
 > q

Now, we've set the SYMBOL-VALUE of X to 3 and the SYMBOL-FUNCTION to our 
defined function. we can also set these cells directly using the 
appropriate accessors :

CL-USER> (symbol-function 'x)
#<FUNCTION X>
CL-USER> (setf (symbol-value 'x) 4)
4
CL-USER> (x x)
4
CL-USER> (setf (symbol-function 'x) (lambda (x) (1+ x)))
#<FUNCTION (LAMBDA (X)) {A7C7455}>
CL-USER> (x x)
5

Just for fun we can set values in the plist as well, still punning on X:

CL-USER> (setf (get 'x 'x) x)
4
CL-USER> (x (get 'x 'x))
5
CL-USER> (inspect 'x)

The object is a SYMBOL.
0. Name: "X"
1. Package: #<PACKAGE "COMMON-LISP-USER">
2. Value: 4
3. Function: #<FUNCTION (LAMBDA (X)) {A7C7455}>
4. Plist: (X 4)

So, in CL when we want to call a FUNCTION that is in the SYMBOL-VALUE 
cell, we have to use FUNCALL. And believe it or not, we prefer it that 
way :)

Having said all that, in the example you gave you'd probably want FLET :

CL-USER> (flet ((x (x) x))
	   (x 3))
3


hth.
-- 
Drew Crampsie
drewc at tech dot coop
"Never mind the bollocks -- here's the sexp's tools."
	-- Karl A. Krueger on comp.lang.lisp
From: Pascal Bourguignon
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <87slxhlepp.fsf@thalassa.informatimago.com>
·········@gmail.com writes:

> In Scheme, the following code works:
>
>   (let ((x (lambda (x) x)))
>     (x 3))      ;  => 3
>
> This doesn't work in Lisp.  Is funcall the normal way to do the
> equivalent?

Yes.

Note that you can also write: ((lambda (x) x) 3)


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
I need a new toy.
Tail of black dog keeps good time.
Pounce! Good dog! Good dog!
From: Kent M Pitman
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <uvf2dband.fsf@nhplace.com>
·········@gmail.com writes:

> In Scheme, the following code works:
> 
>   (let ((x (lambda (x) x)))
>     (x 3))      ;  => 3
> 
> This doesn't work in Lisp.  Is funcall the normal way to do the
> equivalent?

Yes (as others have noted).

But your subject line implies a misunderstanding.

LAMBDA is a symbol, not a function in either Scheme nor in Common Lisp.

A "lambda expression" is a list whose first element is the symbol LAMBDA
(in Common Lisp).  Scheme defines it ever-so-slightly differently because
its semantics are defined in terms of notation rather than instantiated
datastructure, but it amounts to the same.  In both languages, Lambda
expressions name functions, but are not functions themselves.

In both languages, when you perform a normal evaluation of a lambda
expression, you get a function as the result.

What differs is that in Common Lisp, the car of a form is not evaluated
normally, so when you write 
 ((lambda (x) x) 3)
in Scheme you are actually getting "normal evaluation" on (lambda (x) x)
and on 3.  Then when you get the results, the function resulting from
evaluating that lambda expression is called on the object that results from
evaluating 3 (which happens to be itself, 3, since numbers self-evaluate).
In Common Lisp, the car of a form is always treated specially; that means
that if the car is a lambda expression, then by special exception it is
treated as if you'd done (funcall (lambda (x) x) 3), BUT if you put a
symbol there, it is "functionally evaluated", that is, its value is found
in the "function namespace", not in the "variable namespace".  Since
these namespaces contain different mappings, and since you've done
 (let ((x (lambda (x) x))) ...)
you have associated a function [the result of evaluating (lambda (x) x)
with a variable in both Scheme and Common Lisp, but in Common Lisp when you
later do (x 3), you look in different places.  Scheme looks in the value
namespace because it has no other; CL looks in the function namespace.

In CL, it is possible to write:

 (let ((list '(a b c)))
   (list list list))

and get ((a b c) (a b c)).  In Scheme, if you did this, you'd get an error
because the first list use of LIST would not be a function.  CL considers
this a feature.

In any case, my main point here was only to say that describing your problem
as something to do with the "use of a lambda" was a misnomer.  The issue has
nothing to do with lambda and everything to do with how the car of a form
is evaluated (where a function definition is looked for).

I hope that helps.
From: ·········@gmail.com
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <1123774976.207327.324290@f14g2000cwb.googlegroups.com>
Thanks for that explanation.  Are lambda expressions the only things
that get special treatment as the car of a function call?
From: Pascal Costanza
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <3m2372F152630U1@individual.net>
·········@gmail.com wrote:
> Thanks for that explanation.  Are lambda expressions the only things
> that get special treatment as the car of a function call?

The car can be a symbol naming a function, macro or a special operator, 
or it can be a lambda expression. See 
http://www.lispworks.com/documentation/HyperSpec/Body/03_abab.htm


Pascal

-- 
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++
From: Lars Rune Nøstdal
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <pan.2005.08.11.09.10.23.450697@gmail.com>
Den Wed, 10 Aug 2005 12:36:56 -0700, skrev batkins57:

> In Scheme, the following code works:
> 
>   (let ((x (lambda (x) x)))
>     (x 3))      ;  => 3
> 
> This doesn't work in Lisp.  Is funcall the normal way to do the
> equivalent?

I'm in kind of a hurry here, so this might have been mentioned before, but:


CL-USER> (flet ((x (x) x))
	   (x 3))
3

-- 
Mvh, 
Lars Rune Nøstdal
http://lars.nostdal.org/
From: Lars Rune Nøstdal
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <pan.2005.08.11.09.12.21.255892@gmail.com>
Den Thu, 11 Aug 2005 09:10:36 +0000, skrev Lars Rune Nøstdal:

> Den Wed, 10 Aug 2005 12:36:56 -0700, skrev batkins57:
> 
>> In Scheme, the following code works:
>> 
>>   (let ((x (lambda (x) x)))
>>     (x 3))      ;  => 3
>> 
>> This doesn't work in Lisp.  Is funcall the normal way to do the
>> equivalent?
> 
> I'm in kind of a hurry here, so this might have been mentioned before,
> but:
> 
> 
> CL-USER> (flet ((x (x) x))
> 	   (x 3))
> 3

Also note that this works:

(let ((x "hi there"))
	   (format t "~A" x)
	   (flet ((x (x) x))
	     (x 3)))
hi there
3

(separate namespace for functions and variables)

-- 
Mvh,
Lars Rune Nøstdal
http://lars.nostdal.org/
From: Lars Rune Nøstdal
Subject: Re: Using a lambda as a function
Date: 
Message-ID: <pan.2005.08.11.09.14.33.793888@gmail.com>
(let ((x "hi there"))
	   (flet ((x (x) x))
	     (format t "~A" x)
	     (x 3)))
hi there
3