Clojure

clojure.repl/source does not work with deftype

Details

  • Type: Enhancement Enhancement
  • Status: In Progress In Progress
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

clojure.repl/source does not work on a deftype

user> (deftype Foo [a b])
user.Foo
user> (source Foo)
Source not found

Cause: deftype creates a class but not a var so no file/line info is attached anywhere.

Approach:

Patch:

Screened by:

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/304
Hide
Assembla Importer added a comment -

chouser@n01se.net said: That's a great question. get-source just needs a file name and line number.

If IMeta were a protocol, it could be extended to Class. That implementation could look for a "well-known" static field, perhaps? __clojure_meta or something? Then deftype would just have to populate that field, and get-source would be all set.

Does that plan have any merit? Is there a better place to store a file name and line number?

Show
Assembla Importer added a comment - chouser@n01se.net said: That's a great question. get-source just needs a file name and line number. If IMeta were a protocol, it could be extended to Class. That implementation could look for a "well-known" static field, perhaps? __clojure_meta or something? Then deftype would just have to populate that field, and get-source would be all set. Does that plan have any merit? Is there a better place to store a file name and line number?
Hide
Assembla Importer added a comment -

stu said: Seems like a reasonable idea, but this is going to get back-burnered for now, unless there is a dire use case we have missed.

Show
Assembla Importer added a comment - stu said: Seems like a reasonable idea, but this is going to get back-burnered for now, unless there is a dire use case we have missed.
Stuart Halloway made changes -
Field Original Value New Value
Assignee Stuart Halloway [ stu ]
Reporter Assembla Importer [ importer ]
Priority Minor [ 4 ]
Alex Miller made changes -
Fix Version/s Backlog [ 10035 ]
Alex Miller made changes -
Labels repl
Hide
Gary Trakhman added a comment -

I could use this for cider's file/line jump-around mechanism as well.

With records, I can work around it by deriving and finding the corresponding constructor var, but it's a bit nasty.

Show
Gary Trakhman added a comment - I could use this for cider's file/line jump-around mechanism as well. With records, I can work around it by deriving and finding the corresponding constructor var, but it's a bit nasty.
Hide
Bozhidar Batsov added a comment -

I'd also love to see this fixed.

Show
Bozhidar Batsov added a comment - I'd also love to see this fixed.
Hide
Andy Fingerhut added a comment -

Bozhidar, voting on a ticket (clicking the Vote link in the right of the page when viewing the ticket) can help push it upwards on listings of tickets by # of votes.

Show
Andy Fingerhut added a comment - Bozhidar, voting on a ticket (clicking the Vote link in the right of the page when viewing the ticket) can help push it upwards on listings of tickets by # of votes.
Alex Miller made changes -
Description Now that deftype creates a class (but not a var), you can't use c.c.repl-utils/get-source on a deftype. Is there something we can do on the Clojure side to help this work again? clojure.repl/source does not work on a deftype

{code}
user> (deftype Foo [a b])
user.Foo
user> (source Foo)
Source not found
{code}

*Cause:* deftype creates a class but not a var so no file/line info is attached anywhere.

*Approach:*

*Patch:*

*Screened by:*
Alex Miller made changes -
Summary contrib get-source no longer works with deftype clojure.repl/source does not work with deftype

People

Vote (4)
Watch (2)

Dates

  • Created:
    Updated: