From: ······@gmail.com
Subject: How to execute a function passed as a list
Date: 
Message-ID: <ce56246e-5c84-4299-8124-958cbbe42872@c33g2000hsd.googlegroups.com>
I would like to have a function that takes one argument (a list) and
the executes the function contained in that list, like this:

(defun foo (lt)
     (lt))

where lt: (+ 2 3 4)

Can this be done?

From: Brian
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <8fc4806c-b58f-493d-a241-e97a82a81bdd@b1g2000hsg.googlegroups.com>
······@gmail.com wrote:
> I would like to have a function that takes one argument (a list) and
> the executes the function contained in that list, like this:
>
> (defun foo (lt)
>      (lt))
>
> where lt: (+ 2 3 4)
>
> Can this be done?
Yes (the function EVAL will 'execute' that sample list), BUT if you
need to, it is probably a sign that you are doing something wrong.

What do you need this for?
From: ·······@eurogaran.com
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <c591ab1d-75d8-48e2-bf2d-7b2013c4682c@i29g2000prf.googlegroups.com>
On Mar 13, 6:15 pm, ·······@gmail.com" <······@gmail.com> wrote:
> I would like to have a function that takes one argument (a list) and
> the executes the function contained in that list, like this:
>
> (defun foo (lt)
>      (lt))
>
> where lt: (+ 2 3 4)
>
> Can this be done?

What you are looking for is EVAL
which is one of the fundaments of Lisp :
(setq lt '(+ 1 2 3))
lt  ->  (+ 1 2 3)
(eval lt)  ->  6
From: ······@gmail.com
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <0e449ac6-d84e-4a61-abf7-98579d964c5a@k13g2000hse.googlegroups.com>
On Mar 13, 10:21 am, ·······@eurogaran.com wrote:
> On Mar 13, 6:15 pm, ·······@gmail.com" <······@gmail.com> wrote:
>
> > I would like to have a function that takes one argument (a list) and
> > the executes the function contained in that list, like this:
>
> > (defun foo (lt)
> >      (lt))
>
> > where lt: (+ 2 3 4)
>
> > Can this be done?
>
> What you are looking for is EVAL
> which is one of the fundaments of Lisp :
> (setq lt '(+ 1 2 3))
> lt  ->  (+ 1 2 3)
> (eval lt)  ->  6

Ok, so really what I wanted to do was the following:
(defun foo (lt fn)
   (let lt)
   (eval fn)))

I was going over the funcall procedure but don't think that is what I
really need.
From: Geoffrey Summerhayes
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <9180cda3-a84b-49e8-a65d-22a82e5af0dc@i12g2000prf.googlegroups.com>
On Mar 13, 1:26 pm, ·······@gmail.com" <······@gmail.com> wrote:
>
> Ok, so really what I wanted to do was the following:
> (defun foo (lt fn)
>    (let lt)
>    (eval fn)))
>
> I was going over the funcall procedure but don't think that is what I
> really need.

Guessing you mean something like:

(defun foo(lt fn) (eval `(let ,lt ,fn)))

umm, why are you looking for this?

---
Geoff
From: Jason
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <e4c596e0-4b8b-41fd-9c59-dffa61fbbb46@i29g2000prf.googlegroups.com>
On Mar 13, 10:15 am, ·······@gmail.com" <······@gmail.com> wrote:
> I would like to have a function that takes one argument (a list) and
> the executes the function contained in that list, like this:
>
> (defun foo (lt)
>      (lt))
>
> where lt: (+ 2 3 4)
>
> Can this be done?

(defun foo (lt)
   (apply (car lt) (cdr lt)))
From: Kaz Kylheku
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <e3bdd7ce-b03a-4526-8706-ae58b255a19b@s37g2000prg.googlegroups.com>
On Mar 13, 10:40 am, Jason <·······@gmail.com> wrote:
> On Mar 13, 10:15 am, ·······@gmail.com" <······@gmail.com> wrote:
>
> > I would like to have a function that takes one argument (a list) and
> > the executes the function contained in that list, like this:
>
> > (defun foo (lt)
> >      (lt))
>
> > where lt: (+ 2 3 4)
>
> > Can this be done?
>
> (defun foo (lt)
>    (apply (car lt) (cdr lt)))


Oops!

  ;; problem: LET is not a function, but a special op.
  (foo '(let ((x 3)) (1+ x)))

  ;; problem: 42 is not a cons.
  (foo 42)

  ;; problem: arguments are not avaluated
  (foo '(list (+ 2 2)) -> ((+ 2 2))  ; expected (4)

But FOO probably saves a couple of machine cycles over EVAL in the non-
failing situations. :)
From: Sohail Somani
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <H7eCj.77629$FO1.6390@edtnps82>
On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:

[snip]
> (defun foo (lt)
>    (apply (car lt) (cdr lt)))

Eek. I know car and cdr are cool but people can we please use first and 
rest. They have actual meaning!

-- 
Sohail Somani
http://uint32t.blogspot.com
From: Mike G.
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <b01ff483-6749-4296-a8fc-3197193a9f5d@b64g2000hsa.googlegroups.com>
On Mar 13, 2:11 pm, Sohail Somani <······@taggedtype.net> wrote:
> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>
> [snip]
>
> > (defun foo (lt)
> >    (apply (car lt) (cdr lt)))
>
> Eek. I know car and cdr are cool but people can we please use first and
> rest. They have actual meaning!

So do CAR and CDR.

-M
From: Thomas A. Russ
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <ymiod9ifo9o.fsf@blackcat.isi.edu>
Sohail Somani <······@taggedtype.net> writes:

> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
> 
> [snip]
> > (defun foo (lt)
> >    (apply (car lt) (cdr lt)))
> 
> Eek. I know car and cdr are cool but people can we please use first and 
> rest. They have actual meaning!

So do CAR and CDR.  ;)

But I don't think that you will have much success in getting the old
fogies among us to change our style at this late stage of the game....

Anyway, what is the application that you need this for?  Depending on
what larger goal you are trying to accomplish, there may be other
solutions available as well.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Kent M Pitman
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <utzjanr7b.fsf@nhplace.com>
···@sevak.isi.edu (Thomas A. Russ) writes:

> Sohail Somani <······@taggedtype.net> writes:
> 
> > On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
> > 
> > [snip]
> > > (defun foo (lt)
> > >    (apply (car lt) (cdr lt)))
> > 
> > Eek. I know car and cdr are cool but people can we please use first and 
> > rest. They have actual meaning!
> 
> So do CAR and CDR.  ;)

I agree.

The rest of this reply is really a reply to Sohail.

Moreover, the abstractions are different and both relevant.

The CAR/CDR abstraction tells us that what is passed as an argument, lt,
would, in terms of other languages like C#, might be written:

  Pair<Delegate,IList>

It's the case that Pair often has a First/Second accessor, but that's bad
naming, actually.  Because really it means Left and Right, or LHS and RHS.
But it's not like there's a Third or an Nth. There are just two.

Now, you can in C# pretend there is an abstraction which is a lisp-like list,
but C# really doesn't have that notion of a recursive type, other than that
you could write

  Pair<Object,Object>

but then you don't know that this is intended to be linked, and you don't have
any reason to suppose nth would be meaningful.  Certainly if it was, then
Second would return the wrong thing because it would not return Second of Rest.

My point is that FIRST/REST are NOT, as often suggested, synoyms for one 
another any more than NOT and NULL are.  NOT/NULL are synonyms to _some_
people who decline to make the distinction others do, in the same sense
that CAR/FIRST and CDR/REST are synonyms.  But some people (I am one of them)
try to write CAR and CDR when suggesting a non-homogenous backbone [not in
type, but in intent], while they try to write FIRST and REST when suggesting
a homogenous backbone.

So I might write:

  (defun my-eval (x)
    (if (atom x) (my-symbol-value x)
        (apply (car x) (my-eval-args (cdr x)))))

because there is an asymmetry between the nature of the car and the cdr.
While I would write [if I wrote things tail-recursively, which I usually 
don't when I mean iteration]:

  (defun my-eval-args (args)
    (if (null args) '()
        (cons (my-eval (first args))
              (my-eval-args (rest args)))))

You might, of course, decide you'd write my-eval with first/rest as well.
And that's fine.  But the issue is that this is a subjective decision and
at least one subjective way of doing it is to make the distinction I have.
From: Sohail Somani
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <h5jCj.78588$FO1.35412@edtnps82>
On Thu, 13 Mar 2008 19:23:52 -0400, Kent M Pitman wrote:

> ···@sevak.isi.edu (Thomas A. Russ) writes:
> 
>> Sohail Somani <······@taggedtype.net> writes:
>> 
>> > On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>> > 
>> > [snip]
>> > > (defun foo (lt)
>> > >    (apply (car lt) (cdr lt)))
>> > 
>> > Eek. I know car and cdr are cool but people can we please use first
>> > and rest. They have actual meaning!
>> 
>> So do CAR and CDR.  ;)
> 
> I agree.
> 
> The rest of this reply is really a reply to Sohail.
> 
> Moreover, the abstractions are different and both relevant.
> 
> The CAR/CDR abstraction tells us that what is passed as an argument, lt,
> would, in terms of other languages like C#, might be written:
> 
>   Pair<Delegate,IList>
> 
[snip]

Using C# to explain Lisp. There is something wrong with that!

> My point is that FIRST/REST are NOT, as often suggested, synoyms for one
> another any more than NOT and NULL are.  

I don't think I said first/rest are synonyms for each other! Unless the 
words first,rest and synonym mean something different in your part of the 
world. Did you mean first/car and rest/cdr?

> NOT/NULL are synonyms to _some_
> people who decline to make the distinction others do, in the same sense
> that CAR/FIRST and CDR/REST are synonyms.  But some people (I am one of
> them) try to write CAR and CDR when suggesting a non-homogenous backbone
> [not in type, but in intent], while they try to write FIRST and REST
> when suggesting a homogenous backbone.

Ah. I understand now. So when Kent uses first/rest he is saying first foo 
and rest of the foos. But when he says car/cdr he means first element in 
list, rest of the elements in the list.

That is (in my opinion) a good coding standard.

-- 
Sohail Somani
http://uint32t.blogspot.com
x
From: Pascal Bourguignon
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <87tzj9re4f.fsf@thalassa.informatimago.com>
Sohail Somani <······@taggedtype.net> writes:

> On Thu, 13 Mar 2008 19:23:52 -0400, Kent M Pitman wrote:
>
>> ···@sevak.isi.edu (Thomas A. Russ) writes:
>> NOT/NULL are synonyms to _some_
>> people who decline to make the distinction others do, in the same sense
>> that CAR/FIRST and CDR/REST are synonyms.  But some people (I am one of
>> them) try to write CAR and CDR when suggesting a non-homogenous backbone
>> [not in type, but in intent], while they try to write FIRST and REST
>> when suggesting a homogenous backbone.
>
> Ah. I understand now. So when Kent uses first/rest he is saying first foo 
> and rest of the foos. But when he says car/cdr he means first element in 
> list, rest of the elements in the list.

You got it wrong.

car/cdr mean the 'a' and the 'd' slots of a cons.  Nothing about any
list ever implied when you use car/cdr.  Here we only speak about
conses.

first/rest mean the head and tail of a list.  

But since we were discussing function calls, function names and
arguments, we should use:

function-call-function / function-call-arguments, which are as easy to
implement using lower abstraction as first/rest.



Using car/cdr when you have a list is equivalent to speak of yourself
as a bunch of cells.   Using car/cdr when you have function calls is
equivalent to speak of yourself as a bunch of atoms.

Hey atom #:CARBON-123091275201, move over there (and let's see if
Sohail follows...).


> That is (in my opinion) a good coding standard.

Yes.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.
From: Kent M Pitman
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <uabl1sphz.fsf@nhplace.com>
Pascal Bourguignon <···@informatimago.com> writes:

> > Ah. I understand now. So when Kent uses first/rest he is saying first foo 
> > and rest of the foos. But when he says car/cdr he means first element in 
> > list, rest of the elements in the list.
> 
> You got it wrong.
> 
> car/cdr mean the 'a' and the 'd' slots of a cons.  Nothing about any
> list ever implied when you use car/cdr.  Here we only speak about
> conses.
> 
> first/rest mean the head and tail of a list.  
> 
> But since we were discussing function calls, function names and
> arguments, we should use:
> 
> function-call-function / function-call-arguments, which are as easy to
> implement using lower abstraction as first/rest.

Or using car/cdr.  My point is that if you think of a function call
not as a list of things all the same, but as, for example:

  f(a,b,c)

where f is really not part of the list, but is somehow paired with its
argument list, and where the args happen to be a list, but not a list
of which f is conceptually a part, then car is the right accessor for
the function name, and cdr for the arglist.

If, instead, you think (f a b c) is four things of the same kind, rather than
the join of a single thing [the function] that is of one kind and three things
[the args] of another kind, then first and rest are your accessors of choice.

So it depends on what you are trying to express as to which abstraction
you choose, just as people might legitimately answer the question "how many
people were in the discussion?", when 1 teacher and 5 students ar present,
with the number 5 or the number 6.  Someone answering 5 is trying to say
the discussion is among the students.  Someone answering 6 is focusing on
the fact that a teacher is a part of the discussion.  But neither answer is
strictly wrong.  People often refer to "class size" in schools without 
mentioning the teacher, even though the teacher is clearly part of the class.

So people often convey very complicated and subtle information through
their choice of abstraction.  There are often multiple views on the same
piece of data.

Another example is that (cons 'a '()) vs (list 'a) conveys very
different information to readers of the code.  The former is a pair
that might or might not be intended to be viewed as a list, while the
latter is fairly obviously intended to be seen as a list.
From: Majorinc Kazimir
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <MPG.22473430e4fa917d989689@news.t-com.hr>
Interesting idea, using synonyms to provide clarity of the 
intention and possibly easier reimplementation in the future. I 
think I might adopt that. 
From: Jason
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <4cd20f93-fa92-43cf-9766-6ea081dd04c1@e23g2000prf.googlegroups.com>
On Mar 13, 11:11 am, Sohail Somani <······@taggedtype.net> wrote:
> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>
> [snip]
>
> > (defun foo (lt)
> >    (apply (car lt) (cdr lt)))
>
> Eek. I know car and cdr are cool but people can we please use first and
> rest. They have actual meaning!
>
> --
> Sohail Somanihttp://uint32t.blogspot.com

first means car, and rest means cdr. Why use an alias when you can use
the real thing?
From: Pascal Bourguignon
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <873aqus8gq.fsf@thalassa.informatimago.com>
Jason <·······@gmail.com> writes:

> On Mar 13, 11:11 am, Sohail Somani <······@taggedtype.net> wrote:
>> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>>
>> [snip]
>>
>> > (defun foo (lt)
>> >    (apply (car lt) (cdr lt)))
>>
>> Eek. I know car and cdr are cool but people can we please use first and
>> rest. They have actual meaning!
>>
>> --
>> Sohail Somanihttp://uint32t.blogspot.com
>
> first means car, and rest means cdr. Why use an alias when you can use
> the real thing?

Because abstraction is good.  Actually,  neither CAR or FIRST should
be used.  You should define abtractions such as:

(defun make-function-call (function-name arguments) (cons function-name arguments))
(defun function-call-function  (call) (car call))
(defun function-call-arguments (call) (cdr call))

or:

(defun make-function-call (function-name arguments) (list* function-name arguments))
(defun function-call-function  (call) (first call))
(defun function-call-arguments (call) (rest call))

or:

(defclss function-call (expression)
  ((function  :initarg :function-name :accessor function-call-function)
   (argumetns :initarg :arguments     :accessor function-call-arguments)))
(defun make-function-call (function-name arguments) 
   (make-instance 'function-call :function-name function-name
                                 :arguments arguments))

etc...

One nice thing with such abstractions as you can see, is that you can
change the implementation easily.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein
From: Sohail Somani
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <zsgCj.77690$FO1.15765@edtnps82>
On Thu, 13 Mar 2008 20:57:25 +0100, Pascal Bourguignon wrote:

> Jason <·······@gmail.com> writes:
> 
>> On Mar 13, 11:11 am, Sohail Somani <······@taggedtype.net> wrote:
[snip]
>>> Eek. I know car and cdr are cool but people can we please use first
>>> and rest. They have actual meaning!
>>
>> first means car, and rest means cdr. Why use an alias when you can use
>> the real thing?
> 
> Because abstraction is good.

I'm not quite sure how to interpret the rest of your message!

-- 
Sohail Somani
http://uint32t.blogspot.com
From: Dan Muller
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <LDjCj.14027$5K1.4319@newssvr12.news.prodigy.net>
Sohail Somani <······@taggedtype.net> writes:

> On Thu, 13 Mar 2008 20:57:25 +0100, Pascal Bourguignon wrote:
>
>> Jason <·······@gmail.com> writes:
>> 
>>> On Mar 13, 11:11 am, Sohail Somani <······@taggedtype.net> wrote:
> [snip]
>>>> Eek. I know car and cdr are cool but people can we please use first
>>>> and rest. They have actual meaning!
>>>
>>> first means car, and rest means cdr. Why use an alias when you can use
>>> the real thing?
>> 
>> Because abstraction is good.
>
> I'm not quite sure how to interpret the rest of your message!
>

By using EVAL, of course.
From: Espen Vestre
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <m1myp18zo9.fsf@gazonk.vestre.net>
Dan Muller <·········@sneakemail.com> writes:

>> I'm not quite sure how to interpret the rest of your message!
>>
>
> By using EVAL, of course.

One should always try to compile the essence of an article before
trying to evaluate it.
-- 
  (espen)
From: Ken Tilton
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <47d9b3d2$0$5618$607ed4bc@cv.net>
Sohail Somani wrote:
> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
> 
> [snip]
> 
>>(defun foo (lt)
>>   (apply (car lt) (cdr lt)))
> 
> 
> Eek. I know car and cdr are cool but people can we please use first and 
> rest. They have actual meaning!
> 

CAR and CDR are faster, they are machine language.

hth, kenny

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Sohail Somani
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <bdjCj.78676$FO1.65666@edtnps82>
On Thu, 13 Mar 2008 19:08:02 -0400, Ken Tilton wrote:

> Sohail Somani wrote:
[snip]
>> Eek. I know car and cdr are cool but people can we please use first and
>> rest. They have actual meaning!
>> 
>> 
> CAR and CDR are faster, they are machine language.
> 
> hth, kenny

That helped a lot, thanks. Machines are fast. Lisp is interpreted.

/me locates flame-retardant suit

-- 
Sohail Somani
http://uint32t.blogspot.com
From: Geoffrey Summerhayes
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <574866a2-6e85-476d-adce-0c29cbcc904f@s8g2000prg.googlegroups.com>
On Mar 13, 7:59 pm, Sohail Somani <······@taggedtype.net> wrote:
> On Thu, 13 Mar 2008 19:08:02 -0400, Ken Tilton wrote:
> > Sohail Somani wrote:
> [snip]
> >> Eek. I know car and cdr are cool but people can we please use first and
> >> rest. They have actual meaning!
>
> > CAR and CDR are faster, they are machine language.
>
> > hth, kenny
>
> That helped a lot, thanks. Machines are fast. Lisp is interpreted.
>
> /me locates flame-retardant suit

Don't be an idiot.
Lisp is compiled,
*Usenet posts* are interpreted...badly.

---
Geoff
From: Ken
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <47da8edb$0$5644$607ed4bc@cv.net>
Geoffrey Summerhayes wrote:
> On Mar 13, 7:59 pm, Sohail Somani <······@taggedtype.net> wrote:
>> On Thu, 13 Mar 2008 19:08:02 -0400, Ken Tilton wrote:
>>> Sohail Somani wrote:
>> [snip]
>>>> Eek. I know car and cdr are cool but people can we please use first and
>>>> rest. They have actual meaning!
>>> CAR and CDR are faster, they are machine language.
>>> hth, kenny
>> That helped a lot, thanks. Machines are fast. Lisp is interpreted.
>>
>> /me locates flame-retardant suit
> 
> Don't be an idiot.
> Lisp is compiled,
> *Usenet posts* are interpreted...badly.

I was wondering what all those .FASLs were...

kenny
From: Frank Buss
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <1guxgzpgn496w.1vrn3ahpep3az.dlg@40tude.net>
Ken Tilton wrote:

> Sohail Somani wrote:
>> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>> 
>> [snip]
>> 
>>>(defun foo (lt)
>>>   (apply (car lt) (cdr lt)))
>> 
>> 
>> Eek. I know car and cdr are cool but people can we please use first and 
>> rest. They have actual meaning!
>> 
> 
> CAR and CDR are faster, they are machine language.

on ancient machines, only. But nevertheless, CAR, CDR and things like CADR
are very useful, if not abused (like CAAAAR) and every Lisp programmer
knows what it means and when to use it.

-- 
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Raffael Cavallaro
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <2008031319282682327-raffaelcavallaro@pasdespamsilvousplaitmaccom>
On 2008-03-13 19:18:08 -0400, Frank Buss <··@frank-buss.de> said:

>> 
>> CAR and CDR are faster, they are machine language.
> 
> on ancient machines, only.

it was a joke Frank
From: Kent M Pitman
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <u4pba2jl1.fsf@nhplace.com>
Raffael Cavallaro <················@pas-d'espam-s'il-vous-plait-mac.com> writes:

> On 2008-03-13 19:18:08 -0400, Frank Buss <··@frank-buss.de> said:
> 
> >> CAR and CDR are faster, they are machine language.
> > on ancient machines, only.
> 
> it was a joke Frank

Yeah, but a joke that works only on ancient programmers.  Now if you
just updated the joke, as in:

 FIRST and REST are faster, they are machine language.

it should be hysterically funny to younger, trendier programmers.

... or maybe only virtually funny.
From: Thomas F. Burdick
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <9c8bc147-f36a-4d80-b2bd-23cd70707a56@s37g2000prg.googlegroups.com>
On Mar 14, 2:14 am, Kent M Pitman <······@nhplace.com> wrote:
> Raffael Cavallaro <················@pas-d'espam-s'il-vous-plait-mac.com> writes:
> > On 2008-03-13 19:18:08 -0400, Frank Buss <····@frank-buss.de> said:
>
> > >> CAR and CDR are faster, they are machine language.
> > > on ancient machines, only.
>
> > it was a joke Frank
>
> Yeah, but a joke that works only on ancient programmers.  Now if you
> just updated the joke, as in:
>
>  FIRST and REST are faster, they are machine language.
>
> it should be hysterically funny to younger, trendier programmers.
>
> ... or maybe only virtually funny.

"... so I says to her, I says 'let me slip out of this wet cdr and
into a dry [edx+1]!' ..."
From: Steven M. Haflich
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <EOHCj.3103$6H.394@newssvr22.news.prodigy.net>
Thomas F. Burdick wrote:
>>  FIRST and REST are faster, they are machine language.

You don't need first and rest to achieve an efficient implementation
of car and cdr.  I use these definitions:

(defun car (x)
   (destructuring-bind (car . cdr)
       x
     (declare (ignore cdr))
     car)))

(defun cdr (x)
   (destructuring-bind (car . cdr)
       x
     (declare (ignore car))
     cdr)))

but I also sneak in compiler macros so they inline in compiled code.
From: Ken Tilton
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <47db6cbb$0$25057$607ed4bc@cv.net>
Steven M. Haflich wrote:
> Thomas F. Burdick wrote:
> 
>>>  FIRST and REST are faster, they are machine language.
> 
> 
> You don't need first and rest to achieve an efficient implementation
> of car and cdr.  I use these definitions:
> 
> (defun car (x)
>   (destructuring-bind (car . cdr)
>       x
>     (declare (ignore cdr))
>     car)))


Nice! But use first and rest for the var names, that's machine language, 
Burdick says it'll run faster.

hth, kenny


> 
> (defun cdr (x)
>   (destructuring-bind (car . cdr)
>       x
>     (declare (ignore car))
>     cdr)))
> 
> but I also sneak in compiler macros so they inline in compiled code.

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Kaz Kylheku
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <e5b9ed33-117c-4cf1-b68c-8ea358f2dad5@s19g2000prg.googlegroups.com>
On Mar 13, 6:14 pm, Kent M Pitman <······@nhplace.com> wrote:
> Raffael Cavallaro <················@pas-d'espam-s'il-vous-plait-mac.com> writes:
> > On 2008-03-13 19:18:08 -0400, Frank Buss <····@frank-buss.de> said:
>
> > >> CAR and CDR are faster, they are machine language.
> > > on ancient machines, only.
>
> > it was a joke Frank
>
> Yeah, but a joke that works only on ancient programmers.  Now if you
> just updated the joke, as in:
>
>  FIRST and REST are faster, they are machine language.

But what about their relative performance?

In every benchmark I have ever come across, the FIRST beat the REST.

*duck*
From: Duane Rettig
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <o0fxutwzo8.fsf@gemini.franz.com>
Sohail Somani <······@taggedtype.net> writes:

> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>
> [snip]
>> (defun foo (lt)
>>    (apply (car lt) (cdr lt)))
>
> Eek. I know car and cdr are cool but people can we please use first and 
> rest. They have actual meaning!

Ah, yes.  That's like some programming I once ran across 35 years ago,
aound the time when Pascal was making a bid to take over C shops, and
one brilliant programmer had a pascal.h file that included

 #define BEGIN {
 #define END }

so that he could write more pascal-like programs.

Well, of course, BEGIN seems to have a lot more meaning than {, but
that's not the point - the point is to match the meaning to the
context, and in such a context (i.e. a C program) the { was much much
more meaningful than the BEGIN.

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182   
From: Ken
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <47da2ab6$0$5622$607ed4bc@cv.net>
> Sohail Somani <······@taggedtype.net> writes:
> 
>> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>>
>> [snip]
>>> (defun foo (lt)
>>>    (apply (car lt) (cdr lt)))
>> Eek. I know car and cdr are cool but...

Ten more years in the temple for you. There is no higher value than 
cool. Meanwhile, few things are more enjoyable about Lisp than its 
history and nothing conveys that better than the musty smell of some of 
the names. Close second to the three ways of accessing a sequence by 
position.

I mean, you *do* use rplaca and rplacd over (setf car) and (setf cdr) 
don't you?...oh my.

kenny

ps. No, my desktop still has not recovered. But it is now daring me to 
reattach some peripherals, lessee... k
From: Jason
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <848e9191-eed4-473c-b03d-977e556a5b7c@i7g2000prf.googlegroups.com>
On Mar 14, 12:35 am, Ken <·················@optonline.net> wrote:
> > Sohail Somani <······@taggedtype.net> writes:
>
> >> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>
> >> [snip]
> >>> (defun foo (lt)
> >>>    (apply (car lt) (cdr lt)))
> >> Eek. I know car and cdr are cool but...
>
> Ten more years in the temple for you. There is no higher value than
> cool. Meanwhile, few things are more enjoyable about Lisp than its
> history and nothing conveys that better than the musty smell of some of
> the names. Close second to the three ways of accessing a sequence by
> position.
>
> I mean, you *do* use rplaca and rplacd over (setf car) and (setf cdr)
> don't you?...oh my.
>
> kenny
>
> ps. No, my desktop still has not recovered. But it is now daring me to
> reattach some peripherals, lessee... k

Speaking of cool, I have a plan to build an entire language using
nothing but regular expression syntax and here doc formatting.

Now THAT would be cool!
From: Marco Antoniotti
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <3f180893-54c2-4675-9f65-5c39823caf7c@h11g2000prf.googlegroups.com>
On Mar 14, 3:22 pm, Jason <·······@gmail.com> wrote:
> On Mar 14, 12:35 am, Ken <·················@optonline.net> wrote:
>
>
>
> > > Sohail Somani <······@taggedtype.net> writes:
>
> > >> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>
> > >> [snip]
> > >>> (defun foo (lt)
> > >>>    (apply (car lt) (cdr lt)))
> > >> Eek. I know car and cdr are cool but...
>
> > Ten more years in the temple for you. There is no higher value than
> > cool. Meanwhile, few things are more enjoyable about Lisp than its
> > history and nothing conveys that better than the musty smell of some of
> > the names. Close second to the three ways of accessing a sequence by
> > position.
>
> > I mean, you *do* use rplaca and rplacd over (setf car) and (setf cdr)
> > don't you?...oh my.
>
> > kenny
>
> > ps. No, my desktop still has not recovered. But it is now daring me to
> > reattach some peripherals, lessee... k
>
> Speaking of cool, I have a plan to build an entire language using
> nothing but regular expression syntax and here doc formatting.
>
> Now THAT would be cool!

You cannot beat this: http://www.dangermouse.net/esoteric/piet.html
(but wait! Is "cool" right in this case? :) )

Cheers
--
Marco
From: Rob Warnock
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <Pf6dndFHyqNx30banZ2dnUVZ_qainZ2d@speakeasy.net>
Marco Antoniotti  <·······@gmail.com> wrote:
+---------------
| On Mar 14, 3:22�pm, Jason <·······@gmail.com> wrote:
| > Speaking of cool, I have a plan to build an entire language using
| > nothing but regular expression syntax and here doc formatting.
| > Now THAT would be cool!
| 
| You cannot beat this: http://www.dangermouse.net/esoteric/piet.html
| (but wait! Is "cool" right in this case? :) )
+---------------

Come on, guys! No discussion of perverse Turing-complete languages
is complete without a mention of "Brainf*ck" [eight instructions
denoted by "<>+-.,[]"]:

    http://www.muppetlabs.com/~breadbox/bf/

and "Whitespace" [only three ops, using #\space, #\tab, and #\newline]:

    http://compsoc.dur.ac.uk/whitespace/


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Pascal Bourguignon
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <87hcf9q760.fsf@thalassa.informatimago.com>
Marco Antoniotti <·······@gmail.com> writes:

> On Mar 14, 3:22�pm, Jason <·······@gmail.com> wrote:
>> On Mar 14, 12:35 am, Ken <·················@optonline.net> wrote:
>>
>>
>>
>> > > Sohail Somani <······@taggedtype.net> writes:
>>
>> > >> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>>
>> > >> [snip]
>> > >>> (defun foo (lt)
>> > >>> � �(apply (car lt) (cdr lt)))
>> > >> Eek. I know car and cdr are cool but...
>>
>> > Ten more years in the temple for you. There is no higher value than
>> > cool. Meanwhile, few things are more enjoyable about Lisp than its
>> > history and nothing conveys that better than the musty smell of some of
>> > the names. Close second to the three ways of accessing a sequence by
>> > position.
>>
>> > I mean, you *do* use rplaca and rplacd over (setf car) and (setf cdr)
>> > don't you?...oh my.
>>
>> > kenny
>>
>> > ps. No, my desktop still has not recovered. But it is now daring me to
>> > reattach some peripherals, lessee... k
>>
>> Speaking of cool, I have a plan to build an entire language using
>> nothing but regular expression syntax and here doc formatting.
>>
>> Now THAT would be cool!
>
> You cannot beat this: http://www.dangermouse.net/esoteric/piet.html
> (but wait! Is "cool" right in this case? :) )

Yep, piet is cool.   Cooler would be a lisp compiler targetting piet! :-)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

ATTENTION: Despite any other listing of product contents found
herein, the consumer is advised that, in actuality, this product
consists of 99.9999999999% empty space.
From: Sohail Somani
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <qZCCj.88554$w57.2959@edtnps90>
On Fri, 14 Mar 2008 23:20:39 +0100, Pascal Bourguignon wrote:

>> You cannot beat this: http://www.dangermouse.net/esoteric/piet.html
>> (but wait! Is "cool" right in this case?  )
> 
> Yep, piet is cool.   Cooler would be a lisp compiler targetting piet!

Sounds like a Summer of Code project!

-- 
Sohail Somani
http://uint32t.blogspot.com
From: Duane Rettig
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <o063vpcnea.fsf@gemini.franz.com>
Jason <·······@gmail.com> writes:

> On Mar 14, 12:35 am, Ken <·················@optonline.net> wrote:
>> > Sohail Somani <······@taggedtype.net> writes:
>>
>> >> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>>
>> >> [snip]
>> >>> (defun foo (lt)
>> >>>    (apply (car lt) (cdr lt)))
>> >> Eek. I know car and cdr are cool but...
>>
>> Ten more years in the temple for you. There is no higher value than
>> cool. Meanwhile, few things are more enjoyable about Lisp than its
>> history and nothing conveys that better than the musty smell of some of
>> the names. Close second to the three ways of accessing a sequence by
>> position.
>>
>> I mean, you *do* use rplaca and rplacd over (setf car) and (setf cdr)
>> don't you?...oh my.
>>
>> kenny
>>
>> ps. No, my desktop still has not recovered. But it is now daring me to
>> reattach some peripherals, lessee... k
>
> Speaking of cool, I have a plan to build an entire language using
> nothing but regular expression syntax and here doc formatting.
>
> Now THAT would be cool!

Another resurgence of APL, eh?

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182   
From: Evan Monroig
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <87prtxu4ig.fsf@obakechan.net>
Duane Rettig <·····@franz.com> writes:

> Sohail Somani <······@taggedtype.net> writes:
>
>> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>>
>> [snip]
>>> (defun foo (lt)
>>>    (apply (car lt) (cdr lt)))
>>
>> Eek. I know car and cdr are cool but people can we please use first
>> and rest. They have actual meaning!
>
> Ah, yes.  That's like some programming I once ran across 35 years ago,
> aound the time when Pascal was making a bid to take over C shops, and
> one brilliant programmer had a pascal.h file that included
>
>  #define BEGIN {
>  #define END }

Speaking of which, what do people think about defining reader macros #f
and #t for nil and t?

Not that I use it, but I've seen that in several libraries.

Evan
From: Pascal J. Bourguignon
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <7cprtxpksi.fsf@pbourguignon.anevia.com>
Evan Monroig <·········@obakechan.net> writes:

> Duane Rettig <·····@franz.com> writes:
>
>> Sohail Somani <······@taggedtype.net> writes:
>>
>>> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>>>
>>> [snip]
>>>> (defun foo (lt)
>>>>    (apply (car lt) (cdr lt)))
>>>
>>> Eek. I know car and cdr are cool but people can we please use first
>>> and rest. They have actual meaning!
>>
>> Ah, yes.  That's like some programming I once ran across 35 years ago,
>> aound the time when Pascal was making a bid to take over C shops, and
>> one brilliant programmer had a pascal.h file that included
>>
>>  #define BEGIN {
>>  #define END }
>
> Speaking of which, what do people think about defining reader macros #f
> and #t for nil and t?

Unless the point was to load a scheme library to be used in Common
Lisp, the author shall be taken outside and shot� expeditively.



�Not necessarily with a gun, you can find something funnier to shoot at him.
-- 
__Pascal Bourguignon__
From: Campo
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <6d46db67-f0f3-4684-99a7-d6b5b4aa7f9f@m36g2000hse.googlegroups.com>
On Mar 13, 2:11 pm, Sohail Somani <······@taggedtype.net> wrote:
> On Thu, 13 Mar 2008 10:40:06 -0700, Jason wrote:
>
> [snip]
>
> > (defun foo (lt)
> >    (apply (car lt) (cdr lt)))
>
> Eek. I know car and cdr are cool but people can we please use first and
> rest. They have actual meaning!

Car and cdr have meaning too. Actually, having both "first/rest" and
"car/cdr" is useful. Which set you use can show intention, without
overhead, which seems lispy to me (syntax really does matter). I have
to admit that I often break that by using the "car/cdr" set in places
where "first/rest" is more appropriate, but the fact that I have
filthy habits does not impair the point.

Also, the composition of car and cdr is useful. I often start
something off with just some nested lists for structure. Then I type
(cdaddr x) into the repl to make sure it gets what I want. Then I use
(cdaddr) to get at data, inline. Eventually I get confused, so I
define a function with the body (cdaddr x), and give it a name. The
calling code can often be unchanged if I switch to CLOS later. And, as
my AI prof said "there are even some lisp geeks who know how to
pronounce all of the legal combinations of car and cdr." Of course
cddddr is a tongue twister for anyone, but I've never seen it come up.
From: Sohail Somani
Subject: Re: How to execute a function passed as a list
Date: 
Message-ID: <m6eCj.77627$FO1.76282@edtnps82>
On Thu, 13 Mar 2008 10:15:23 -0700, ······@gmail.com wrote:

> I would like to have a function that takes one argument (a list) and the
> executes the function contained in that list, like this:
> 
> (defun foo (lt)
>      (lt))
> 
> where lt: (+ 2 3 4)
> 
> Can this be done?

(defun foo (lt)
  (apply (first lt) (rest lt)))

-- 
Sohail Somani
http://uint32t.blogspot.com