[racket] at-exp: is there any way to make it turn @list{A @"string" escape} into (list "A " "string" " escape") ?
On Sat, Dec 27, 2014 at 6:21 PM, Alexander D. Knauth
<alexander at knauth.org> wrote:
> Is there any way to make the at-exp reader turn @list{A @"string" escape}
> into (list "A " "string" " escape.),
> instead of into (list .A string escape.) ?
You can use @|| to force string delimiters -- but that would probably
not be something you want to use:
@list{A @||@"string"@|| escape}
The idea behind this is that @|...| can be used to include not only any
Racket subexpression, but any number of them, so @|x| is just an
identifier as is often used, and if you need two of them, you can use
@|x y| which is more convenient than @|x|@|y| -- and @|| is therefore
the degenerate case. This means that you can get what you want with
@list{A @|"string"| escape}.
(Long explanation, but the bottom line would look magical without it...)
But...
> The reason is that I wanted to make my own versions of format, printf,
> fprintf, error, etc. that would work with the at-exp reader and
> convert something like this:
> @my-error['f]{message
> given: ~v@"something"
> other-arguments: ~v@"something-else"
> ~v@"another-something-else"}
> into something like this:
> (error 'f "message\n given: ~v\n other-arguments: ~v ~v"
> "something" "something-else" "another-something-else")
... this is generally a bad idea. What do you do when you want the
@"..." escapes? How do you find out which parts of the input are
arguments and which are part of the format string? (A proper answer for
the last one is something that I mentioned recently -- looking at the
syntax properties -- but it means that you're getting a non-uniform
syntax where you can't switch an @-expression into an s-expression.)
But most of all, IMO it sounds like a bad idea since it tries to fight
the natural mixed-text-and-expressions and bend it into a
format-string-like thing. I'd go with something that avoids that and
uses @-expressions more naturally, as in:
@my-error['f]{message
given: @~v[stuff]
other-arguments: @~v[other-stuff]}
and have `my-error' be something like:
(define (my-error what . text) (error what "~a" (string-appeng* text)))
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!