This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # arachne (80)
- # beginners (76)
- # boot (16)
- # cider (66)
- # cljs-dev (62)
- # cljsjs (1)
- # clojure (106)
- # clojure-dev (5)
- # clojure-greece (2)
- # clojure-italy (9)
- # clojure-russia (1)
- # clojure-spec (61)
- # clojure-uk (130)
- # clojurescript (21)
- # core-async (9)
- # cursive (3)
- # datomic (37)
- # events (41)
- # figwheel (31)
- # fulcro (27)
- # hoplon (1)
- # jobs (2)
- # lumo (11)
- # off-topic (155)
- # re-frame (71)
- # reagent (27)
- # ring-swagger (3)
- # shadow-cljs (132)
- # spacemacs (5)
- # specter (1)
- # sql (37)
- # test-check (10)
- # uncomplicate (5)
- # unrepl (2)
- # yada (3)
hi all, how do I look up a functions spec at run-time?
s/get-spec doesn’t seem to to work?
ah thankyou. just spotted it said that in the docs… an I get the fully qualified symbol for a function from that function?
user=> (defn foo  nil) #'user/foo user=> (s/fdef foo :args (s/cat) :ret nil?) user/foo user=> (s/get-spec `foo) #object[clojure.spec.alpha$fspec_impl$reify__2451 0x8c11eee "[email protected]"] user=> (s/form (:args (s/get-spec `foo))) (clojure.spec.alpha/cat)
I used back-tick there - syntax quote will resolve symbols so that’s an easy way, but I also could have done
note that what you get back is a function spec instance, but that spec supports keyword lookup of
or you can use s/form on it directly
user=> (s/form (s/get-spec 'user/foo)) (clojure.spec.alpha/fspec :args (clojure.spec.alpha/cat) :ret clojure.core/nil? :fn nil)
Rich mentioned in a podcast (I think) that there was some sugar forthcoming which allowed a map to specify/lift the namespace for all the keys in the map (if they all had the same namespace) to the map level such that each individual key in the map could be printed / declared as
un namespaced for cleanliness? Is there news on this, or a preview of what it might look like? I'm working on something similar and an example would be great to see. This was mentioned in the context of using spec, so that's why I'm putting it here vs. another channel.
So this foo walks into a bar. Bartender says, "Hey buddy, what kind of example you trying to set?"
...and it's been around for awhile now... I'll try not to feel dumb. https://groups.google.com/forum/#!topic/clojure-dev/8tHLCm8LpyU and https://dev.clojure.org/jira/browse/CLJ-1910
ok, so if I have a function `f’ thats been passed in to another function and I don’t know it’s fully qualified name is there a way to find it?
ah I do mean var I think - how do I look up a fully qualified name/spec for a function referenced by a variable?
I won’t have the fully qualified symbol when I come to do it - does this mean it’s a no go?
ah ok - this is a shame - The REPL seems to be able to look up the fully-qualified symbol for function
@gihadi - it is a bit convoluted - I’m experimenting with agent based computing - and turning functions in to agents using only the information in there type signatures
not what I want unfortuantely - I’m doing some crazy stuff with the spec - I unpack info about each argument and tehn search a collection for it.
the only thing I can’t do is look up wether or a not a function has had a spec written for it (when I don’t have its fully wualified name)
If you don’t have the qualifier, then it’s ambiguous what you’re referring to
That said, the registry is just a map with either qualified symbols or qualified keywords as keys - you could search for it
A function instance doesn’t hold an explicit name for its source var
bb-simple.core> (defn function [a] a) #'bb-simple.core/function bb-simple.core> (def z function) #'bb-simple.core/z bb-simple.core> z #function[bb-simple.core/function] bb-simple.core>
that’s not the default printer - you must be running with something addition in your repl
the function class name is a munged version of the original function name (assuming it was from a var, can be from other places too)
what that’s doing is using
demunge to get from the class name to an approximation of the original var
but that is not relibale and can only be done if the function was compiled from a
you can demunge to recover the class name, but the munge operation is not a true function (mathematically) in that multiple inputs map to the same class name
oh ok this all sounds a bit yuck. Think I’ll steer clear for now. It’s a lot of extra typing for me but such islife