From: Christian von Essen
Subject: #' at lambda expression
Date: 
Message-ID: <pan.2004.08.14.23.25.07.754577@mvonessen.de>
Hi,

I read that #' is an abbreviation for 'function' when used with lambda
expressions. I know, that using 'function' with 'lambda' returns the
closure of this lambda-expression. But i could not find any difference in
using

(defun adder (x) (lambda (y) (+ x y)))

and

(defun adder (x) #'(lambda (y) (+ x y)))

Both seem to work the same, and I think that I know, where the difference
is, namely that using lambda without #' makes the result of the
lambda-expression using dynamic binding, and with #' lexical binding.
But I could not find any practical difference.

Could you give me examples or explanation to show the difference, please?

Christian von Essen

From: Pascal Costanza
Subject: Re: #' at lambda expression
Date: 
Message-ID: <cfm76o$avh$2@newsreader2.netcologne.de>
Christian von Essen wrote:

> Hi,
> 
> I read that #' is an abbreviation for 'function' when used with lambda
> expressions. I know, that using 'function' with 'lambda' returns the
> closure of this lambda-expression. But i could not find any difference in
> using
> 
> (defun adder (x) (lambda (y) (+ x y)))
> 
> and
> 
> (defun adder (x) #'(lambda (y) (+ x y)))

Try (macroexpand '(lambda (y) (+ x y))


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Rainer Joswig
Subject: Re: #' at lambda expression
Date: 
Message-ID: <joswig-E1461C.01575715082004@news-50.dca.giganews.com>
In article <······························@mvonessen.de>,
 Christian von Essen <·········@mvonessen.de> wrote:

> Hi,
> 
> I read that #' is an abbreviation for 'function' when used with lambda
> expressions. I know, that using 'function' with 'lambda' returns the
> closure of this lambda-expression. But i could not find any difference in
> using
> 
> (defun adder (x) (lambda (y) (+ x y)))
> 
> and
> 
> (defun adder (x) #'(lambda (y) (+ x y)))
> 
> Both seem to work the same, and I think that I know, where the difference
> is, namely that using lambda without #' makes the result of the
> lambda-expression using dynamic binding, and with #' lexical binding.
> But I could not find any practical difference.
> 
> Could you give me examples or explanation to show the difference, please?
> 
> Christian von Essen

There is no difference.

Look for LAMBDA in the Hyperspec.

Or see it for yourself:

(macroexpand '(lambda (y) (+ x y)))

-> (FUNCTION (LAMBDA (Y) (+ X Y)))
From: Christian von Essen
Subject: Re: #' at lambda expression
Date: 
Message-ID: <pan.2004.08.15.11.59.45.512042@mvonessen.de>
On Sun, 15 Aug 2004 01:57:57 +0200, Rainer Joswig wrote:
> 
> There is no difference.
> 
> Look for LAMBDA in the Hyperspec.
> 
> Or see it for yourself:
> 
> (macroexpand '(lambda (y) (+ x y)))
> 
> -> (FUNCTION (LAMBDA (Y) (+ X Y)))

Thank you
This means that it's a matter of style, whether a write "#'" or not,
correct?
From: Pascal Costanza
Subject: Re: #' at lambda expression
Date: 
Message-ID: <cfnk4o$f7r$1@newsreader2.netcologne.de>
Christian von Essen wrote:

> On Sun, 15 Aug 2004 01:57:57 +0200, Rainer Joswig wrote:
> 
>>There is no difference.
>>
>>Look for LAMBDA in the Hyperspec.
>>
>>Or see it for yourself:
>>
>>(macroexpand '(lambda (y) (+ x y)))
>>
>>-> (FUNCTION (LAMBDA (Y) (+ X Y)))
> 
> Thank you
> This means that it's a matter of style, whether a write "#'" or not,
> correct?

Yes. Some find the #' variant clearer because it tells the reader that 
you are dealing with the function space, while others prefer to get rid 
of two characters. Just try to consistently use one way or the other.


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Rainer Joswig
Subject: Re: #' at lambda expression
Date: 
Message-ID: <joswig-C4944C.16294515082004@news-50.dca.giganews.com>
In article <······························@mvonessen.de>,
 Christian von Essen <·········@mvonessen.de> wrote:

> On Sun, 15 Aug 2004 01:57:57 +0200, Rainer Joswig wrote:
> > 
> > There is no difference.
> > 
> > Look for LAMBDA in the Hyperspec.
> > 
> > Or see it for yourself:
> > 
> > (macroexpand '(lambda (y) (+ x y)))
> > 
> > -> (FUNCTION (LAMBDA (Y) (+ X Y)))
> 
> Thank you
> This means that it's a matter of style, whether a write "#'" or not,
> correct?

Yes, it is a matter of style whether you write

(function (lambda ( ... ) ... )

or

#'(lambda ( ... ) ... )

or

(lambda ( ... ) ... )
From: André Thieme
Subject: Re: #' at lambda expression
Date: 
Message-ID: <cfqume$clg$1@ulric.tng.de>
Christian von Essen schrieb:
> Hi,
> 
> I read that #' is an abbreviation for 'function' when used with lambda
> expressions. I know, that using 'function' with 'lambda' returns the
> closure of this lambda-expression. But i could not find any difference in
> using
> 
> (defun adder (x) (lambda (y) (+ x y)))
> 
> and
> 
> (defun adder (x) #'(lambda (y) (+ x y)))
> 
> Both seem to work the same, and I think that I know, where the difference
> is, namely that using lambda without #' makes the result of the
> lambda-expression using dynamic binding, and with #' lexical binding.
> But I could not find any practical difference.
> 
> Could you give me examples or explanation to show the difference, please?
> 
> Christian von Essen


As I understood it, it works this way:
the only correct version is
#'(lambda (y) (+ x y))


The "trick" now is, that in CL there is a macro "lambda".
This symbol looks exactly like the symbol "lambda" which denotes a
lambda expression.
Whenever you do something like
(lambda (y) (+ x y))
the macro is called and changes your code to
#'(lambda (y) (+ x y))


Andr�
--
From: Coby Beck
Subject: Re: #' at lambda expression
Date: 
Message-ID: <12uUc.34790$fz2.23389@edtnps89>
"Andr� Thieme" <······························@justmail.de> wrote in message
·················@ulric.tng.de...
> Christian von Essen schrieb:
> As I understood it, it works this way:
> the only correct version is
> #'(lambda (y) (+ x y))

See the other replies in the thread, it is a matter of style, not
correctness.

> The "trick" now is, that in CL there is a macro "lambda".
> This symbol looks exactly like the symbol "lambda" which denotes a
> lambda expression.
> Whenever you do something like
> (lambda (y) (+ x y))
> the macro is called and changes your code to
> #'(lambda (y) (+ x y))

There is an exception to this interchangability:

CL-USER 45 > ((lambda (x) (* x x)) 5)
25

CL-USER 46 > ((function (lambda (x) (* x x))) 5)

Error: Syntactic error in form ((FUNCTION (LAMBDA (X) (* X X))) 5):
   Illegal function name (FUNCTION (LAMBDA (X) (* X X))).
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other
options


-- 
Coby Beck
(remove #\Space "coby 101 @ big pond . com")
From: Matthew Danish
Subject: Re: #' at lambda expression
Date: 
Message-ID: <20040817212356.GC13999@mapcar.org>
On Tue, Aug 17, 2004 at 08:39:25PM +0000, Coby Beck wrote:
> There is an exception to this interchangability:
> 
> CL-USER 45 > ((lambda (x) (* x x)) 5)
> 25
> 
> CL-USER 46 > ((function (lambda (x) (* x x))) 5)
> 
> Error: Syntactic error in form ((FUNCTION (LAMBDA (X) (* X X))) 5):

Before this confuses some poor newbie, let me point out that this is no
exception, but rather a natural consequence of the evaluation model.

Given a form for evaluation, the evaluator considers the context of each
element of the form.  The first element of the form is treated
differently from all other elements of the form.  The first element of
the form is NOT EVALUATED, but rather it is taken to be the name of a
(1) special operator, (2) macro, (3) function, or (4) a lambda form.  If
(3) or (4) is the case, then the rest of the elements are evaluated
normally from left to right, and applied to the function.

Hence, if the form (lambda (x) (* x x)) appears as the first element of
a form, it is not evaluated and therefore the macro is not expanded.  If
it appears anywhere in the rest of a form, it may be evaluated normally
and then the macro will be expanded.  There is no exception being made
for LAMBDA, it is just a normal macro.

(defmacro lambda (args &body body)
  `(function (lambda ,args ,@body)))

The argument to the FUNCTION special operator is also considered to be
in a special unevaluated context, where only a function name or lambda
form may be specified.

-- 
;;;; Matthew Danish -- user: mrd domain: cmu.edu
;;;; OpenPGP public key: C24B6010 on keyring.debian.org