[racket-dev] Square-bracket-sensitive macros in Scribble sandboxes

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Nov 30 10:24:05 EST 2012

Yesterday, Neil Toronto wrote:
> I wouldn't want to write that, either. Right now, you'd write
>    (array
>     #[#[(list (1- i) (1- j)) (list i (1- j)) (list (1+ i) (1- j))]
>       #[(list (1- i)     j ) (list i     j ) (list (1+ i)     j )]
>       #[(list (1- i) (1+ j)) (list i (1+ j)) (list (1+ i) (1+ j))]])
> The vector syntax just delimits rows; it never quotes.

OK, so it's like the `array*' I suggested later, right?  If that's the
more useful use case, then it probably makes sense to have `array' do
it.  (It should be clear in the docs, of course.)

BTW, I didn't realize that this is a syntax that construct something
completely different.  What happens when I want to have a plain vector
as a value?  Forcing me to use `vector' for that seem a bit odd.

> Square parens aren't required, but make rows easier to distinguish.

(I don't care much -- I just stuck to #()s to stress the fact that
they shouldn't matter.)

> Arrays' custom printers print square parens, which gives feedback
> when a user is confused about whether #(...) means a row or a
> vector-valued element.

Related to the above BTW -- if I can't write vector literals in code,
then it's probably a bad idea to show them in your printed

> Quotes and quasiquotes stop the `array' macro's recursion into rows,
> so quotes always mean "this is an element". For example, this is a
> zero-dimensional array that contains a vector:
>    (array '#(0 1 2 3))

Ah.  Sneaky.  Especially since (IIUC) in `#(... ,(blah) ...) the blah
part isn't done either.  More concretely, the 2 in #[1 `,2 3], which
might be a result of some macro.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.