This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-27
Channels
- # announcements (3)
- # babashka (16)
- # beginners (177)
- # calva (102)
- # cider (2)
- # clj-kondo (12)
- # clojars (10)
- # clojure (91)
- # clojure-argentina (3)
- # clojure-australia (5)
- # clojure-europe (16)
- # clojure-nl (1)
- # clojure-uk (10)
- # clojurescript (73)
- # community-development (8)
- # cursive (9)
- # depstar (7)
- # fulcro (5)
- # helix (1)
- # introduce-yourself (1)
- # jobs-discuss (18)
- # lsp (32)
- # luminus (1)
- # malli (2)
- # music (4)
- # off-topic (20)
- # pathom (19)
- # polylith (15)
- # re-frame (4)
- # reagent (6)
- # ring (13)
- # sci (36)
- # shadow-cljs (7)
- # spacemacs (4)
- # sql (3)
- # tools-deps (112)
- # vim (21)
I think one could install a patched version of clojure.core/defn
that looks at some config file where you can state which vars you actually don't want to directly link
and this could be used for SCI-based graalvm binaries where the compiled vars need a bit of patching
Couldn't you alter-meta for the defn to add ^:redef to it before compilation? Assuming you didn't own the code
@didibus No, that you cannot do that, since the direct linking can occur in the same namespace
Oh... I see what you mean, like you'd need to alter the meta right after the defn if other things later in the namespace were calling it
If you declare the def first, does calling defn overwrite the meta for it or just merges?
Like say you'd do:
(in-ns ns-i-dont-control)
(declare ^:redef foo)
(ns my-ns
(:require [ns-i-dont-control :as dont]))
Where foo is the defn you don't want direct linkedSeems with self-hosted ClojureScript, the meta gets replaced, not merged... Just trying using my Android self-hosted repl. Not sure for real Clojure
Hmm...
user=> (in-ns 'cheshire.core)
#object[clojure.lang.Namespace 0x55ea2d70 "cheshire.core"]
cheshire.core=> (declare ^:redef generate-string)
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: declare in this context
cheshire.core=> (clojure.core/declare ^:redef generate-string)
#'cheshire.core/generate-string
cheshire.core=> (ns user
)
nil
user=> (require 'cheshire.core)
nil
user=> (meta #'cheshire.core/generate-string)
{:arglists ([obj] [obj opt-map]), :doc "Returns a JSON-encoding String for the given Clojure object. Takes an\n optional date format string that Date objects will be encoded with.\n\n The default date format (in UTC) is: yyyy-MM-dd'T'HH:mm:ss'Z'", :line 49, :column 1, :file "cheshire/core.clj", :name generate-string, :ns #object[clojure.lang.Namespace 0x55ea2d70 "cheshire.core"]}
user=> (:redef (meta #'cheshire.core/generate-string))
nil
I think what happens for dynamic is that the meta tells def
to create a Var configured to be dynamic. And when you call def
for it again, even if you don't specify ^:dynamic, it will just alter-var-root so the Var will be the same which is still configured as dynamic... Maybe?