I’m skimming section 16.1 of “The Racket Guide” and I’m stuck on 16.1.4. I understand everything prior to 16.1.4 (of section 16.1 and not the whole guide). What does the following mean?
(define-syntax rotate
(syntax-rules ()
[(rotate a c …)
(shift-to (c … a) (a c …))]))
(define-syntax shift-to
(syntax-rules ()
[(shift-to (from0 from …) (to0 to …))
(let ([tmp from0])
(set! to from) …
(set! to0 tmp))]))
I understand that the “rotate” macro makes use of the “shift-to”. But how does a list “a c …” become “(c … a) (a c …)”?
And then in the “shift-to” macro the whole thing is confusing. How does “(c … a) (a c …)” map to “(from0 from …) (to0 to …)”?
Why does the list become “(c … a) (a c …)” as it gets plugged into the “shift-to” macro? Why is it “(shift-to (c … a) (a c …)) and not “shift-to (a c …) (c … a)”?
Let’s say I have a list ‘(1 2 3).
If I plug that into the “rotate” macro, then the “rotate” macro invokes the “shif-to” helper macro.
That part I understand.
What I don’t understand is how it went from list ‘(1 2 3) to “(shift-to (2 3 1) (1 2 …))”. And why in that order?
And how does “(shift-to (2 3 1) (1 2 …)” map to “(shift-to (from0 from …) (to0 to …)))”.
I’ve tried using ‘(1 2 3) as an example and working it out on paper, but it’s totally baffling.
not_Huyn_Bin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.