<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Dec 28, 2014, at 5:42 PM, Eli Barzilay <<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On Sat, Dec 27, 2014 at 6:21 PM, Alexander D. Knauth<br><<a href="mailto:alexander@knauth.org">alexander@knauth.org</a>> wrote:<br><blockquote type="cite">Is there any way to make the at-exp reader turn @list{A @"string" escape}<br>into (list "A " "string" " escape.),<br>instead of into (list .A string escape.) ?<br></blockquote><br>The idea behind this is that @|...| can be used to include not only any<br>Racket subexpression, but any number of them, so @|x| is just an<br>identifier as is often used, and if you need two of them, you can use<br>@|x y| which is more convenient than @|x|@|y|</blockquote><div><br></div><div>Thanks, this is actually almost perfect, so that way I can do something like</div><div>@my-printf{given: ~v and ~v@|x y|}</div><div><br></div><div>(But DrRacket colors the second one red, is that a bug?)</div><br><blockquote type="cite"> -- and @|| is therefore<br>the degenerate case. This means that you can get what you want with<br><br> @list{A @|"string"| escape}.<br><br>(Long explanation, but the bottom line would look magical without it...)<br><br><br>But...<br><br><blockquote type="cite">The reason is that I wanted to make my own versions of format, printf,<br>fprintf, error, etc. that would work with the at-exp reader and<br>convert something like this:<br>@my-error['f]{message<br> given: ~v@"something"<br> other-arguments: ~v@"something-else"<br>~v@"another-something-else"}<br>into something like this:<br>(error 'f "message\n given: ~v\n other-arguments: ~v ~v"<br> "something" "something-else" "another-something-else")<br></blockquote><br>... this is generally a bad idea. What do you do when you want the<br>@"..." escapes? How do you find out which parts of the input are<br>arguments and which are part of the format string? </blockquote><div><br></div><div>For that, I have a helper function that looks at the first argument, sees how many arguments it would take as a format string, and then takes the next n arguments as the place-fillers for that format string, then recursively looks at the next format string. </div><div><div><font face="Courier New">;; parse-format-args : (Listof Any) -> (Cons String (Listof Any))</font></div><div><font face="Courier New">(define (parse-format-args args)</font></div><div><font face="Courier New"> (match args</font></div><div><font face="Courier New"> [(list) (list "")]</font></div><div><font face="Courier New"> [(cons (? string? s (app format-string->num-of-args n)) rst)</font></div><div><font face="Courier New"> (unless (<= n (length rst))</font></div><div><font face="Courier New"> (error 'parse-format-args "format string requires ~v arguments, given ~v" n (length rst)))</font></div><div><font face="Courier New"> (define-values (rst.vs rst.rst) (split-at rst n))</font></div><div><font face="Courier New"> (match-define (cons rst.rst.s rst.rst.vs) (parse-format-args rst.rst))</font></div><div><font face="Courier New"> (cons (string-append s rst.rst.s) (append rst.vs rst.rst.vs))]))</font></div></div><br><blockquote type="cite">But most of all, IMO it sounds like a bad idea since it tries to fight<br>the natural mixed-text-and-expressions and bend it into a<br>format-string-like thing. I'd go with something that avoids that and<br>uses @-expressions more naturally, as in:<br><br> @my-error['f]{message<br> given: @~v[stuff]<br> other-arguments: @~v[other-stuff]}<br></blockquote><div><br></div><div>I wanted to be able to format things that can’t be converted to text and back properly, so for example in DrRacket this works:</div><div>@my-printf{the plt logo: ~v@(plt-logo #:height 50)}</div><div>But this doesn’t:</div><div>(display @string-append{the plt logo: @~v[(plt-logo #:height 50)]})</div><div>There is a similar-ish thing with syntax-objects and mixed numbers (and there are probably more) in DrRacket.</div><br><blockquote type="cite"><br>and have `my-error' be something like:<br><br> (define (my-error what . text) (error what "~a" (string-appeng* text)))<br><br><br>-- <br> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br> <a href="http://barzilay.org/">http://barzilay.org/</a> Maze is Life!<br></blockquote></div><br></body></html>