Subject: Re: Why is 'if' a special form?
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1998/07/25
Newsgroups: comp.lang.scheme
Message-ID: <6pblhn$193h2@fido.engr.sgi.com>
Barry Margolin  <barmar@bbnplanet.com> wrote:
+---------------
| AFAIK, square brackets don't have any special meaning in CL or Scheme...
+---------------

Not officially, but in quite a few popular implementations they are
considered completely equivalent to parens (except that left & right
brackets must match brackets, and likewise for parens). Particularly
in Scsh and MzScheme code, the square brackets get used a *lot* for
the elements of "let" bindings for readability, e.g.:

    (let* ([ls (regexp-match-positions last-pat last-line)]
           [td (regexp-match-positions (regexp "</TD>") last-line)]
           [t0 (substring last-line (cdar ls) (caar td))]
           [t1 (regexp-replace* (regexp "<[^>]*>") t0 "")]
           [t2 (regexp-replace* (regexp "\&nbsp;") t1 " ")])
      ...body
	  of
	   let...)

While I personally don't write code that way, I admit I find it helpful
when reading complex "let-values" (a MzScheme form of mv-bind), since
the variable part of a binding can itself be a list. An example from a
random MzLib function:

  (define somefunc
    (lambda (get-next-record . rest)
      (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))]
		    ...more bindings...)
        ...body of let...)))

Oh, sure, if (say) R6RS defined square brackets to mean something specific
(such as denoting thunks), it would only take "a small matter of programming"
(uh, editing) to fix all the legacy code, but it *is* something to consider.


-Rob

-----
Rob Warnock, 7L-551		rpw3@sgi.com   http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
2011 N. Shoreline Blvd.		FAX: 650-933-4392
Mountain View, CA  94043	PP-ASEL-IA