This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-08
Channels
- # announcements (11)
- # babashka (13)
- # beginners (11)
- # biff (2)
- # calva (17)
- # cider (19)
- # clojure (60)
- # clojure-berlin (1)
- # clojure-dev (20)
- # clojure-europe (48)
- # clojure-nl (1)
- # clojure-norway (98)
- # clojure-spec (7)
- # clojure-uk (5)
- # core-typed (32)
- # cursive (13)
- # datomic (12)
- # dev-tooling (5)
- # emacs (7)
- # figwheel-main (2)
- # graalvm (4)
- # hyperfiddle (4)
- # introduce-yourself (1)
- # malli (14)
- # missionary (32)
- # off-topic (7)
- # overtone (4)
- # pedestal (10)
- # proletarian (4)
- # re-frame (8)
- # releases (11)
- # tools-build (1)
- # tools-deps (4)
- # xtdb (38)
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?
I think I would say what I said in my response there
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?
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
well, just repeating that the docs don't define functions as a thing that can have metadata, and not all function implementations support metadata
there are some cases now where they can and where it is used
next.jdbc
relies on fn
forms carrying metadata (in JVM Clojure): https://github.com/seancorfield/next-jdbc/blob/develop/src/next/jdbc/connection.clj#L326-L330
Because fn
objects implement clojure.lang.IMeta
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)
this is undefined behavior, I don't know how else to say it
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?
undefined means what it does and whether it works and whether that will change is not defined
@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?
I'm saying nothing anywhere says you can do that
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) 🙂
it is an undefined but observable implementation detail, ymmv
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.
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