Fork me on GitHub
#beginners
<
2023-11-04
>
Felix Dorner08:11:51

Good Morning 🙂. When I want to use java methods as map functions, do I have to wrap that in a clojure function? E.g. I do (map #(.toUpperCase %) col) . Is there a better way?

tomd09:11:22

You can use memfn instead if you like, but it's never really caught on. Most people would do what you've done.

tomd09:11:26

There was mention of this being looked at for Clojure 1.12 but nothing has been released yet afaik. I think it's a tricky issue to solve.

Felix Dorner09:11:07

Is it the issue about java functional interfaces?

Felix Dorner09:11:13

Ah no that’s something else I guess

Fredrik11:11:57

There's the somewhat obscure memfn:

(map (memfn toUpperCase) ["abc"]) 
=> ["ABC"]

Fredrik11:11:36

I call it obscure because I rarely see it mentioned or used. But it does the thing you want. Up to you what you prefer, but there's nothing wrong with your original suggestion, it is pretty common to write it like that.

Alex Miller (Clojure team)12:11:07

This will be in 1.12 alphas soon

Alex Miller (Clojure team)12:11:18

(map .String/toUpperCase col)

8
👀 3
roelof10:11:13

Im doing the clojure koans and I wonder if I solve this one well :

"When things cannot be equal, they must be different"
  (not= :fill-in-the-blank :anything_else))

Fredrik11:11:16

Yeah that's a sweet solution 🙂

roelof11:11:09

I find it hard to see sometimes what they koans expect

roelof11:11:17

Koans ready till sets .

roelof11:11:21

Time for a break

phill11:11:08

Clojure sorts vectors by length first (the length of a vector being known without looking at the vector's contents). I think this is a fine example. Two very-long vectors with the first 999999999999 items in common, can't be equal if one of them is longer than the other.

roelof11:11:19

And why is this one wrong :

"You may have a multitude of possible paths"
  (let [x 5]
    (= :your-road (cond (= x 3) :road-not-taken
                        (= x 6) :another-road-not-taken
                        :else :your-road)))

Fredrik12:11:24

What indications are you getting that it's wrong?

roelof12:11:02

When I do "lein koans run" it still says that I have to medidate on this part

Fredrik12:11:53

Your solution works for me, can you show us the output you're getting?

roelof13:11:29

i getting crazy, I reopen the repo, and everything works

Fredrik13:11:49

cool, then good luck with the rest!

roelof13:11:06

I think the last parts will be really challening

roelof13:11:18

like the part about polyforism

roelof13:11:01

@U024X3V2YN4 did you do the koans to learn clojure basics ?

Fredrik13:11:25

I think I did most of the koans, and then Brave Clojure

roelof13:11:37

aha, I know that book , some things were difficult

Fredrik13:11:53

What is your programming background?

roelof13:11:01

maybe I do als that book and then the clojure track of exercism

roelof13:11:52

I have tried many languages but cannot make up my mind Last 2 years I spend on learning html, css (flex and grid)_ and js well

roelof13:11:15

and what is your background ?

Fredrik13:11:16

Hobby interest in Lisp, then Clojure.

roelof14:11:40

oke, for me curiosity. I like to discover languages that does things other then many languages

roelof14:11:37

first learn clojure well and then maybe look at web -development

λ13:11:37

Is data-driven programming and data-oriented programming 1:1?

phill15:11:41

DOP as defined at https://www.manning.com/books/data-oriented-programming is definitely not data-driven programming as described at https://en.wikipedia.org/wiki/Data-driven_programming

👍 1
roelof17:11:25

hopefully last question of the day What is here the right answer :

(def giants
  (with-meta 'Giants
    {:league "National League"}))

(meditations
  "Some objects can be tagged using the with-meta function"
  (= 'Giants' (meta giants))

roelof17:11:17

I have read it and I see this example

user=> (with-meta [1 2 3] {:my "meta"})
[1 2 3]
so it looks it gives the argument back

hiredman17:11:17

Single quotes are also not doing what you want like that

hiredman17:11:30

'foo is the same thing as (quote foo)

hiredman17:11:26

But ' is also valid as part of a symbol so 'foo' is (quote foo')

roelof18:11:43

Thanks Clojure is another beast then a lot of languages I tried

Muhammad Hamza Chippa20:11:15

Hi I am trying to use the react-hook-form how can I replicate these piece of code in shadow-cljs

const {
    register,
    handleSubmit,
    watch,
    formState: { errors }
  } = useForm();
I am not unable to get the errors by doing this
form (form/useForm)
register (.-register form)
handle-submit (.-handleSubmit form)
form-state (.-formState form)
 _ (js/console.log (:errors form-state))

dvingo20:11:06

errors will be a nested js obj so you need to continue using interop:

(.-errors form-state)
I like to wrap the return value of useForm with cljs-bean https://github.com/mfikes/cljs-bean
(let [form-methods (cljs-bean.core/bean (form/useForm))
      ;; you'll need to also invoke it for formState
      form-state (cljs-bean.core/bean (:formState form-methods))
      errors (:errors form-state)]

Muhammad Hamza Chippa20:11:03

(.-errors form-state)
is not working either

dvingo13:11:21

Sorry, without a complete code sample it is impossible to debug what is wrong. But, I would recommend getting more familiar with react-hook-form, Bill (the author of react-hook-form) has put a ton of effort into making high-quality documentation, e.g.: https://www.youtube.com/watch?v=4kzd572NbkM

Muhammad Hamza Chippa22:11:11

Hi I am trying to integrate react-hook-form and I am doing something like this and getting the empty object in the console. is there something i am doing wrong ?

(defn signin-panel []
  (let [register (.-register (useForm))
        handle-submit (.-handleSubmit (useForm))
        on-submit (fn [data]
                    (js/console.log data))]
    (let [vals (register "username" {:required true})]
      [:input {:props vals
               :placeholder "Username"}])
    ))

Sardtok09:11:09

Are you actually seeing a log message in the console at all? I can't see on-submit being used anywhere, it's just a local function. Also, style-wise you have a let in a let, should probably be just one let. I'll try to translate what you are doing to plain JS, so you can see what you've written:

function signinPanel() {
  let register = useForm().register;
  let handleSubmit = useForm().handleSubmit;
  let onSubmit = data => console.log(data);
  {
    let vals = register("username", {required: true});
    return ();
  }
}

Sardtok09:11:40

Note that register, being a JS function, probably takes a JS object as an arg:

(register "username" #js {:required true})