[CLJ-270] defn-created fns inherit old metadata from the Var they are assigned to Created: 13/Feb/10 Updated: 24/Aug/10 |
|
| Status: | Open |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | Approved Backlog |
| Type: | Defect | ||
| Reporter: | Anonymous | Assignee: | Rich Hickey |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
user> (def #^{:foo "bar"} x 5)
I expect (meta #'x) to evaluate to the value of the final (meta x) in the above.
Current master (commit 61202d2ff6925002400a9843e8fbd080f3bef3a5).
Prompted by discussion at
I think this is due to DefExpr's eval method binding the Var to init.eval() first and attaching the supplied metadata to the Var later – see Compiler.java lines 341-352. (Note the Var is always already in place when init.eval() is called, regardless of whether it existed prior to the evaluation of the def / defn.) Thus the init expression supplied by defn sees the old (and wrong) metadata on the Var. |
| Comments |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
Converted from http://www.assembla.com/spaces/clojure/tickets/270 |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
stu said: [file:dwK4yssayr37y_eJe5d-aX] |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
stu said: The problem happens with defn, but not with def+fn, so I think the original diagnosis is incorrect. Another stab at diagnosis: The defn macro copies metadata from a var onto its new value, so if you defn a var that already exists, the old var metadata becomes metadata on the new value. I don't know why this would be the right thing to do, and if you eliminate this behavior (see patch) all the Clojure and Contrib tests still pass. If this is correct, please assign back to me and I will write tests. If this is wrong, please tell me what's going on here so I know how to write the tests. |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
cgrand said: Child association with ticket #363 was added |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
cgrand said: I think the original diagnosis is correct. Note that the behavior differ when def iscompiled: user=> (def #^{:foo "bar"} x 5) See also http://groups.google.com/group/clojure/browse_thread/thread/6afd81896ca368b2# |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
cgrand said: [file:arrhbiAI4r35lQeJe5cbLr] |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
cgrand said: My patch aligns DefExpr.eval with DefExpr.emit (first set meta then eval the init value). |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
cgrand said: Forget it, my current patch is broken. |
| Comment by Assembla Importer [ 24/Aug/10 6:23 AM ] |
|
cgrand said: My current patch is broken because of #352, what is the rational for #352? |
[CLJ-273] def with a function value returns meta {:macro false}, but def itself doesn't have meta Created: 23/Feb/10 Updated: 24/Aug/10 |
|
| Status: | Open |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | Backlog |
| Type: | Defect | ||
| Reporter: | Anonymous | Assignee: | Rich Hickey |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
On the master (1.2) branch, if you create a def with an initial function value, {:macro false} is added to the metadata of the return value for def. However, if you look again at the metadata on the var itself, the {:macro false} is not present! This breaks the use of contrib's defalias when aliasing macros, because the new alias is marked as {:macro false}. The code below demonstrates the issue, which was introduced in http://github.com/richhickey/clojure/commit/430dd4fa711d0008137d7a82d4b4cd27b6e2d6d1, "metadata for fns." ;; all running on 1.2, DIFF noted in comments
(defmacro foo [])
-> #'user/foo
(meta (def bar (.getRoot #'foo)))
-> {:macro false, :ns #<Namespace user>, :name bar, :file "NO_SOURCE_PATH", :line 83}
;; DIFF: where did that :macro false come from??
(def bar (.getRoot #'foo))
-> #'user/bar
(meta #'bar)
-> {:ns #<Namespace user>, :name bar, :file "NO_SOURCE_PATH", :line 84}
;; LIKE 1.1, but really weird: now the :macro false is gone again!
|
| Comments |
| Comment by Assembla Importer [ 24/Aug/10 9:32 AM ] |
|
Converted from http://www.assembla.com/spaces/clojure/tickets/273 |
[CLJ-2] Scopes Created: 15/Jun/09 Updated: 08/Mar/12 |
|
| Status: | Open |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | Approved Backlog |
| Type: | Enhancement | Priority: | Major |
| Reporter: | Assembla Importer | Assignee: | Rich Hickey |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Attachments: |
|
| Description |
|
Add the scope system for dealing with resource lifetime management |
| Comments |
| Comment by Assembla Importer [ 24/Aug/10 11:43 AM ] |
|
Converted from http://www.assembla.com/spaces/clojure/tickets/2 |
| Comment by Assembla Importer [ 24/Aug/10 11:43 AM ] |
|
richhickey said: Updating tickets (#8, #42, #113, #2, #20, #94, #96, #104, #119, #124, #127, #149, #162) |
| Comment by Stuart Halloway [ 12/Jul/11 8:26 AM ] |
|
Patch demonstrates idea, not ready for prime time. |
| Comment by Tassilo Horn [ 23/Dec/11 7:37 AM ] |
|
I think the decision of having to specify either a Closeable resource or a close function for an existing non-Closeable resource in with-open is quite awkward, because they have completely different meaning. (let [foo (open-my-custom-resource "foo.bar")]
(with-open [r (reader "foo.txt")
foo #(.terminate foo)]
(do-stuff r foo)))
I think a CloseableResource protocol that can be extended to custom types as implemented in the patch to CLJ-308 is somewhat easier to use. Extend it once, and then you can use open-my-custom-resource in with-open just like reader/writer and friends... That said, Scopes can still be useful, but I'd vote for handling the "how should that resource be closed" question by a protocol. Then the with-open helper can simply add (swap! *scope* conj (fn [] (clojure.core.protocols/close ~(bindings 0)))) and cleanup-scope only needs to apply each fn without having to distinguish Closeables from fns. |
[CLJ-84] GC Issue 81: compile gen-class fail when class returns self Created: 17/Jun/09 Updated: 10/Dec/10 |
|
| Status: | In Progress |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | Approved Backlog |
| Fix Version/s: | Approved Backlog |
| Type: | Defect | Priority: | Minor |
| Reporter: | Assembla Importer | Assignee: | Rich Hickey |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Approval: | Incomplete |
| Waiting On: | Chouser |
| Description |
Reported by davidhaub, Feb 14, 2009 When attempting to compile the following program, clojure fails with a ClassNotFoundException. It occurs because one of the methods returns the same class that is being generated. If the returnMe method below is changed to return an Object, the compile succeeds. Beware when testing! If the classpath contains a class file (say from a prior successful build when the returnMe method was changed to return an object), the compile will succeed. Always clear out the clojure.compile.path prior to compiling. ;badgenclass.clj (ns badgenclass (:gen-class :state state :methods [[returnMe [] badgenclass]] :init init)) (defn -init [] [[] nil]) (defn -returnMe [this] this) #!/bin/sh rm -rf classes mkdir classes java -cp lib/clojure.jar:classes:. -Dclojure.compile.path=classes \ clojure.lang.Compile badgenclass Comment 1 by chouser, Mar 07, 2009 Attached is a patch that accepts strings or symbols for parameter and return class names, and generates the appropriate bytecode without calling Class/forName. It fixes this issue, but because 'ns' doesn't resolve :gen-class's arguments, class names aren't checked as early anymore. :gen-class-created classes with invalid parameter or return types can even be instantiated, and no error will be reported until the broken method is called. One possible alternative would be to call Class/forName on any symbols given, but allow strings to use the method given by this patch. To return your own type, you'd need a method defined like: [returnMe [] "badgenclass"] Any thoughts? |
| Comments |
| Comment by Assembla Importer [ 28/Sep/10 5:09 PM ] |
|
Converted from http://www.assembla.com/spaces/clojure/tickets/84 |
| Comment by Assembla Importer [ 28/Sep/10 5:09 PM ] |
|
oranenj said: [file:cWS6Aww30r3RbzeJe5afGb]: on comment 1 |
| Comment by Assembla Importer [ 28/Sep/10 5:09 PM ] |
|
richhickey said: Updating tickets (#8, #19, #30, #31, #126, #17, #42, #47, #50, #61, #64, #69, #71, #77, #79, #84, #87, #89, #96, #99, #103, #107, #112, #113, #114, #115, #118, #119, #121, #122, #124) |
| Comment by Stuart Halloway [ 30/Oct/10 11:58 AM ] |
|
The approach take in the initial patch (delaying resolution of symbols into classes) is fine: gen-class makes no promise about when this happens, and the dynamic approach feels more consistent with Clojure. I think the proposed (but not implemented) use of string/symbol to control when class names are resolved is a bad idea: magical and not implied by the types. Needed:
|
| Comment by Chouser [ 30/Oct/10 9:29 PM ] |
|
Wow, 18-month-old patch, back to haunt me for Halloway'een So what does it mean that the assignee is Rich, but it's waiting on me? |
| Comment by Stuart Halloway [ 01/Nov/10 9:17 AM ] |
|
I am using Approval = Incomplete plus Waiting On = Someone to let submitters know that there is feedback waiting, and that they can move the ticket forward by acting on it. The distinction is opportunity to contribute (something has been provided to let you move forward) vs. expectation of contribution. |