Inconsistent behavior in 1.2.0-master w.r.t. previous versions

3 views
Skip to first unread message

Zach Tellman

unread,
Jan 25, 2010, 10:52:34 PM1/25/10
to Clojure
At the REPL, in 1.2.0-master

> (meta (second '(a #^b c)))
nil

In 1.1.0-new (and I believe all previous versions)

> (meta (second '(a #^b c)))
{:tag b}

Is this intentional, or a bug? Is the new type hint syntax being
introduced in 1.2?

wlr

unread,
Jan 25, 2010, 11:01:21 PM1/25/10
to Clojure
Works for me.

user> [*clojure-version* (meta (second '(a #^b c)))]
[{:interim true, :major 1, :minor 2, :incremental 0, :qualifier
"master"} {:tag b}]

Zach Tellman

unread,
Jan 25, 2010, 11:19:48 PM1/25/10
to Clojure
I've double-checked I have the latest from github, cleaned and
recompiled, and I'm still getting the same results.

user=> [*clojure-version* (meta (second '(a #^b c)))]


[{:interim true, :major 1, :minor 2, :incremental 0, :qualifier

"master"} nil]

Does anyone have an idea what's going on here?

Chouser

unread,
Jan 25, 2010, 11:22:59 PM1/25/10
to clo...@googlegroups.com

I think it's a bug, perhaps related to quoting behavior.
Everything seems to work okay before this commit:

commit 430dd4fa711d0008137d7a82d4b4cd27b6e2d6d1
Author: Rich Hickey <richh...@gmail.com>
Date: Tue Jan 19 14:25:26 2010 -0500

metadata for fns

Afterward:

(meta '#^a b)
;=> nil

(meta '#^{:foo :bar} [5 10])
;=> nil

(meta (first '[#^{:foo :bar} {}]))
;=> nil

This, however, works both before and after:

(meta #^{:foo :bar} [5 10])
;=> {:foo :bar}

Also, the problem appears to be related to 'eval' not 'read':

(second (read-string "(quote #^a b))"))
;=> b

(meta (second (read-string "(quote #^a b))")))
;=> {:tag a}

(eval (read-string "(quote #^a b))"))
;=> b

(meta (eval (read-string "(quote #^a b))")))
;=> nil

--Chouser

AlexK

unread,
Jan 27, 2010, 2:56:21 PM1/27/10
to Clojure
user> (set! *print-meta* true)
true
user> '#^a symbol
symbol
user> '#^a (list)
#^{:line 1, :tag a} (list)
user> '#^a [vector]
[vector]
user> '#^a {:a :map}
{:a :map}
user> '#^a #{:a :set}
#^a #{:a :set}
user> '#^{:meta :map} symbol
symbol
user> '#^{:meta :map} (list)
#^{:line 1, :meta :map} (list)
user> '#^{:meta :map} [vector]
[vector]
user> '#^{:meta :map} {a map}
{a map}
user> '#^{:meta :map} #{a set}
#^{:meta :map} #{a set}


PersistentLists and PersistentHashSets work, but other things fail.

I think i know the reason:
Compiler.emitValue() (Compiler.java:3741-3879) is for initializing
constant expressions, but it only adds metadata, if the value is an
instance of class Obj (Compiler.java:3870). But since commit
430dd4fa711d0008137d7a82d4b4cd27b6e2d6d1 (metadata for fns) AFn no
longer extends Obj, and thus Maps, Symbols and Vectors aren't
instances of Obj anymore.
PersistentList extends ASeq which extends Obj directly, so those work.
No idea why PersistentSet works however.

AlexK


Chouser

unread,
Jan 27, 2010, 3:29:28 PM1/27/10
to clo...@googlegroups.com
On Wed, Jan 27, 2010 at 2:56 PM, AlexK
<alexander.k...@informatik.haw-hamburg.de> wrote:
>
> PersistentLists and PersistentHashSets work, but other things fail.
>
> I think i know the reason:
> Compiler.emitValue() (Compiler.java:3741-3879) is for initializing
> constant expressions, but it only adds metadata, if the value is an
> instance of class Obj (Compiler.java:3870). But since commit
> 430dd4fa711d0008137d7a82d4b4cd27b6e2d6d1 (metadata for fns) AFn no
> longer extends Obj, and thus Maps, Symbols and Vectors aren't
> instances of Obj anymore.
> PersistentList extends ASeq which extends Obj directly, so those work.
> No idea why PersistentSet works however.

I think you nailed it. Changing Obj to IObj on lines 3870 and
3873 seems to fix it.

--Chouser
http://joyofclojure.com/

Rich Hickey

unread,
Jan 27, 2010, 4:30:47 PM1/27/10
to clo...@googlegroups.com


Fixed - thanks all.

Rich

Reply all
Reply to author
Forward
0 new messages