clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Fredrik Meyer 2020-12-05T12:53:17.058900Z

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) ?

borkdude 2020-12-05T12:56:39.059200Z

@hrmeyer What about:

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

Fredrik Meyer 2020-12-05T12:58:51.059500Z

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

borkdude 2020-12-05T12:59:41.059700Z

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

borkdude 2020-12-05T13:01:03.060300Z

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

Fredrik Meyer 2020-12-05T13:10:03.060500Z

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.

borkdude 2020-12-05T13:11:02.060700Z

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

borkdude 2020-12-05T13:11:33.061Z

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

borkdude 2020-12-05T13:12:32.061200Z

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 Meyer 2020-12-05T13:12:52.061400Z

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

borkdude 2020-12-05T13:13:10.061600Z

in B you could do the following:

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

Fredrik Meyer 2020-12-05T13:16:29.061800Z

Thank you! That worked!

šŸ‘ 1
zendevil 2020-12-05T13:46:22.062500Z

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

šŸ‘€ 1
william 2020-12-05T14:45:01.063800Z

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?

borkdude 2020-12-05T15:01:44.064100Z

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

william 2020-12-05T15:03:44.065100Z

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

dominicm 2020-12-05T15:05:50.065600Z

@meditans https://github.com/martinklepsch/derivatives sounds like what you're after?

mpenet 2020-12-05T15:09:26.066300Z

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

mpenet 2020-12-05T15:09:57.066700Z

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

william 2020-12-05T15:11:49.068500Z

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

william 2020-12-05T15:12:15.069100Z

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

william 2020-12-05T15:12:48.070Z

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

william 2020-12-05T15:15:57.070900Z

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

dominicm 2020-12-05T15:19:46.071700Z

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

borkdude 2020-12-05T15:20:19.072500Z

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

dominicm 2020-12-05T15:20:40.072900Z

I'd advise making it a fully controlled component.

borkdude 2020-12-05T15:22:00.074Z

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

borkdude 2020-12-05T15:23:15.074900Z

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

borkdude 2020-12-05T15:25:02.075500Z

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

p-himik 2020-12-05T15:25:26.075800Z

Also reagent.ratom/reaction seems relevant.

borkdude 2020-12-05T15:25:42.076Z

that's what I meant with reaction API yeah

borkdude 2020-12-05T15:25:54.076300Z

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

borkdude 2020-12-05T15:27:21.076900Z

(this is the website hosting it: https://borkdude.github.io/re-find.web)

william 2020-12-05T15:30:07.079600Z

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 Boal 2020-12-05T15:30:25.079900Z

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

borkdude 2020-12-05T15:30:57.080200Z

@cgboal521 This value is printed in your cider REPL buffer

borkdude 2020-12-05T15:31:35.081200Z

@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 Boal 2020-12-05T15:32:01.081900Z

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

borkdude 2020-12-05T15:33:07.082200Z

@cgboal521 This is also a nice read, if you want more: https://clojure.org/guides/repl/introduction

Calum Boal 2020-12-05T15:51:05.082500Z

Cheers will take a look