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

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Dec 29 19:44:04 EST 2014

On Tue, Dec 30, 2014 at 1:03 AM, 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".

There's a pile of very nice use cases...  I tried to cover some in the
reader paper, but there's things that go above that level (like Jay's
C-in-Racket thing), and there are some simple-but-convenient small
things like

    (define rx (compose1 regexp string-append))
    ... @rx{near-literal-regexp} ...

which I often use.


> 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})

Yes, exactly.  One comment though: strictly speaking, the @-form thing
is not "proper interpolation", since it doesn't convert stuff back to
strings to be planted in the original string.  (And IMO this is an
advantage, since the language is more well-behaved.)


> 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.

+17  (with the exception of those cases I mentioned earlier...)


On Tue, Dec 30, 2014 at 1:55 AM, Alexander D. Knauth
<alexander at knauth.org> wrote:
>
>> @~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,

Yes -- but that's only because of what `~a' etc are doing.  It sounds
like what you really want is a different set of simple functions that
actually print stuff instead of generating strings.

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

Posted on the users mailing list.