In article <························@g49g2000cwa.googlegroups.com>,
"Deep" <················@gmail.com> wrote:
> I am missing something here.
>
>
> (functionp (third '(? x #'+)))
#' is a reader macro that makes #'x equivalent to (function x) and 'x is
a reader macro for (quote x) so the reader returns:
(functionp (third (quote (? x (function +)))))
quote is a special form that returns its argument unevaluated, so the
call to third actually sees (? x (function +)) as its argument. It then
returns the third element of that list, (function +), which is a list of
two symbols and not a function.
Depending on what you want to do, you may find fdefinition or fboundp
useful:
(functionp (fdefinition (third '(? x +)))) ==> t
(fboundp (third '(? x +))) ==> #<Compiled-function + #x6089EF6>
Dave
Deep wrote:
> I am missing something here.
>
>
> (functionp (third '(? x #'+)))
>
Whenever you run into something like this, just
back up and un-nest the form, something like ...
CL-USER 1 > (third '(? x #'+))
(FUNCTION +)
CL-USER 2 > (type-of (third '(? x #'+)))
CONS
CL-USER 3 > (functionp (third '(? x #'+)))
NIL
CL-USER 6 > (type-of (third `(? x ,#'+)))
LOW:COMPILED-CODE
CL-USER 7 > (functionp (third `(? x ,#'+)))
T
CL-USER 8 >
"Deep" <················@gmail.com> writes:
> I am missing something here.
> (functionp (third '(? x #'+)))
Not missing -- adding something you didn't mean.
You might have meant this:
(functionp (third (list '? 'x #'+)))
Hi.
.....
> (functionp (third (list '? 'x #'+)))
Maybe he wants a literal ?
(functionp (third '(? x #.#'+))) ==> T
I'm not sure that it's portable ? Is it ?
Regards.
"tichy" <·····@o2.pl> writes:
>> (functionp (third (list '? 'x #'+)))
>
> Maybe he wants a literal ?
>
> (functionp (third '(? x #.#'+))) ==> T
>
> I'm not sure that it's portable ? Is it ?
AFAIK, it's portable.
--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot. don't bother saving your artefacts.
Pascal Bourguignon <····@mouse-potato.com> writes:
> "tichy" <·····@o2.pl> writes:
>>> (functionp (third (list '? 'x #'+)))
>>
>> Maybe he wants a literal ?
>>
>> (functionp (third '(? x #.#'+))) ==> T
>>
>> I'm not sure that it's portable ? Is it ?
>
> AFAIK, it's portable.
As long as you don't compile it. (Functions are not necessarily
externalizable objects.)
-Peter
--
Peter Seibel * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
Peter Seibel wrote:
> Pascal Bourguignon <····@mouse-potato.com> writes:
>
>
>>"tichy" <·····@o2.pl> writes:
>>
>>>>(functionp (third (list '? 'x #'+)))
>>>
>>>Maybe he wants a literal ?
>>>
>>>(functionp (third '(? x #.#'+))) ==> T
>>>
>>>I'm not sure that it's portable ? Is it ?
>>
>>AFAIK, it's portable.
>
>
> As long as you don't compile it. (Functions are not necessarily
> externalizable objects.)
You mean "As long as you don't compile it to a file." It's possible to
compile expressions that contain functions:
? (compile nil '(lambda (x)
(funcall #.(lambda (x) (+ x x)) x)))
#<Anonymous Function #x3321DDE>
NIL
NIL
? (funcall * 5)
10
Pascal
--
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++
Pascal Costanza wrote:
> You mean "As long as you don't compile it to a file." It's possible to
> compile expressions that contain functions:
God anticipated problems with this restriction. That's why he created
load-time-value, which does The Right Thing whether interpreted,
compile'd, or compile-file'd. Details left as an exercise to the
reader (human reader, not cl:read).
"Deep" <················@gmail.com> writes:
> I am missing something here.
>
>
> (functionp (third '(? x #'+)))
Yes. You should forget for a while ' and #' and write explicitely what you mean:
(functionp (third (quote (? x (function +)))))
Is it clearer yet?
If no: (quote (? x (function +)))
evaluates to: (? x (function +))
Do you see a function here?
Try: (COM.INFORMATIMAGO.COMMON-LISP.CONS-TO-ASCII:PRINT-CONSES '(? x #'+))
It prints:
(? . (X . ((FUNCTION . (+ . ())) . ())))
Do you still see a function here?
Unfortunately, some implementations will print (quote (function x)) as
#'x which is highly misleading, since CL actually sees no more than a
list of two symbols. I see no reason to print (quote (x y)) as (x y)
and to print (quote (function y)) as #'y, this is ridiculous.
Anyway, by now you will have seen that there's no function in the list
passed to third, so obviously functionp returns nil.
Perhaps you'll want to write: (functionp (third (list (quote ?)
(quote x)
(function +))))
--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
In article <··············@thalassa.informatimago.com>,
Pascal Bourguignon <····@mouse-potato.com> wrote:
> Unfortunately, some implementations will print (quote (function x)) as
> #'x which is highly misleading, since CL actually sees no more than a
> list of two symbols. I see no reason to print (quote (x y)) as (x y)
> and to print (quote (function y)) as #'y, this is ridiculous.
And I see no reason to print (quote #'y) as (function y). Since there's
no magical presentation information carried through the list structure,
you've got to pick one or the other for output. If you don't like it,
*PRINT-PRETTY* is over there.
-bcd
--
*** Brian Downing <bdowning at lavos dot net>
Brian Downing wrote:
> And I see no reason to print (quote #'y) as (function y). Since there's
> no magical presentation information carried through the list structure,
> you've got to pick one or the other for output. If you don't like it,
> *PRINT-PRETTY* is over there.
The ANS does not specify that #'foo prints as "(function foo)" when
*print-pretty* is false. I believe this is left up to the
implementation.