From: Tyro
Subject: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <ff11f622.0311182015.368dc9e9@posting.google.com>
I am looking for the name of the standard Lisp function that takes an
argument and returns it w/o evaluating. I need such a function for a
default value of the :key keyword parameter in some other function.
Could someone remind me of the function's name?

P.S.
I know that I can write one. But I need the standard version.

From: Joe Marshall
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <n0at3s98.fsf@comcast.net>
····@yandex.ru (Tyro) writes:

> I am looking for the name of the standard Lisp function that takes an
> argument and returns it w/o evaluating. I need such a function for a
> default value of the :key keyword parameter in some other function.
> Could someone remind me of the function's name?
>
> P.S.
> I know that I can write one. But I need the standard version.

Are you thinking of the IDENTITY function?

--------

Eval is the only function that evaluates its argument.


-- 
~jrm
From: Tyro
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <ff11f622.0311190645.3cc08d3a@posting.google.com>
Joe Marshall <·············@comcast.net> wrote in message news:<············@comcast.net>...
> ····@yandex.ru (Tyro) writes:
> 
> > I am looking for the name of the standard Lisp function that takes an
> > argument and returns it w/o evaluating. I need such a function for a
> > default value of the :key keyword parameter in some other function.
> > Could someone remind me of the function's name?
> >
> > P.S.
> > I know that I can write one. But I need the standard version.
> 
> Are you thinking of the IDENTITY function?
> 
> --------
> 
> Eval is the only function that evaluates its argument.

Thank you. identity is exactly what I need.
From: Henrik Motakef
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <868ymcewe1.fsf@pokey.internal.henrik-motakef.de>
····@yandex.ru (Tyro) writes:

> I am looking for the name of the standard Lisp function that takes an
> argument and returns it w/o evaluating. I need such a function for a
> default value of the :key keyword parameter in some other function.

This sounds strange. What exactly are you trying to do?
From: Pascal Bourguignon
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <87wu9wsxtx.fsf@thalassa.informatimago.com>
Henrik Motakef <············@henrik-motakef.de> writes:

> ····@yandex.ru (Tyro) writes:
> 
> > I am looking for the name of the standard Lisp function that takes an
> > argument and returns it w/o evaluating. I need such a function for a
> > default value of the :key keyword parameter in some other function.
> 
> This sounds strange. What exactly are you trying to do?

Sounds like the question of someone who slept in class...

All functions have their arguments evaluated for them.
Macros have their arguments unevaluated.
Special forms are special.

QUOTE is  the standard  Lisp special forma  tha takes an  argument and
returns it without evaluating:

[94]> (QUOTE (+ 1 2))
(+ 1 2)
[95]> (defun some-other-function (&key (key (quote (+ 1 2))))
    (list 'the 'result 'is key))
SOME-OTHER-FUNCTION
[96]> (some-other-function)
(THE RESULT IS (+ 1 2))



-- 
__Pascal_Bourguignon__
http://www.informatimago.com/
From: Thomas A. Russ
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <ymi4qwyvr2k.fsf@sevak.isi.edu>
····@yandex.ru (Tyro) writes:
> 
> Sounds like the answer of someone who is overreacting. ;-) Thank you
> for your help. But I was looking for identity function.

There may have been some overreaction in the ancilliary comments, but
the description of QUOTE as returning an argument w/o evaluating it is
correct, although as noted it technically isn't a function.  Evaluation
of arguments in Lisp is one of the fundamental concepts that one needs
to grasp to understand its operation.

Perhaps a better characterization of your question is that it used terms
with a very specialized meaning (in the context of Lisp), and that you
were unaware of the implications of those meanings.

Meanwhile the identity function does evaluate its argument.  That is
because it really is a function.  For example

  (identity (+ 3 4))     ==>   7           (+ 3 4) was evaluated.
  (quote (+ 3 4))        ==>  (+ 3 4)      (+ 3 4) not evaluated.

Identity simply returns its evaluated argument (unchanged).  As you
point out in code I snipped, this can sometimes be useful when using
higher-order functions such as mapping functions.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Joe Marshall
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <y8uaoo5a.fsf@ccs.neu.edu>
···@sevak.isi.edu (Thomas A. Russ) writes:

> Meanwhile the identity function does evaluate its argument.  That is
> because it really is a function.  For example
>
>   (identity (+ 3 4))     ==>   7           (+ 3 4) was evaluated.

The identity function didn't evaluate it, it got it `pre-evaluated'.
From: Kent M Pitman
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <wkad6q4wgr.fsf@nhplace.com>
···@sevak.isi.edu (Thomas A. Russ) writes:

[I'm quite sure Tom knows all this stuff I'm going to say, since he's been
 around a while.  My reply is more generally addressed to others looking on.]

> ····@yandex.ru (Tyro) writes:
> > 
> > Sounds like the answer of someone who is overreacting. ;-) Thank you
> > for your help. But I was looking for identity function.
> 
> There may have been some overreaction in the ancilliary comments, but
> the description of QUOTE as returning an argument w/o evaluating it is
> correct, although as noted it technically isn't a function.  Evaluation
> of arguments in Lisp is one of the fundamental concepts that one needs
> to grasp to understand its operation.

This is a place that one suddenly realizes that having separate names
for each of "argument form", "actual argument", and "formal argument"
(or "lambda variable" or "parameter") and not calling them all just
"arguments" can be useful.

> Perhaps a better characterization of your question is that it used terms
> with a very specialized meaning (in the context of Lisp), and that you
> were unaware of the implications of those meanings.
> 
> Meanwhile the identity function does evaluate its argument.

No function other than EVAL evaluates its actual argument (the value
of its formal argument) since all evaluation of argument forms occurs
earlier than the call to the function.

In some cases, this means that no evaluation happens at all.  Consider:

  (apply #'identity '((+ 3 4))) => (+ 3 4)

In this case, there isn't an argument form at all.  There is only an actual
argument.  The actual argument does not result from evaluation of an argument
form because there is no function call form.  Rather, the argument form for
APPLY is evaluated to an actual argument for that function, and the argument
setup for IDENTITY is done without any further evaluations either before 
calling IDENTITY or after.

The interesting quality of a 'special operator' and of a 'macro' is that
these have a way of intervening before argument evaluation is done.
A consequence of this, however, is that APPLY cannot be used on special
operators and macros, since special operators and macros manipulate the
call form and use of APPLY implies that there is no call form to manipulate.
This fact is not as visible in CL, but if you go back in time to Maclisp,
where primitive macros were written like:

 (DEFUN STACK-TOP MACRO (MACRO-FORM) (LIST 'CAR (CADR MACRO-FORM)))

and had be repeatedly expanded in the interpreter because the source form
was what was actually executing, it was common to write

 (DEFUN STACK-TOP MACRO (MACRO-FORM)
   (RPLACA MACRO-FORM 'CAR)) ;returns MACRO-FORM
     
which was called a displacing macro because after the first time you did

 (STACK-TOP X)

the actual definition itself had been changed to 

 (CAR X)

Actually, we often used an operator called DISPLACE that would expand into
something like 

 (INTERNAL-DISPLACED-MACRO (CAR X) (STACK-TOP X))

and that would pretty-print as its CADDR but expand trivially as its CADR
in order to save time in case the macro expansion was expensive, since a
lot more code in Maclisp was run interpreted than is probably now true.

In CL, we ask programmers not to displace macro forms because it 
probably won't work to do so [the implementation is probably not executing
the source form, since for a lexically scoped list you have to do a bunch
of pre-processing that wasn't as needed in old dynamic lisps, and you can't
usually execute the raw source code].

The reason that macros cannot be applied, incidentally, is that it would
thwart some displacement styles, often creating a big mess, if you did
 (defun apply-macro (macro-name macro-body)
   (funcall (macro-function macro-name) (cons macro-name macro-body)))
because the identity of the object you were displacing was not the same
each time, so the macro body would be hopelessly mangled, but the macro
form itself could never be mutated and would work much less well the second
time.  Absent displacing macros, I'm not sure there's a good reason (other
than efficiency, which indeed is a killer sometimes, but which could in
principle be left to users and tuning) for not being able to apply a macro
or even a special form.  Of course, it would have to be done in the null
lexical environment, but when you tell people they can't do the apply, they
just cons the form up and toss it to EVAL anyway, so little is saved by
claiming the system can't do it for you.

> [The identity function evaluates its argument]
> because it really is a function.

The identity function receives its argument evaluated because it really
is a function.

> For example
> 
>   (identity (+ 3 4))     ==>   7           (+ 3 4) was evaluated.
>   (quote (+ 3 4))        ==>  (+ 3 4)      (+ 3 4) not evaluated.
> 
> Identity simply returns its evaluated argument (unchanged).

Yes, IDENTITY simply returns its argument, that is, the object that
might have been (and was in the examples shown) evaluated prior to its
receipt.

In (FUNCALL #'IDENTITY '(+ 3 4)) the argument to IDENTITY is never 
evaluated.  Hence, I prefer to avoid referring to IDENTITY's argument
as evaluated.  Evaluation is an artifact of forms, not an artifact of
function calls.  I know this difference seems subtle, but it is critical.

QUOTE actually does have the opportunity to intervene and chooses to
inhibit evaluation before it takes action.  PROGN, by contrast,
has the opportunity to intervene but does not inhibit evaluation.

(progn (+ 3 4)) => 7

In case anyone is curious, PROGN is a special form so that it can
return multiple values.  Normal functions only receive (and hence can
only return) the primary return value of each argument form.

> As you point out in code I snipped, this can sometimes be useful
> when using higher-order functions such as mapping functions.

Yep.
From: Thomas A. Russ
Subject: Re: Newbie question: a function that returns an argument w/o evaluating it...
Date: 
Message-ID: <ymi3cciv713.fsf@sevak.isi.edu>
Kent M Pitman <······@nhplace.com> writes:

> 
> ···@sevak.isi.edu (Thomas A. Russ) writes:
> 
> [I'm quite sure Tom knows all this stuff I'm going to say, since he's been
>  around a while.  My reply is more generally addressed to others looking on.]

Thanks for the kind words. :)

Although I had some grasp of most of what you said, it was not really at
the nice detailed cognitive level.  I found your exposition enlightening
and helped provide a nice structure for characterizing and making
explicit what is going on in the evaluation process.

-Tom.

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