xlambein
2021-6-10 12:43:20

Yeah that’s why I used ..., I only knew about syntax-case


xlambein
2021-6-10 12:44:05

Didn’t think to change afterwards tho, thanks for pointing that out!


greg
2021-6-10 15:04:51

I thought your original code was, “one \n, followed by zero or more \n”. Which together actually means “1 or more” — not “2 or more”? Anyway, now you know the available building blocks, you can figure it out. :smile:


joshibharathiramana
2021-6-11 05:09:52

What is the rule of thumb for deep vs shallow copy? For e.g. I find the following confusing > (define (set-var! x) (set! x 5)) > (define (set-table! h) (dict-set! h 1 'a)) > (define x 2) > (set-var! x) > x 2 ; Value didn't change, deep copy > (define h (make-hash)) > (set-table! h) > h '#hash((1 . a)) ; Value changed, shallow copy


sorawee
2021-6-11 05:24:17

That’s not about shallow vs deep copy (which both are a kind of object mutation). Rather, it’s about binding mutation vs object mutation.


notjack
2021-6-11 05:28:15

it’s about your set-var! function, which is busted


notjack
2021-6-11 05:29:07

in (define (set-var! x) (set! x 5)) you’re only setting the function variable x, which is completely unrelated to any variables that happen to be around where you call set-var!


notjack
2021-6-11 05:29:21

otherwise how would (set-var! (+ 1 2 3)) work?


notjack
2021-6-11 05:29:50

if you want to pass mutable storage locations to functions like that, you should use boxes


notjack
2021-6-11 05:30:54

> (define (set-var! x) (set-box! x 5)) > (define x (box 2)) > (set-var! x) > (unbox x) 5


joshibharathiramana
2021-6-11 05:50:39

where can I read up more about binding mutation vs object mutation? Specifically which procedure does what


notjack
2021-6-11 06:14:28

set! is the only form that does binding mutation, and it’s not a procedure. Procedures can’t mutate bindings. They can only mutate objects.


joshibharathiramana
2021-6-11 06:15:59

Ah yes, my bad. It slipped my mind that it’s a special form. Thanks @notjack!