Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unmunge" deftype field names #33

Closed
tsdh opened this issue Sep 2, 2015 · 5 comments
Closed

"Unmunge" deftype field names #33

tsdh opened this issue Sep 2, 2015 · 5 comments

Comments

@tsdh
Copy link

tsdh commented Sep 2, 2015

When you have a Clojure type like

(deftype Foo [x-y] ...)

then (.x completes to (.x_y instead of (.x-y. That's because for a deftype a class is generated, and the field names of the class are the "munged" names of the deftype's fields, i.e., hypens are replaced with underscores.

In Clojure on the JVM, (.x_y foo) actually works but it relies on this very implementation detail and is not portable to the CLR or ClojureScript. Thus, it's better to use (.x-y foo) as this is the documented way to access fields of a deftype.

So it would be nice if CIDER could directly suggest the correct version when completing. The fact that can be exploited is that all classes (and only those) generated for a deftype implement clojure.lang.IType (see https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L396). Therefore, I suggest to "unmunge" field names of classes implementing IType.

@alexander-yakushev
Copy link
Owner

So everything that comes from deftype implements IType. Can we be reasonably sure that noone implements IType on their own?

@tsdh
Copy link
Author

tsdh commented Sep 2, 2015

Yes, we may assume that. IType is just a marker interface for exactly this purpose.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 8, 2016

Yeah, that'd be nice.

@alexander-yakushev
Copy link
Owner

Didn't even take 8 years 🎉

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 8, 2023

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants