Fork me on GitHub
#clojure-dev
<
2024-03-08
>
Noah Bogart14:03:30

I see in https://ask.clojure.org/index.php/11514/functions-with-metadata-can-not-take-more-than-20-arguments that it's "undefined behavior" that functions carry metadata. Given that this behavior has been in Clojure since https://github.com/clojure/clojure/commit/2b16fee78a0517bc83dd5735ab01d3d5813b1f72, is there any reason to expect that this behavior will change?

👀 1
Alex Miller (Clojure team)14:03:58

I think I would say what I said in my response there

Noah Bogart14:03:27

i don't think that answers my question. the original question was about clojurescript's implementation of metadata on functions, and you answered more broadly about clojures in general that it's undefined/unspecified. then you said that some clojures choose to implement it in various ways, but that it's probably not going to be consistent across impls. i'm asking specifically about JVM clojure. can we rely on metadata being supported on functions?

Noah Bogart14:03:07

if we can't, then clj-kondo/eastwood/splint can warn against it and we can avoid issues in the future if/when it changes

Alex Miller (Clojure team)14:03:20

well, just repeating that the docs don't define functions as a thing that can have metadata, and not all function implementations support metadata

Alex Miller (Clojure team)14:03:04

there are some cases now where they can and where it is used

seancorfield16:03:18

Because fn objects implement clojure.lang.IMeta

Noah Bogart16:03:29

right, i understand that people use it. i didn't realize until i read the Ask that it's not technically "defined" behavior, it's just JVM implementation behavior, and the wording made me wonder if it was something that might change in the future (and thus should be avoided)

Alex Miller (Clojure team)16:03:08

this is undefined behavior, I don't know how else to say it

Noah Bogart16:03:22

with C, undefined behavior means "do not rely on this at all, if you trigger UB you cannot trust the results even when they're accidentally correct, we're free to change the behavior at any time". is that how you're using it?

Alex Miller (Clojure team)17:03:43

undefined means what it does and whether it works and whether that will change is not defined

seancorfield21:03:21

@U064X3EF3 So, just to clarify, are you saying that fn objects implementing clojure.lang.IMeta is "undefined behavior" because it is just an implementation detail and might change?

Alex Miller (Clojure team)21:03:40

I'm saying nothing anywhere says you can do that

seancorfield21:03:11

Fair enough. So this is one of those things like :1 that is undefined but if y'all ever change it, you may well break people's code (and therefore might consider not changing it) 🙂

Alex Miller (Clojure team)21:03:39

it is an undefined but observable implementation detail, ymmv

seancorfield21:03:34

FYI: The release notes for Clojure 1.3 say "Functions only get metadata support code when metadata explicitly supplied" (under performance enhancements) and then this ticket in 1.6 ensured metadata on functions printed properly: https://clojure.atlassian.net/browse/CLJ-908 -- which speaks to some deliberate choices to support metadata on functions, even if it isn't documented.

Alex Miller (Clojure team)21:03:55

That doesn't sound like feature words to me, more internal performance changes. I can't find any docstring or reference page that documents metadata on fns specifically

slipset09:03:28

Enter Hyrum

😆 1
🤝 1