From: ····@sonic.net
Subject: beginner question: why does lisp work like this?
Date: 
Message-ID: <m3acqmrxp6.fsf@teak.ramandgita.com>
I'm just getting started with lisp and I don't understand
an aspect of function calls in lisp.

Consider this:

(defun add (a b)
  (+ a b))

(setq tmp '(add))

This is allowed:

form 1: (add 1 2)

But this is not:

form 2: ((car tmp 1 2))

Why is form 1 allowed but not form 2.

Thanks for any insight.

-Ram

From: Kenny Tilton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <thjMd.101339$kq2.40135@twister.nyc.rr.com>
····@sonic.net wrote:
> I'm just getting started with lisp and I don't understand
> an aspect of function calls in lisp.
> 
> Consider this:
> 
> (defun add (a b)
>   (+ a b))
> 
> (setq tmp '(add))
> 
> This is allowed:
> 
> form 1: (add 1 2)
> 
> But this is not:
> 
> form 2: ((car tmp 1 2))

I think you mean ((car tmp) 1 2)

> 
> Why is form 1 allowed but not form 2.

Form 1 is Common Lisp, Form 2 is Scheme. The difference is an incredibly 
long story with vast religious implications. Scheme is a failed 
experiment, so if you need the moral equivalent of Form 2, just:

    (funcall (car tmp) 1 2)

...or...

    (let ((args (list 1 2)))
        (apply (car tmp) args))

kenny

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: ···············@yahoo.com
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <1107455297.602817.103630@c13g2000cwb.googlegroups.com>
> Scheme is a failed experiment...

No, don't say this in a thread started by a newbie.  :-)
Scheme is small, pure and elegant.
But I won't say any more, so as to avoid the vast religious
implications.
From: Kenny Tilton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <VvvMd.104961$kq2.61081@twister.nyc.rr.com>
···············@yahoo.com wrote:

>>Scheme is a failed experiment...
> 
> 
> No, don't say this in a thread started by a newbie.  :-)
> Scheme is small, pure and elegant.

Yep. That is what failed to catch on.

:)

kt

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Christopher C. Stacy
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <u1xbxqtjg.fsf@news.dtpq.com>
Kenny Tilton <·······@nyc.rr.com> writes:

> ···············@yahoo.com wrote:
> 
> >>Scheme is a failed experiment...
> > No, don't say this in a thread started by a newbie.  :-)
> > Scheme is small, pure and elegant.
> 
> Yep. That is what failed to catch on.

It caught on quite well for its intended purpose, 
which was to teach 6.001.  It's also a vehicle for 
research into programming languages.  It is also 
used in some industrial settings, outside of academia

Personally, I use Common Lisp.
But there's no need to incite a stupid flame war.
From: Kenny Tilton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <FEwMd.104977$kq2.18776@twister.nyc.rr.com>
Christopher C. Stacy wrote:
> Kenny Tilton <·······@nyc.rr.com> writes:
> 
> 
>>···············@yahoo.com wrote:
>>
>>
>>>>Scheme is a failed experiment...
>>>
>>>No, don't say this in a thread started by a newbie.  :-)
>>>Scheme is small, pure and elegant.
>>
>>Yep. That is what failed to catch on.
> 
> 
> It caught on quite well for its intended purpose, 
> which was to teach 6.001. 

Nonsense. They were trying to outdo the bloated and impure balls of mud 
of the day. They suceeded in keeping the spec small, period. They threw 
a party and no one came. That's all.

> But there's no need to incite a stupid flame war.

Where do you see a flame war? There are newbies around, some trying to 
choose between CL and Scheme. They are entitled to know the trade-offs. 
Period. Full stop, for the yobbos.

kt


-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Christopher C. Stacy
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <u4qgsooms.fsf@news.dtpq.com>
Kenny Tilton <·······@nyc.rr.com> writes:

> Christopher C. Stacy wrote:
> > Kenny Tilton <·······@nyc.rr.com> writes:
> >
> >>···············@yahoo.com wrote:
> >>
> >>
> >>>>Scheme is a failed experiment...
> >>>
> >>>No, don't say this in a thread started by a newbie.  :-)
> >>>Scheme is small, pure and elegant.
> >>
> >>Yep. That is what failed to catch on.
> > It caught on quite well for its intended purpose, which was to teach
> > 6.001.
> 
> Nonsense. They were trying to outdo the bloated and impure balls of
> mud of the day. They suceeded in keeping the spec small, period.
> They threw a party and no one came. That's all.

As far as the goals, I suppose that's open to interpretation,
but I'm just going by the impression I got back at the time
when Sussman handed me a draft of SICP.

You clipped out the part of my statement where I pointed out that
Scheme is widely used for certain purposes, and less widely used 
(but still used) for other purposes.  Your claim that "nobody came"
seems unfounded in light of those facts.

> > But there's no need to incite a stupid flame war.
> 
> Where do you see a flame war? There are newbies around, some trying to
> choose between CL and Scheme. They are entitled to know the
> trade-offs. Period. Full stop, for the yobbos.

Your statement to the newbie seemed inflamatory and without
meaningful content, apparently designed to inflame.
Rather like your follow-up here.

I also recommend Common Lisp.
From: Kenny Tilton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <ZGEMd.105288$kq2.1195@twister.nyc.rr.com>
Christopher C. Stacy wrote:

> Kenny Tilton <·······@nyc.rr.com> writes:
> 
> 
>>Christopher C. Stacy wrote:
>>
>>>Kenny Tilton <·······@nyc.rr.com> writes:
>>>
>>>
>>>>···············@yahoo.com wrote:
>>>>
>>>>
>>>>
>>>>>>Scheme is a failed experiment...
>>>>>
>>>>>No, don't say this in a thread started by a newbie.  :-)
>>>>>Scheme is small, pure and elegant.
>>>>
>>>>Yep. That is what failed to catch on.
>>>
>>>It caught on quite well for its intended purpose, which was to teach
>>>6.001.
>>
>>Nonsense. They were trying to outdo the bloated and impure balls of
>>mud of the day. They suceeded in keeping the spec small, period.
>>They threw a party and no one came. That's all.
> 
> 
> As far as the goals, I suppose that's open to interpretation,

As opposed to objective fact independent of any human judgment? 
PWUAAHAHHAHAHHAHAAHH!!!

But, yeah, I am going by the fact that they gloat over the size of their 
spec relative to some chapter in CLTL1 or something. That would be 
incoherent if they were freely conceding their exercise to be purely 
academic/research. That would be like building a paper airplane and then 
saying, "Now look at the Boeing 747 parts list!!!".

Of course if the scheme group is willing to concede they have a toy 
language, hey, we have a negotiation breakthrough. (I do not hear them 
saying that.)

> but I'm just going by the impression I got back at the time
> when Sussman handed me a draft of SICP.

Name-dropper. :)

> 
> You clipped out the part of my statement where I pointed out that
> Scheme is widely used for certain purposes, and less widely used 
> (but still used) for other purposes.

Make up your mind! Is Scheme a toy, academic exercise or a full-blown 
production language? Hint: rare production Scheme successes mean nothing 
other than that the developer is really good.


>  Your claim that "nobody came"
> seems unfounded in light of those facts.

Boring writers (and academics) worry about the mathematical and 
theoretical precision and provability of every clause of every sentence. 
Cowboys just wing it and trust to native intelligence to downgrade 
superlatives to reasonable values.

ie, That's a quibble.

> 
> 
>>>But there's no need to incite a stupid flame war.
>>
>>Where do you see a flame war? There are newbies around, some trying to
>>choose between CL and Scheme. They are entitled to know the
>>trade-offs. Period. Full stop, for the yobbos.
> 
> 
> Your statement to the newbie seemed inflamatory and without
> meaningful content, apparently designed to inflame.
> Rather like your follow-up here.

But look at the non-existence proof. No flame war has broken out. Why? 
Because I am a known demon and lunatic, so anything I say gets scaled 
down automatically by any intelligent reader, if not ignored completely. 
This is one of the advantages of achieving "loose cannon" status.

I think it is illustrative that the only flame war is the blowtorch you 
have trained on me, when in fact...

> 
> I also recommend Common Lisp.

...we agree.

:)

kenny

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Förster vom Silberwald
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <1107517759.810811.150460@o13g2000cwo.googlegroups.com>
Kenny Tilton wrote:

> Make up your mind! Is Scheme a toy, academic exercise or a full-blown

> production language? Hint: rare production Scheme successes mean
nothing
> other than that the developer is really good.

Sorry for that Kenny:

But I will always use that toy and failed experiment as you like to
call it over Common Lisp.

Sorry to disappoint you for that but I use Bigloo on a daily basis.

Scheme at least Bigloo is a full-blown language and fuller-blown than
CommonLisp for me.

Foerster vom Silberwald
From: Christopher C. Stacy
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <u4qgsn5tr.fsf@news.dtpq.com>
Kenny Tilton <·······@nyc.rr.com> writes:
 
> > You clipped out the part of my statement where I pointed out that
> > Scheme is widely used for certain purposes, and less widely used
> > (but still used) for other purposes.
> 
> Make up your mind! Is Scheme a toy, academic exercise or a full-blown
> production language? Hint: rare production Scheme successes mean
> nothing other than that the developer is really good.

I don't know how you're going to prove your negative statement that
Scheme is not widely used ("failed experiment" and "nobody came").
I gave positive examples of where Scheme is used, and I don't
understand your call for me to pick just one of those uses.

> But look at the non-existence proof. No flame war has broken out. Why?
> Because I am a known demon and lunatic, so anything I say gets scaled
> down automatically by any intelligent reader, if not ignored
> completely. 

I don't think that newbies are familar with your reputation, 
and I myself was assuming that you are reasonable person.  
From: kanzen
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <1107457873.004622.87240@o13g2000cwo.googlegroups.com>
This "failed experiment" business sounds interesting... do you have a
link to somewhere that discusses all the religious aspects of the
argument for the morbidly curious?
From: Kenny Tilton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <suvMd.104957$kq2.57924@twister.nyc.rr.com>
kanzen wrote:
> This "failed experiment" business sounds interesting... do you have a
> link to somewhere that discusses all the religious aspects of the
> argument for the morbidly curious?
> 

I think google groups searching c.l.l. for "scheme" should turn up the 
gist of the debate. The debate is truly a dead horse. And now that Lisp 
is catching on, the NG is having too much fun helping newbies to get 
going on that debate again.

kt

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Cameron MacKinnon
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <Q9udnS3j786n3pjfRVn-hg@golden.net>
Kenny Tilton wrote:
> 
> Scheme is a failed experiment...

I agree. It won originally in goading other Lisps into going beyond
their inconsistent bag of compiled vs. interpreted, lexical versus
dynamic scope HACKS.

Its next trick -- to show that a small, formal specification can (for
some purposes) be better than a large, internally inconsistent set of
non-normative examples trailed by a cloud of language lawyers -- has
been less successful.

Its attempt to show that a Lisp like language can have a thriving user
community and multiple mature implementations on top of a standard which
is evolving, not fossilized, certainly hasn't influenced things elsewhere.

But it sure is funny watching you explain (without really explaining)
to a newbie that his natural instinct not to treat the car of a list any
differently from the rest is, um, immoral.
From: Kenny Tilton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <JfeNd.72538$Yh2.25742359@twister.nyc.rr.com>
Cameron MacKinnon wrote:
> Kenny Tilton wrote:
> 
>>
>> Scheme is a failed experiment...
> 
> 
> I agree. It won originally in goading other Lisps into going beyond
> their inconsistent bag of compiled vs. interpreted, lexical versus
> dynamic scope HACKS.
> 
> Its next trick -- to show that a small, formal specification can (for
> some purposes) be better than a large, internally inconsistent set of
> non-normative examples trailed by a cloud of language lawyers -- has
> been less successful.
> 
> Its attempt to show that a Lisp like language can have a thriving user
> community and multiple mature implementations on top of a standard which
> is evolving, not fossilized, certainly hasn't influenced things elsewhere.
> 
> But it sure is funny watching you explain (without really explaining)
> to a newbie that his natural instinct not to treat the car of a list any
> differently from the rest is, um, immoral.

I doubt I said that, because I /love/ that feature of scheme. My problem 
is with the tiny spec and the absence of mud to play with when building 
applications. CL comes with, yes, hundreds of pages of standardized 
goodies to use. Including macros and an object system.

With Scheme, some assembly is required, and then it is hard to share 
higher-level libs because they may use different packages for the same 
problem.

Besides, having a small spec does nothing for me as a humble application 
programmer. It is like giving an auto mechanic a tool-and-die machine 
instead of a set of tools.

kt

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: John Thingstad
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <opslq6dacgpqzri1@mjolner.upc.no>
On Sun, 06 Feb 2005 01:18:33 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:

>
> Besides, having a small spec does nothing for me as a humble application  
> programmer. It is like giving an auto mechanic a tool-and-die machine  
> instead of a set of tools.
>
> kt
>

As long as you stay with a single system like PLT Sheme you will find
that it has everything you need. It only becomes a problem if you
need to port it to another system. So do you want to write programs
or port programs? lol

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Kenny Tilton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <gagNd.72542$Yh2.25762108@twister.nyc.rr.com>
John Thingstad wrote:
> On Sun, 06 Feb 2005 01:18:33 GMT, Kenny Tilton <·······@nyc.rr.com> wrote:
> 
>>
>> Besides, having a small spec does nothing for me as a humble 
>> application  programmer. It is like giving an auto mechanic a 
>> tool-and-die machine  instead of a set of tools.
>>
>> kt
>>
> 
> As long as you stay with a single system like PLT Sheme you will find
> that it has everything you need. It only becomes a problem if you
> need to port it to another system. So do you want to write programs
> or port programs? lol
> 

After <gasp> two years of working as much on porting software such as 
Cello and even RoboCells, forget LOL, should be <sob>. :) ie, You are 
right, I would rather not be porting software. Because as fat as the 
spec is, it does not include FFI or sockets. Which I guess makes my 
point again: big specs rock.

But of course the whole world should be having as much fun as I am with 
Cells, so porting cannot be completely avoided. Fortunately, now that I 
have backed off the MOP for implementation, Cells runs everywhere 
without a problem. Of couse if the spec included the MOP...

:)

kt

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Jim Newton
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <36du9eF4ssuhbU1@individual.net>
hi Ram, a couple of problems with your expression:
    ((car tmp 1 2))

Problem 1 is that CAR takes exactly 1 argument.  You
have given it 3 arguments.

Problem 2 is that the expression such as
((car tmp) 1 2).  It would be a logical question
to ask why this does not call the function ADD.
But in Common Lisp a function call does not evaluate
the function name.

What would you expect to happen in the following?

(defun f ( a b)
   (+ a b))

(defun g ( a b)
   (- a b))

(let (( f 'g))
   (f 3 2) ;; <-- what would you expect this to return?
)

Would you expect?  Well in common lisp the function F
would be called, not the function G because eval'ing
a list does not evaluate the first element of the list.

As I understand it, scheme would indeed evaluate the symbol
F to get G then call the function G.  That is
a main difference between common lisp and scheme.

so in scheme your modified example ((car tmp) 1 2)
would infact call your ADD function

In common lisp, if you want to call add this way
there is a special function called FUNCALL.

(funcall (car tmp) 1 2)

this would call your ADD function.

-jim

····@sonic.net wrote:
> I'm just getting started with lisp and I don't understand
> an aspect of function calls in lisp.
> 
> Consider this:
> 
> (defun add (a b)
>   (+ a b))
> 
> (setq tmp '(add))
> 
> This is allowed:
> 
> form 1: (add 1 2)
> 
> But this is not:
> 
> form 2: ((car tmp 1 2))
> 
> Why is form 1 allowed but not form 2.
> 
> Thanks for any insight.
> 
> -Ram
> 
From: John Thingstad
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <opsllyropxpqzri1@mjolner.upc.no>
On Thu, 03 Feb 2005 05:59:56 GMT, <····@sonic.net> wrote:

> I'm just getting started with lisp and I don't understand
> an aspect of function calls in lisp.
>
> Consider this:
>
> (defun add (a b)
>   (+ a b))
>
> (setq tmp '(add))
>
> This is allowed:
>
> form 1: (add 1 2)
>
> But this is not:
>
> form 2: ((car tmp 1 2))
>
> Why is form 1 allowed but not form 2.
>
> Thanks for any insight.
>
> -Ram
>

Variables and functions exist in different name spaces.

I could forinstance write (let ((list (list 1 2)) ..)
The first reference of list is the variable list the second to the funtion  
lisp.

Second car takes one argument. (car tmp 1 2) gives an error

To store a function in a variable use #'
To call a function in a variable use the funtion funcall

To summarize...

(defun add (a b) (+ 1 2))

(setf tmp #'add)

(add 1 2)
gives 3

(funcall tmp 1 2)
also gives 3

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: John Thingstad
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <opsllzcvn6pqzri1@mjolner.upc.no>
On Thu, 03 Feb 2005 07:24:50 +0100, John Thingstad  
<··············@chello.no> wrote:


> (defun add (a b) (+ 1 2))
>
> (setf tmp #'add)
>
> (add 1 2)
> gives 3
>
> (funcall tmp 1 2)
> also gives 3
>
to fix your actual example

(setf tmp (list #'add))

(funcall (car tmp) 1 2)
gives 3

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Thomas A. Russ
Subject: Re: beginner question: why does lisp work like this?
Date: 
Message-ID: <ymibrb131qn.fsf@sevak.isi.edu>
····@sonic.net writes:

> 
> I'm just getting started with lisp and I don't understand
> an aspect of function calls in lisp.
> 
> Consider this:
> 
> (defun add (a b)
>   (+ a b))
> 
> (setq tmp '(add))
> 
> This is allowed:
> 
> form 1: (add 1 2)
> 
> But this is not:
> 
> form 2: ((car tmp 1 2))

I think you actually mean:

     ((car tmp) 1 2)

> Why is form 1 allowed but not form 2.
> 
> Thanks for any insight.

Keywords:  Lisp-2 versus Lisp-1 debate
You can use these to search for more than you ever wanted to know...

The reason has to do with different namespaces and evaluation rules that
are based on them.  The first position in a form must resolve to
something that the evaluator can apply to the rest of the form.
Generally this is a function (but it could also be a macro or special
form).  The rules for what is allowed in that position in Common Lisp
are that it must either be a symbol or a lambda expression.

A symbol is intepreted as the name of a function and looked up in the
function namespace.  Scheme, in contrast, does not have a separate
function and value namespace, so it does things a bit differently.
But back to Common Lisp:  There is no general form evaluation that takes
place to come up with the function to apply.  Only the special function
name lookup or the use of a lambda expression is supported.  If you want
to have normal evaluation rules, rather than special evaluation rules
apply to derive the function to apply, then you will need to use either
FUNCALL or APPLY:

  (funcall (car tmp) 1 2)
  (apply (car tmp) '(1 2))

Simplifying a bit, the main difference is that apply takes a list of
arguments whereas funcall has them in-line in the form.



I will warn you that Lisp-1 versus Lisp-2 is one of the highly religious
debates that often pit Lisp versus Scheme in rhetorical battle.

-- 
Thomas A. Russ,  USC/Information Sciences Institute