Fork me on GitHub
#clojure
<
2021-04-24
>
Alexander Kaiser11:04:20

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 Kaiser11:04:47

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 Kaiser12:04:08

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.

p4ulcristian14:04:02

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?

vncz14:04:58

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?

vncz14:04:28

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

vncz14:04:41

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

p-himik14:04:08

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

p-himik15:04:23

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

vncz15:04:01

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

p-himik15:04:41

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.

Darrick Wiebe16:04:43

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 Wiebe16:04:11

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

p-himik16:04:48

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

vncz17:04:15

cdr is from decrementing register according to what I read

Darrick Wiebe21:04:54

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! 🙂

potetm14:04:59

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

noisesmith17:04:03

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

noisesmith17:04:36

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)

potetm14:04:15

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

potetm14:04:37

(And I find much of the syntax confusing.)

Stuart14:04:15

I find scheme harder to parse.

vncz15:04:29

Parse as human or through other computer programs?

Stuart15:04:02

In my head to understand what the code is doing.

vncz15:04:50

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

Stuart15:04:28

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

vncz15:04:53

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!

andy.fingerhut15:04:45

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.

andy.fingerhut15:04:58

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."

☝️ 3
andy.fingerhut15:04:15

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

vncz15:04:12

I’ve watched all the talks, yes.

vncz15:04:29
replied to a thread:I find scheme harder to parse.

Parse as human or through other computer programs?