Fork me on GitHub
#clojure-uk
<
2020-04-15
>
dharrigan05:04:35

Good Morning!

thomas07:04:52

Good morning lovely people. How are you all this morning?

👍 4
Jakob Durstberger07:04:09

Morning :) Fine overall, just miss having people around. I am still not really used to working remotely

Johanna07:04:12

Morning 🌞

dominicm07:04:21

Apparently everyone in the village shops at 08:20 on a Wednesday, so I just bailed on that queue.

4
dominicm09:04:42

Figured I'd shop later (now), but now the queue has doubled... I wish I'd brought a coloring book or something.

alexlynham07:04:24

maybe it's a hump day thing

alexlynham07:04:41

everybody down my way seems to do it fri night and sat, like a proper activity

guy08:04:20

yeah i queued for food today as well

guy08:04:30

I think its a wednesday thing yeah, agree with alex

mccraigmccraig08:04:18

seems bank-holiday friday nights are a good time to go shopping around here - no queues at all on good friday eve

agile_geek09:04:51

Morning

👋 8
dharrigan09:04:30

As part of a effort by the company I work for, and to support people working at home, and to feel connected, I've volunteered to run an Introduction to Clojure/Programming course, starting on Friday!

👍 12
dharrigan09:04:34

3 people have signed up 🙂

🎉 8
dharrigan09:04:56

A colleague of mine is doing a Javascript workshop.

yogidevbear10:04:50

Which workshop had the larger sign up?

yogidevbear13:04:46

I suppose that is to be expected 🙂

agile_geek09:04:10

FYI I'm currently watching a 24 hour live online conference https://www.allthetalks.org/ . Mainly cos I'm bored but also because I strongly suspect my own conference https://bitrconf.org/ is not going to happen 'live' despite being postponed to 12th Nov and I'm looking for ideas about how to stream a multi stream conference.

👍 4
brunex10:04:28

Hi, question related with clojurescript macros: Given a list of `(def data [:foo :bar :baz])`, I want to dynamically generate:

(def foo (some-fn foo))
(def bar (some-fn bar))
(def baz (some-fn baz))
in clojure, I got something like this doing the job:
(def data ["foo" "bar" "baz"])

(defmacro test-macro
  [data]
  `(do
     ~@(map (fn [e]
              (let [e-name (symbol e)]
                `(def ~e-name (some-fn ~e))))
         (deref (resolve data)))))

(macroexpand-1 '(test-macro  data))
the main issue is the `resolve`  part I guess 😕

brunex10:04:59

does anyone already tried something similar in clojurescript ?

alexlynham10:04:20

kind of seems like you might want a multi method

alexlynham10:04:35

though it depends on how you want to call it I guess

alexlynham10:04:09

but this rings to me of a case where a macro is papering over a need to step back and reassess the design - although I can't be sure without knowing the exact use-case

👍 4
yogidevbear10:04:06

Morning 😄

👏 8
rickmoynihan11:04:59

@brunex: Without knowing more it looks to me like this is best covered by the first rule of macro club 🙂 What exactly do you want to do? And why do you need a macro? It looks like you’re just partially applying a function with the values of data and building a var for it. To address the problem you’re finding though; clojurescript’s compiler is written in clojure, and macros are expanded in clojure, not clojurescript, but their expansion is sent to clojurescript/js for execution. Hence the problem is indeed with the resolve part, as clojurescript doesn’t have proper vars, and hence you can’t resolve them there. i.e. your macro is resolving the var in the expansion, not at compile time.

rickmoynihan11:04:30

If you remove the (deref (resolve data)) and replace it with just data you can probably avoid the issue if you’re happy to call the macro like this: (test-macro ["foo" "bar" "baz"]) At least that’s my suspicion, I haven’t actually tried it.

rickmoynihan11:04:07

But again you probably don’t need or want a macro here… or if you do, you probably want to move the goal posts a bit and make it work differently to more easily align with what you require of it. However without knowing more about the real use it’s impossible to say.

brunex11:04:35

thanks @rickmoynihan,and yes it works if I use the data literal ["foo" "bar" "baz"]

brunex11:04:04

is there anyway of declaring global namespace vars in clojurescript run-time

rickmoynihan11:04:26

what do you mean?

rickmoynihan11:04:52

you mean declaring the data var?

brunex11:04:53

something like this:

(doall (for [e data]
             (eval `(def ~(symbol (->kebab-case e)) (component e)))))

brunex11:04:11

eval is also missing 😛

rickmoynihan11:04:43

indeed — but eval is also evil (except when it’s not 😁 )

alexlynham11:04:57

> Your scientists were so preoccupied with whether or not they could, they didn't stop to think if they should.

mccraigmccraig11:04:57

@brunex clojurescript doesn't have vars!

brunex11:04:52

what I would like todo, is to lookup some data-structure in run-time declare some namespace global accessible vars

mccraigmccraig11:04:44

generally, use an atom and wrap the access in a fn

brunex11:04:23

somewhere on stackoverflow someone was suggesting:

(set! namespace.somehting.variable value)
but shadow-cljs throws a exception 😕

rickmoynihan11:04:03

@brunex ok but clojurescript doesn’t have a self hosted compiler, and compile time in clojurescript is a lot further away from runtime in cljs… i.e. compiling cljs is more like AOT compilation.

rickmoynihan11:04:45

so you can indeed resolve stuff available to the clojure runtime; but generally that’s not available at cljs runtime. It depends exactly on what you know/when.

brunex11:04:14

yep I need to change my approach

brunex11:04:16

thanks guys

Wes Hall15:04:11

I always feel like Clojurescript would be great if it wasn't for Javascript 😉. I'd quite like to go back in time and tell Brendan Eich, "Hey dude, so in 25 years, this language you are hacking up will be the foundation of the worlds largest and most important information and commerce platform.... take a couple of extra days... "

🚀 8
mccraigmccraig15:04:41

i reckon clojurescript is pretty great despite javascript, and even javascript isn't so bad apart from the horror of type-coercion. you should definitely use your time-machine to get rid of that

Ben Hammond15:04:41

this is starting to sound like a > I'm just putting out a quick production fix. its so simple it doesn't need testing kinda scenario

Ben Hammond15:04:20

you don't have a crystal ball and you never get everything right

Ben Hammond15:04:38

its the way you improve the language over time that mattters

Ben Hammond15:04:13

Javascript seems to be able to grow and better itself at the moment

Ben Hammond15:04:20

so its all good

Ben Hammond15:04:32

and you couldn't really stop M$$ doiing all it could to throw a spanner into the cross-browser compatibility in the late 90s

tragiclifestories15:04:56

I have to say that a few of the many changes to the language made a huge amount of difference to how enjoyable I find it to write today (basically destructuring, promises and lambdas). I don't do so much Javascript as I used to, but I find it pleasant to come back to every time.

tragiclifestories15:04:13

I wonder if the reason people hate it is basically because everybody has to write it at one time or another, so if you have very different opinions about the Right Way to do things, it can be frustrating indeed to be stuck with it anyway. You can just choose not to write PHP, but there just isn't anything like parity of library coverage and community support and so on between CLJS / Elm / Purescript and whatever else and plain old JS, so most people are stuck with it (or with a more semantically similar dialect like Typescript)

folcon19:04:14

Just a quick check to any emacs/cider user the keyboard shortcut to take this:

(comment
  (+ 1 1)|)  ;; the | stands for the cursor...
and send it to the repl is CTRL-x CTRL-e right?