[racket] heredoc syntax

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Aug 18 18:19:54 EDT 2011

Two minutes ago, Jon Rafkind wrote:
> 
> My issue is that first I try @{foo} and get the error "expected a
> procedure, given a string". At which point I remember kevin telling
> me off-hand how you (eli) had a trick to deal with these situations,
> which was to put string-append between the @ and {.

It's not really a trick.  What if you want to do something else:

  (define foo 123)
  @string-append{blah @foo blah}

this reads as

  (string-append "blah " 123 " blah")

Obviously, `list' won't work in all cases too, since you might want a
string.

Instead, things are kept very simple -- and very *uniform*: both the
"command part" (following the `@') and the "datums part" (inside `[]')
are put in a list, before the rest of the actual text.  Since the
command part is optional, you can omit it, but then

  @{foo bar baz}

reads as ("foo bar baz")

Another exmaple:

  @[emph]{blah}

reads as (emph "blah") which is the same as

  @emph{blah}

If you want a cheap way to have a list of text, you could use quote
(again, uniformity is top priority, which makes these things fall off
for free):

  '{for bar baz}

but there's no similar way to get a single string, because of the
"interpolation" feature.  (Not really interpolation, but close in
spirit.)


> Could @{ as a special case do string-append for me?

BTW, you could still do it in your language:

  -> ,r scribble/reader
  -> (read-syntax)
  @{foo}
  #<syntax::34 ("foo")>
  -> (syntax-property ^ 'scribble)
  '(form #f 1)

having a scribble property that starts with `form' identifies a form,
and the #f identifies the missing command part.  (I don't remember
what's 1, but that should be easy to find.)

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


Posted on the users mailing list.