clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Alexander Kaiser 2021-04-24T11:14:20.008200Z

Hi, I have a question about core.match If a map pattern comes from a local binding then it behaves like [(map-pattern :only [(keys map-pattern)])] instead of [map-pattern]

(let [map-pattern {:a 1}]
    (match [{:a 1 :b 2}]
           [map-pattern] true
           :else false
           ))
  ;; => false
How can i avoid that core.match matches map patterns from local bindings with the :only pattern?

Alexander Kaiser 2021-04-24T11:15:47.008300Z

These work as expected:

(match [{:a 1 :b 2}]
       [{:a 1}] true
       :else false
       )
;; => true


(match [{:a 1 :b 2}]
       [({:a 1} :only [:a])] true
       :else false
       )
;; => false

(let [map-pattern {:a 1}]
  (match [{:a 1}]
         [map-pattern] true
         :else false
         ))
;; => true

Alexander Kaiser 2021-04-24T12:44:08.008600Z

Is it maybe not possible to do this? It seems that patterns in local bindings are treated as literals and are only valid if they are exactly matched against them self.

paul931224 2021-04-24T14:23:02.011100Z

Hello Clojurians. What is the best way to hot reload my clojure files on change? I use deps.edn . I am not able to use wrap-reload because it wants a declared variable, but I use function , because my system depends on re-frame , so my subscribe is nil in the first run. Is there any other way, without having to use some restart mechanism on the backend?

vncz 2021-04-24T14:48:58.012400Z

I do not know about you people — and this might be stupid — but now that I do Clojure I struggle to read Scheme. Even though it’s still LISP, it appears to me to be confusing. Anybody has the same experience?

vncz 2021-04-24T14:49:28.012800Z

To be a little bit more specific, I am reading this book: https://mitpress.mit.edu/books/software-design-flexibility — and all the examples are in Scheme

vncz 2021-04-24T14:52:41.017100Z

The two biggest confusion point that I’ve found I’ve found: 1. Clojure uses vector for arguments, while Scheme uses regular lists. That requires me to pay a little bit more attention than regular to identify functions. 2. There’s a number of forms that are confusing. For instance, to define a function: (define (function-name arg1 arg2) ‘(arg1 arg2))) The function name looks like another special form and that confuses me a bit instead of (def function-name (fn [arg1 arg2] ‘(arg1 arg2)))

2021-04-24T14:57:59.018100Z

They’re two completely different languages. The only similarity is that they structure the language with parentheses.

2021-04-27T17:30:03.085Z

they are both aggressively lexically scoped (let has similar rules, function closures have the same capture behavior)

2021-04-27T17:30:36.085200Z

the surface level syntax is more diverse for clojure, semantically they are very similar (though the scheme functions for vectors and sets and hash-maps are excessively verbose)

p-himik 2021-04-24T14:58:08.018400Z

> Anybody has the same experience? Yep. And let.

2021-04-24T14:58:15.018700Z

So yeah. I cannot read scheme or common lisp. 🙂

2021-04-24T14:58:37.019Z

(And I find much of the syntax confusing.)

2021-04-24T14:59:15.019100Z

I find scheme harder to parse.

p-himik 2021-04-24T15:02:23.019200Z

And to be fair, I learned Scheme to some extent way before Clojure, via SICP. And it was just as confusing back then.

vncz 2021-04-24T15:10:01.020Z

It might also be just because I’m used to Clojure. People writing Scheme might say the same of Clojure

p-himik 2021-04-24T15:13:41.020800Z

I've seen this argument before. The nitpick was, IIRC, "Clojure doesn't use S-expressions everywhere". Why exactly it's bad, wasn't really described.

2021-04-24T15:14:02.021Z

In my head to understand what the code is doing.

vncz 2021-04-24T15:19:50.021600Z

Same here. Apparently this book ain’t gonna be easy to read then!

2021-04-24T15:22:28.021800Z

Im reading this book currently too. Its tough, both the scheme and the concepts!

vncz 2021-04-24T15:23:53.023Z

I’ve read the first chapter on the regular expression and the temperature converter. So far it was not life changing, it’s something that I’ve been doing/advocating anyway in the past. Will see how the rest turns out!

2021-04-24T15:31:45.023200Z

Coming to that book from Clojure might not be as life-changing is it might be coming from a different background. I bought a copy but haven't read it yet, but I suspect if you've listened to many of Rich Hickey's talks, you will find some similar advice in this book. I also fully believe the book will have some good gems spread throughout.

2021-04-24T15:32:58.023400Z

This question of Scheme/Common Lisp readability after being accustomed to Clojure reminds me of the phrase: "The United States and Great Britain are two countries separated by a common language."

☝️ 1
2021-04-24T15:41:15.023600Z

i.e. most things look familiar, but a little bit of the vocabulary means something completely different than you expect.

vncz 2021-04-24T15:48:12.024Z

I’ve watched all the talks, yes.

Darrick Wiebe 2021-04-24T16:40:43.024200Z

I have read through this book, and yes the scheme took a bit of time to get comfortable with. Fortunately the book is very light on macros, which is not the case with other scheme I've encountered! A difference from Clojure that was confusing at first is that scheme apparently treats (...) and [...] the same, so those forms are interchangeable and how people use them is simply a matter of style. Once I got used to the (define (fn-name arg1 arg2 . rest) ...) form I admit that I found it kind of elegant, since it means the function definition looks exactly like the function invocation. On the other hand it loses out on Clojure's ability to define multiple arities... As I got farther along, I started thinking of scheme (let loop [x x y y] ... (loop (cdr x) (cdr y))) as virtually identical to Clojure's (loop [x x y y] ... (recur (next x) (next y))), though the Scheme syntax is more expressive because you can use it in more complex nestings, so when porting the code I'd need to pull out code into letfn forms, which I also pulled out whenever I came across a nested define... Curiously, letfn does seem more scheme-like than other parts of Clojure... Anyway, it's a great book! Have fun!

Darrick Wiebe 2021-04-24T16:45:11.024400Z

Oh yeah the worst named scheme standard functions: memq -> contains? and iota -> range.

p-himik 2021-04-24T16:48:48.024600Z

cdr is not much better. :D Everything has its history, of course, but without knowing it it's impossible to guess what it does.

vncz 2021-04-24T17:51:15.025200Z

cdr is from decrementing register according to what I read

Darrick Wiebe 2021-04-24T21:08:54.025600Z

Yeah, I guess I've encountered enough cdaddrs by now to be able to just untangle them and move on without another thought. Clever hacks from the dawn of time... Definitely glad Clojure dropped them! 🙂