From: Akyl Tulegenov
Subject: Lambda
Date: 
Message-ID: <Pine.GSO.4.21.0305251509140.18369-100000@granby.ccc.nottingham.ac.uk>
Dear All!

What is wrong with this string?

((lambda (f) (f `(b c))) `(lambda (x) (cons `a x)))

it produces error message . (Taken from the paper by Paul Grahaham).
I would rather prefer 
((lambda (f) (f `(b c))) (lambda (x) (cons `a x)))

instead, as (lambda (x) (cons `a x)) should already returns the value
(list) (dont't see the need for quoting). But it again gives error message.


Thanks. 
Akyl.

From: Justin Dubs
Subject: Re: Lambda
Date: 
Message-ID: <2e262238.0305250925.34cfb5ed@posting.google.com>
Akyl Tulegenov <······@unix.ccc.nottingham.ac.uk> wrote in message news:<········································@granby.ccc.nottingham.ac.uk>...
> Dear All!
> 
> What is wrong with this string?
> 
> ((lambda (f) (f `(b c))) `(lambda (x) (cons `a x)))
> 
> it produces error message . (Taken from the paper by Paul Grahaham).
> I would rather prefer 
> ((lambda (f) (f `(b c))) (lambda (x) (cons `a x)))
> 
> instead, as (lambda (x) (cons `a x)) should already returns the value
> (list) (dont't see the need for quoting). But it again gives error message.

Assuming that this is Lisp and not Scheme code, there are several
things wrong with it.

First, in (lambda (f) (f `(b c))), f is a variable not a function. 
So, you can't use it like a function.  Functions and variables are
completely separate entities in Lisp.  They are stored in separate
namespaces.  So, you can have a function called foo and a variable
called foo at the same time, and they won't conflict with each other.

So, instead of (lambda (f) (f `(b c))) you want (lambda (f) (funcall f
`(b c))).  Funcall let's you call a function which is stored in a
variable.

Second, the other lambda, (lambda (x) (cons `a x)) shouldn't be
quoted.  If you quote it then f will be bound to the list (lambda (x)
(cons `a x)).  You don't want that.  You want it to be bound to the
result of evaluating (lambda (x) (cons `a x)), which is a function,
which is what will happen if it's not quoted.

Third, you probably don't mean to be using ` in this code.  You can
use it, but there is no reason to.  Instead, you should use the
regular quote: '.

So, the final code, after all of those changes, should look like this:

((lambda (f) (funcall f '(b c))) (lambda (x) (cons 'a x)))

Hope this helps.

Justin Dubs
From: Nils Goesche
Subject: Re: Lambda
Date: 
Message-ID: <87el2njc7n.fsf@darkstar.cartan>
Akyl Tulegenov <······@unix.ccc.nottingham.ac.uk> writes:

> Dear All!
> 
> What is wrong with this string?
> 
> ((lambda (f) (f `(b c))) `(lambda (x) (cons `a x)))
> 
> it produces error message . (Taken from the paper by Paul Grahaham).
> I would rather prefer 
> ((lambda (f) (f `(b c))) (lambda (x) (cons `a x)))
> 
> instead, as (lambda (x) (cons `a x)) should already returns the
> value (list) (dont't see the need for quoting). But it again
> gives error message.

Welcome to Lisp-2 ;-)  Try

((lambda (f) (funcall f '(b c))) (lambda (x) (cons 'a x)))

What gets called in (lambda (f) (f '(b c))) is not the argument
bound to F, but a function /named/ F in the function namespace.

Regards,
-- 
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Kalle Olavi Niemitalo
Subject: Re: Lambda
Date: 
Message-ID: <87brxrggvj.fsf@Astalo.kon.iki.fi>
Akyl Tulegenov <······@unix.ccc.nottingham.ac.uk> writes:

> What is wrong with this string?
>
> ((lambda (f) (f `(b c))) `(lambda (x) (cons `a x)))

It binds the variable f to the list (lambda (x) (cons `a x)) and
then calls the function f with the argument (b c).  In Common
Lisp however, variables and functions are in separate namespaces;
having a variable f does not mean you also have a function f.
To call the function that is the value of a variable, you need
to use FUNCALL or APPLY.  (Or use Scheme, which puts functions
and variables in the same namespace; but then it would be better
to ask in <news:comp.lang.scheme>.)

With FUNCALL, the form would become:

  ((lambda (f) (funcall f `(b c))) `(lambda (x) (cons `a x)))

This works in Emacs Lisp, but still not in Common Lisp, because
the variable f holds a list (lambda (x) (cons `a x)) and lists
are not functions. To get a function, you can do one of these:

  ((lambda (f) (funcall f `(b c))) (lambda (x) (cons `a x)))
  ((lambda (f) (funcall f `(b c))) #'(lambda (x) (cons `a x)))

These two forms are equivalent; which one you use is a matter of
style.

I have left in your backquotes (`) because they don't prevent the
example from working.  However, it's bad style; you should use
regular quotes (') when you don't need the extra features
provided by backquotes.