basic quoting question

40 views
Skip to first unread message

Brian Craft

unread,
Oct 8, 2012, 10:43:28 AM10/8/12
to clo...@googlegroups.com
user=> ("X" "Y")
ClassCastException java.lang.String cannot be cast to clojure.lang.IFn  user/eval116 (NO_SOURCE_FILE:32)
user=> '(X Y)
(X Y)
user=> ['X 'Y]
[X Y]
user=> '[X Y]
[X Y]
user=> ('X 'Y)
nil


All of these are as I expected except the last, which I thought would throw something like the 1st case. What's going on there?

Jay Fields

unread,
Oct 8, 2012, 10:45:58 AM10/8/12
to clo...@googlegroups.com
symbol, 'X in the last case, implements IFn, and you're calling it
with the symbol 'Y as an argument.
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Jack Moffitt

unread,
Oct 8, 2012, 11:02:50 AM10/8/12
to clo...@googlegroups.com
> user=> ('X 'Y)
> nil
>
> All of these are as I expected except the last, which I thought would throw
> something like the 1st case. What's going on there?

You've prevented X from being evaluated (it will be seen as the symbol
X), but you haven't prevented evaluation of the function call. Symbols
happen to be functions that look themselves up in collections. 'Y is
not a collection, so it returns nil.

Had you had something else in function position that wasn't actually a
valid function, you would have gotten a ClassCastException.

jack.

Brian Craft

unread,
Oct 8, 2012, 11:06:22 AM10/8/12
to clo...@googlegroups.com, ja...@metajack.im
Thanks!

Is the string vs symbol distinction peculiar to clojure, among lisps?

Ben Smith-Mannschott

unread,
Oct 8, 2012, 11:11:00 AM10/8/12
to clo...@googlegroups.com, ja...@metajack.im
On Mon, Oct 8, 2012 at 5:06 PM, Brian Craft <craft...@gmail.com> wrote:
> Thanks!
>
> Is the string vs symbol distinction peculiar to clojure, among lisps?
>

Yes, strings are distinct from symbols in every reputable lisp.

That symbol and keyword know how to look themselves up in an
associative collection is, as far as i know, unique to Clojure.

// Ben

> On Monday, October 8, 2012 8:03:00 AM UTC-7, Jack Moffitt wrote:
>>
>> > user=> ('X 'Y)
>> > nil
>> >
>> > All of these are as I expected except the last, which I thought would
>> > throw
>> > something like the 1st case. What's going on there?
>>
>> You've prevented X from being evaluated (it will be seen as the symbol
>> X), but you haven't prevented evaluation of the function call. Symbols
>> happen to be functions that look themselves up in collections. 'Y is
>> not a collection, so it returns nil.
>>
>> Had you had something else in function position that wasn't actually a
>> valid function, you would have gotten a ClassCastException.
>>
>> jack.
>
Reply all
Reply to author
Forward
0 new messages