This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-24
Channels
- # announcements (6)
- # babashka (25)
- # beginners (52)
- # cherry (8)
- # cider (9)
- # clj-kondo (9)
- # clojure (44)
- # clojure-australia (5)
- # clojure-dev (4)
- # clojure-europe (8)
- # clojure-nl (5)
- # clojure-norway (3)
- # clojure-spec (3)
- # clojure-uk (1)
- # clojurescript (16)
- # conjure (1)
- # core-async (8)
- # cursive (11)
- # fulcro (13)
- # honeysql (6)
- # hyperfiddle (13)
- # jackdaw (1)
- # jobs (9)
- # lsp (13)
- # meander (5)
- # missionary (2)
- # off-topic (11)
- # polylith (11)
- # re-frame (2)
- # reitit (11)
- # shadow-cljs (69)
- # squint (23)
- # tools-deps (30)
- # xtdb (3)
Howdie,
Why am I having trouble calling and referring clojure.set/union
from the repl
user=> (clojure.set/union #{1 2 3 4} #{3 4 5 6})
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:445).
user=> (refer 'clojure.set)
Execution error at user/eval5899 (REPL:1).
No namespace: clojure.set
use/refer are typically discouraged, but I think you're looking for use
rather than refer
Thank you that works but why does it fail when called by its fully qualified name?
(clojure.set/union #{1 2 3 4} #{3 4 5 6})
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:445)
I'm not sure. It works for me when I use the fully qualified name. Does it fail if you start a new repl from scratch and just use
?
seanc@Sean-win-11-laptop:~/clojure$ clj
Clojure 1.11.1
user=> (clojure.set/union #{1 2 3} #{2 3 4})
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:445).
clojure.set
user=> (require 'clojure.set)
nil
user=> (clojure.set/union #{1 2 3} #{2 3 4})
#{1 4 3 2}
user=>
You should assume everything except clojure.core
needs to be require
'd before use even if a given REPL experience happens to auto-load something...
Hi, I'm running into an issue when writing a macro and I can't figure out how to make it work like I'd want. My goal is to write a macro that spits out a map that looks like:
{'get goog.object/get
'set goog.object/set}
I have the following code, however I can't properly quote the keys so that they're not evaluating (and resulting in an undeclared var issue).
(defmacro my-macro []
(let [ns-keys
['get 'set]
ns-values
(mapv #(symbol "goog.object" (str %)) ns-keys)]
(zipmap ns-keys ns-values)))
Any ideas? Thanks in advance!ns-keys
will be larger and I'd like to ensure that it matches the function naming in goog.object
(trying to dry this code up a bit - https://github.com/dehli/nbb/blob/dbb2fde79a0624683fef35178e44963767785edd/src/nbb/core.cljs#L464-L499)
It might be possible to do it w/o a macro. I'm not sure how to dynamically reference the gobj/*
functions at runtime though.
Yeah, the non-macro code I shared does work. I was trying to see if I could use a macro to prevent accidentally doing something like {'foo goog.object/bar}
since you always want the symbol on the left to match to the function name in goog.object
. Seems like it might be best to just not use a macro to keep it simpler though
Right after saying that I was able to get the macro working 🙂 Needed to do:
(zipmap (map (fn [k] `'~k) ns-keys)
ns-values)
I saw that there's a new Clojure implementation (with types) for the LLVM. Just wondering, is it wrong to think that because Clojure has reached many eco systems, in the future there will be more demand for it as it can run in a lot of places? Or is this wrong thinking?
demand creates supply, not vice versa. For example, Clojure CLR has been there for a long time, but still, I can’t say that there is a huge demand for developers with both .Net and Clojure experience. For sure, I’m in my own information bubble and there is a high chance I don’t see the big picture.
Hi all,
I have a silly requirement.
I have a list/vector ["a" "b" "c" "d"]
I want to use the strings in this list/vector to execute (def a (literal-number 'a))
as shown for the first element. For the second element it'll be (def b (literal-number 'b))
. How do I go about it?
literal-number is a sicmutils library function
def
if a special form. you will need a macro for that. do you know the list at compile time or something produces it in runtime?
I will need both for compile time & runtime... atleast I think I do... depending on the answer I might decide one way or other...
(defmacro defify [bindings]
`(do
~@(map (fn [binding]
`(def ~(symbol binding) (literal-number '~(symbol binding))))
bindings)))
(macroexpand '(defify ["a" "b" "c" "d"]))
;; => (do
;; (def a (literal-number 'a))
;; (def b (literal-number 'b))
;; (def c (literal-number 'c))
;; (def d (literal-number 'd)))
but that macro won’t work if bindings are unknown at compile time.
many thanx, I'll try this and get back if I still have issues... but already looks good! Thanks again!
(doseq [x ["a" "b" "c" "d"]] (intern *ns* (symbol x) (literal-number (symbol x)))
would that work ?clojure has a template macro that is for stuff like this https://clojuredocs.org/clojure.template/do-template
thanks for all the help guys!! Appreciate it!
@U04V4KLKC I tried your solution but I am getting an error as shown below. Any suggestions? I can confirm that create-body function works independently.
Is it possible that these solutions are only applicable to clojure and NOT clojurescript?
@U02F0C62TC1 your solution also didn't work for me.
macroses exists only in clojure. you can use the result of a macro in clojurescript context thou. https://www.clojurescript.org/about/differences#_macros
intern also wouldn’t work with cljs because it is not implemented - https://www.clojurescript.org/about/differences#_vars_and_the_global_environment
ok thanks for that!! I'll investigate this further
Good day,
How common is it to use data structures other than :keywords
as map keys?
If it is relatively common in which kind of situations are they used?
keywords are definitely the most common key type, but it's not uncommon to use other data types. • String keys are common when working with data from outside of clojure. • Numbers and uuids are common when used as ids • It's also not uncommon to use vectors/sets/maps as keys. Use cases vary, but I think https://clojuredocs.org/clojure.set/index#example-542692d0c026201cdc326ef1 is an illustrative example.
There is a (evil) global in our system, is there a way to detect when it changes (stack trace preferably)? Most usages do a (binding) to it, fwiw.
Hi folks, how to debug request coming from http in clojure ? is like var_dump in php or console.log in JS
interesting, println is just a prn without readability (of course, that's a good thing here, so you can see 'invisible' characters as their escape seqs):
(defn println
"Same as print followed by (newline)"
{:added "1.0"
:static true}
[& more]
(binding [*print-readably* nil]
(apply prn more)))