Metadata on symbols differ with caret reader

273 views
Skip to first unread message

mdzaebel

unread,
Jan 9, 2011, 4:52:19 PM1/9/11
to Clojure
Hi,

(meta ^:k []) --> {:tag :k}
(meta ^:k 'o) --> nil
(meta(with-meta 'o {:tag :k})) --> {:tag :v}

Why doesn't the second line return the metadata?

Thanks, Marc

Using Clj 1.2

Meikel Brandmeyer

unread,
Jan 9, 2011, 7:09:21 PM1/9/11
to clo...@googlegroups.com
Hi,

Am 09.01.2011 um 22:52 schrieb mdzaebel:
> (meta ^:k []) --> {:tag :k}
> (meta ^:k 'o) --> nil
> (meta(with-meta 'o {:tag :k})) --> {:tag :v}
>
> Why doesn't the second line return the metadata?

Because 'o expands to (quote o) and you actually hint this list. You might try (meta ' ^:k o).

Sincerely
Meikel

Tim Robinson

unread,
Jan 9, 2011, 7:10:16 PM1/9/11
to Clojure
You must have something messed up:

In line 1 (meta ^:k []) does not return {:tag :k} it returns nil and
I am using Clojure 1.2.

Both lines 1 and 2, shouldn't return meta, because 'meta' only takes
an object as an input argument.
And only if the object already has metadata will metadata will return.

=> (def o (with-meta ['mydatastructure] {:k []}))
=> (meta o)
{:k []}

Meikel Brandmeyer

unread,
Jan 9, 2011, 7:17:20 PM1/9/11
to clo...@googlegroups.com
Hi,

Am 10.01.2011 um 01:10 schrieb Tim Robinson:

> You must have something messed up:
>
> In line 1 (meta ^:k []) does not return {:tag :k} it returns nil and
> I am using Clojure 1.2.
>
> Both lines 1 and 2, shouldn't return meta, because 'meta' only takes
> an object as an input argument.
> And only if the object already has metadata will metadata will return.
>
> => (def o (with-meta ['mydatastructure] {:k []}))
> => (meta o)
> {:k []}

Are you sure?

Clojure 1.2.0
user=> (meta '^:k o)
{:tag :k}
user=> (meta ^:k [])
{:tag :k}
user=> (meta (with-meta 'o {:tag :k}))
{:tag :k}
user=> (meta ^:k 'o)
nil

The ^ stuff all works in the reader. So meta always sees only one argument with metadata already attached. The question is: Where is the meta data attached?

Sincerely
Meikel

Tim Robinson

unread,
Jan 9, 2011, 7:22:29 PM1/9/11
to Clojure
Am I sure?.. No, I'm never sure :)

But I am using 1.2 and when I run (meta ^:k []) or even (meta '^:k o)
I get nil.

Plus:

app=> (doc meta)
-------------------------
clojure.core/meta
([obj])
Returns the metadata of obj, returns nil if there is no metadata.
nil

I could be missing something?

Tim Robinson

unread,
Jan 9, 2011, 10:17:24 PM1/9/11
to Clojure
user=> (meta '^:k o)
{:tag :k}

How does this happen when :tag is not even in the expression?
If you launch a brand new repl and run it what happens?

On Jan 9, 5:17 pm, Meikel Brandmeyer <m...@kotka.de> wrote:

Meikel Brandmeyer

unread,
Jan 10, 2011, 1:40:38 AM1/10/11
to Clojure
Hi,

On 10 Jan., 04:17, Tim Robinson <tim.blacks...@gmail.com> wrote:

> How does this happen when :tag is not even in the expression?
> If you launch a brand new repl and run it what happens?

What I posted in the previous email is exactly a fresh repl session
and what happens there with 1.2. And in fact, that it is what I would
expect.

^String is a short-hand notation for ^{:tag String}. There was a
change planned for using ^ with keywords, namely that ^:foo is short-
hand for ^{:foo true}. But I don't know whether this change made it
into 1.3.

Sincerely
Meikel

mdzaebel

unread,
Jan 10, 2011, 2:48:35 AM1/10/11
to Clojure
Hi Meikel,

On 10 Jan., 01:09, Meikel Brandmeyer <m...@kotka.de> wrote:
> Because 'o expands to (quote o) and you actually hint this list. You might try (meta ' ^:k o).

Very interesting, this works! I did not know that syntax and none of
my books or the reader section of clojure.org mentioned it.

Thanks a lot, Marc

Tim Robinson

unread,
Jan 10, 2011, 8:36:04 AM1/10/11
to Clojure
Interesting.

My downloaded version of clojure 1.2.0 acts exactly as you describe.

However my basic lein project with only

(defproject prj "1.0.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.2.0"]]])

acts differently.

Well as I said, I can never sure about anything :)
Cheers
Tim

Meikel Brandmeyer

unread,
Jan 10, 2011, 8:44:40 AM1/10/11
to Clojure
Hi,

On 10 Jan., 14:36, Tim Robinson <tim.blacks...@gmail.com> wrote:

> Interesting.

Suspicious, I'd say.

> My downloaded version of clojure 1.2.0 acts exactly as you describe.
>
> However my basic lein project with only
>
>   (defproject prj "1.0.0-SNAPSHOT"
>     :dependencies [[org.clojure/clojure "1.2.0"]]])
>
> acts differently.

Sounds like some kind of bug with lein?

> Well as I said, I can never sure about anything :)

Indeed. :)

Sincerely
Meikel

Stefan Kamphausen

unread,
Jan 10, 2011, 8:47:32 AM1/10/11
to clo...@googlegroups.com
Hi,

I can't verify that a REPL created by lein behaves differently.  Did you perhaps update an old project.el without running lein deps?

In addition to that: your defproject has too many ]'s


Regards,
Stefan

Tim Robinson

unread,
Jan 20, 2011, 12:50:25 AM1/20/11
to Clojure
I upgraded lein from 1.3.1 to 1.4.2, which fixed the problem.
:)
Reply all
Reply to author
Forward
0 new messages