Fork me on GitHub
#clojure
<
2020-12-05
>
Fredrik Meyer12:12:17

Is there a way to make qualified keywords from a string? Iā€™m thinking of for example making ::a from the string "a". Is the only way to type out the whole namespace in (keyword "very.long.namespace.name" some-string) ?

borkdude12:12:39

@hrmeyer What about:

user=> (defn qkw [s] (keyword (str (ns-name *ns*)) s))
#'user/qkw
user=> (qkw "a")
:user/a

Fredrik Meyer12:12:51

I tried that, but when I called my function from core, I noticed that *ns* refers to the current namespace.

borkdude12:12:41

yes, *ns* refers to the current namespace. ::a also resolved in the current namespace.

borkdude13:12:03

could you give an example of what is the expectation when calling it with two separate namespace?

Fredrik Meyer13:12:03

I might be misunderstanding something šŸ™‚ I have a namespace/file myfile.clj where I define these keys, and do some operations on them. But I get a different result when I call this this function from core.clj.

borkdude13:12:02

when you call the function from core.clj it will use the value to which *ns* is bound at that moment, which is foo.core

borkdude13:12:33

what is unexpected about this, and what should be happening?

borkdude13:12:32

so the function is defined in namespace B but you are calling it from namespace A, but the namespace in the keyword should always be from B?

Fredrik Meyer13:12:52

Yes, that is what I want to achieve šŸ™‚

borkdude13:12:10

in B you could do the following:

(def current-ns-name (ns-name *ns*))
(defn qkw [s] (keyword (str current-ns-name) s))

Fredrik Meyer13:12:29

Thank you! That worked!

šŸ‘ 3
zendevil13:12:22

Is there a point cloud library or an open 3d alternative for clojure?

šŸ‘€ 3
william14:12:01

what's the best way of having an atom a update when atoms b or c update? Is there something like merge-atom? Or should I use add-watch?

borkdude15:12:44

maybe you could just merge the state of the three atoms into one?

william15:12:44

it's a good suggestion, but it would break encapsulation in my case; I'm now interested in the toy problem on how to merge them properly

mpenet15:12:26

or just refs, depends on the type of operation and level of safety you want

mpenet15:12:57

having all state in 1 atom is way easier šŸ™‚

william15:12:49

ok y'all make good points, so, let give some more context on the original problem: I'm using reagent, and I have a function that takes some data as a prop. Inside that function, I want to manipulate a local copy, and sync outside my program when the local state has some properties

william15:12:15

so, I would prefer not to put all the state in one atom because that mixes up local and global state

william15:12:48

but I don't know how to write that I want the local state to be either a result of the user manipulation, or the change coming from the global var, whichever came last

william15:12:57

so basically I'd like something like r/with-let [local (r/atom global)], but which continues to post update to the value

dominicm15:12:46

@meditans I'm pretty sure that's a react anti pattern.

borkdude15:12:19

@meditans it sounds like you might want to look at re-frame

dominicm15:12:40

I'd advise making it a fully controlled component.

borkdude15:12:00

in a re-frame subscription you could merge the component local and global state and then act on that

borkdude15:12:15

there's also the more low level reaction API for reagent and r/track, which could possibly offer a solution for this

borkdude15:12:02

yeah, you could also have a component which gets the merged state as props and merge that state in the parent

p-himik15:12:26

Also reagent.ratom/reaction seems relevant.

borkdude15:12:42

that's what I meant with reaction API yeah

borkdude15:12:54

I think I did something like this in re-find.web, lemme check

william15:12:07

thanks! give me a minute to parse all this info; you're right that it could be a react antipattern, and in fact part of this is learning what the correct patterns are (I usually write FRP, in which this problem doesn't exist)

Calum Boal15:12:25

Hey, so i'm trying to identify the value of a parameter being passed to a function. Im using emacs with cider, however, when i run the function via the repl i'm only getting back the return value of the call, not the printed value. Anyone know how i can access this?

(defn- sign-request
  ([client req]
   (println req)
   (client req)
  ))
For example, i'm trying to identify the value of req

borkdude15:12:57

@cgboal521 This value is printed in your cider REPL buffer

borkdude15:12:35

@cgboal521 You could also capture the value and then inspect it. E.g. like this: https://blog.michielborkent.nl/2017/05/25/inline-def-debugging/

Calum Boal15:12:01

Hmm, wasn't showing up but may be doing the wrong kind of repl execute in emacs. Cheers, will check that link

Calum Boal15:12:05

Cheers will take a look