From ... Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!zeus.visi.com!priapus.visi.com!orange.octanews.net!news.octanews.net!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed1.e.nsc.no!nsc.no!nextra.com!uio.no!nntp.uio.no!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: Macro to enable Perl-style strings Date: 18 Jan 2004 21:26:17 +0000 Organization: Naggum Software, Oslo, Norway Lines: 37 Message-ID: <3283449977481024KL2065E@naggum.no> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: readme.uio.no 1074461178 14472 129.240.65.210 (18 Jan 2004 21:26:18 GMT) X-Complaints-To: abuse@uio.no NNTP-Posting-Date: Sun, 18 Jan 2004 21:26:18 +0000 (UTC) Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: archiver1.google.com comp.lang.lisp:10248 * Nepheles | I hacked together a short macro to enable you to use Perl-style | strings in Lisp. I.e., something like "Today is $DAY" will have $DAY | replaced with the (symbol-value) of DAY. [...] Unfortunately, this | forbids lexical variables. Let the caller of the macro evaluate the expression, instead. E.g., the macro call (evalstr "mumble $foo $bar $zot mumble") should return (concatenate 'string "mumble " foo " " bar " " zot " mumble"). You should use READ-FROM-STRING to pick up the symbol names from the string, not try to parse and hack things together yourself. Just give it a :START argument of the position following the $. Then you can use any Common Lisp expression you want after the $, not just simple variable names. I recommend :PRESERVE-WHITESPACE T, so any whitespace that terminates the expression is part of the string literal. This function returns the position following what it just read. Once you have this working, consider using a reader macro, instead, so that, e.g., $"mumble $foo $bar $zot mumble" returns the expression at read-time. Some languages need special syntax to prevent the name of the variable from running into the following text. If you follow my suggestions, you can use "foo$(values bar)zot" or any other expression that returns the evaluated value. (Note that QUOTE does not.) But if you're really into syntactic sugar, you could write a reader macro for {...} that returns (values ...). I have not looked at the pre-existing solutions for interpolating strings, but I would be surprised if they did not do most if not all of the above. -- Erik Naggum | Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.