2
votes

This is an example of for loop in Racket:

(define List '(1 2 3))
(for ((I List))
  (displayln I)
)

In Scheme/Racket, the single-parenthesis pair wrapping about something is for evaluation. But the for loop form above takes the first param as ((I List)) which is wrapped in double-parenthesis pair.

That seems like:

  • First, evaluate (I List)
  • Then, evaluate I List

What's the actual, theoretical meaning of this kind of evaluation, in double-parentheses?

1
It might be helpful to know that while you will see list of bindings in Scheme as double parentheses very often, Racket allows brackets to act like parentheses, and some (arguably most) Racket users would be more likely to write a binding using bracket. That is, write (for ([x '(1 2 3)]) (displayln x)) instead of (for ((x '(1 2 3))) (displayln x)). Same for cond, syntax-case, etc. - Sorawee Porncharoenwase
the [ ] is in general programming is a list of something, so i now prefer using for [(i List)] Form instead :) - datdinhquoc

1 Answers

3
votes

It's a sequence of bindings not a function call.

(let* ((x 1) (y 2) (z 3))  ; <-- sequence of bindings
  (displayln (+ x y z)))

Analogously:

(for ((x '(1 2 3)) (y '(3 2 1))) ; <-- like above 
  (displayln (+ x y)))

Theoretically, either the language parses them differently or they expand to other forms (macros).