[racket] at-exp: is there any way to make it turn @list{A @"string" escape} into (list "A " "string" " escape") ?

From: Alexander D. Knauth (alexander at knauth.org)
Date: Mon Dec 29 18:55:49 EST 2014

On Dec 29, 2014, at 6:03 PM, Greg Hendershott <greghendershott at gmail.com> wrote:

>> 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]}
> 
> I had a similar thought. Actually I have a draft of a blog post
> looking at some handy ways to use @-exprs beyond "it's for writing
> Scribble". One way is to do what I believe langs like Python and Ruby
> refer to as "string interpolation".
> 
> Instead of:
> 
> (format "x is ~a and y is ~a" x y))
> 
> you could write:
> 
> @~a{x is @x and y is @y})

But this doesn’t work for values like images, syntax-objects, mixed-numbers, etc.
that can’t be converted to strings properly, so for example this works: (in DrRacket)
@my-printf{blah blah ~v@(plt-logo #:height 50) more blah blah ~v@#'stx more blah blah}
But this doesn’t:
(display @~a{blah blah ~v@(plt-logo #:height 50) more blah blah @#’stx more blah blah})
Also I want to be able to specify whether I want ~a or ~v etc, especially if one of the
arguments happens to be a string, while still handling images, syntax-objects etc. properly.

That’s why I wanted something that looked a bit more like @~a{x is @x and y is @y}, but
translated it to a format-like structure.

> With the format style you have to flip between the `~a`s on the left
> and the values on the right, making sure they match. How many times
> have you gotten them out of sync? Yeah, me too.
> 
> Whereas with the @-expr ("string interpolation") style, writing the
> values "inline" is arguably easier to write, read, and maintain
> correctly.
> 
> So if possible it might be nice to have it be @-exprs all the way up,
> rather than hiding that goodness below a format-style interface.



Posted on the users mailing list.