LW Owens <lwo2@airmail.net> wrote:
+---------------
| Why do people use square brackets? Do you intend a semantic
| distinction between ( ) and [ ], and if so, what?
+---------------
The Rice folks seem to use them mainly for visual emphasis, to make it
easier to pick out certain sub-forms in heavily-nested expressions,
especially around each variable binding in a "let" or let-like form, e.g.:
(let ([var1 (this (that) the other)]
[v2 (some (+ other thing) here)]
[last (* one (/ more example))])
...body...)
To me, this hardly seems a great improvement, but in the case of,
say, "let*-values" some might find it more helpful, as in this
fragment clipped from "plt/collects/mzlib/awkr.ss":
(let*-values ([(user-fields rest) (values (car rest) (cdr rest))]
[(counter rest) (if (and (pair? rest) (symbol? (car rest)))
(values (car rest) (cdr rest))
(values (gensym) rest))]
[(user-state-var-decls rest) (values (car rest) (cdr rest))]
[(continue rest) (if (and (pair? rest) (symbol? (car rest)))
(values (car rest) (cdr rest))
(values (gensym) rest))]
[(user-state-vars) (map car user-state-var-decls)]
[(local-user-state-vars) (map gensym user-state-vars)]
...)
...)
Since in this case each binding sub-form binds a list of variables
to the values of a multiple-valued expression, the square brackets
perhaps provide some helpful visual punctuation.
They also use them in the branches of a "cond", which I find much less
compelling. In fact, to me, both plain "let" and "cond" are more readable
*without* the square brackets, and their use in "let*-values" is marginal
(again, to my taste).
But, as they say, YMMV...
-Rob
-----
Rob Warnock, 31-2-510 rpw3@sgi.com
Network Engineering http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. PP-ASEL-IA
Mountain View, CA 94043