(list 1 (string->symbol (string #\; #\" #\))) 2)
Guile prints it as (1 #{.\\;\\\"}# 2). In CL:
[1]> (list 1 (make-symbol (coerce (list #\; #\" #\)) 'string)) 2)
(1 #:|;")| 2)
Both of these choices strike me as baroque, but
(1 ;") 2)
is worse.
I think your example and output are mismatched; my system prints
(1 #{\;\"\)}# 2)
'#{...}#' seems to be the delimiter for a nonstandard symbol name
a single backslash is a standard escape character.
> In CL:
>
> [1]> (list 1 (make-symbol (coerce (list #\; #\" #\)) 'string)) 2)
> (1 #:|;")| 2)
Translating this:
a '#:' prefix means the symbol does not belong to any package.
'|...|' delimits symbols containing nonstandard characters.
';")' is the name of the symbol.
- Daniel
Patient: each time I do this, it hurts terribly.
Doctor: don't do it, then.
That being said, Common Lisp's |...| notation comes to mind.
--
Nils M Holm | http://t3x.org
>Is there a consensus on how to print funny symbol names
>in Scheme?
There is a standard for it, if that's what you mean. R6RS describes and
details a syntax for printing and entering symbols containing the range
of unicode characters inthem. It is less pretty than some solutions, but
more pretty than others, and it is, at least, fully general and safe on
ASCII terminals.
> I'm wondering about stuff like:
>(list 1 (string->symbol (string #\; #\" #\))) 2)
>Guile prints it as (1 #{.\\;\\\"}# 2). In CL:
>[1]> (list 1 (make-symbol (coerce (list #\; #\" #\)) 'string)) 2)
>(1 #:|;")| 2)
>Both of these choices strike me as baroque, but
>(1 ;") 2)
>is worse.
There are many different syntaxes that Schemes have for entering
symbols, though I know of less for displaying them. On Chez Scheme, the
R6RS syntax is supported, as well as backslash and |...|. The most
commonly supported ones are, I think |...| and maybe R6RS if you want to
count all of the R6RS Schemes out there.
However, since all of these are non-standard and they don't always
behave in the same way, you have to be aware of their gotchas when you
use them.
Aaron W. Hsu
How does Chez display that symbol?
FWIW, MzScheme prints (1 |;")| 2), as will Common Lisp (below).
+---------------
| > In CL:
| > [1]> (list 1 (make-symbol (coerce (list #\; #\" #\)) 'string)) 2)
| > (1 #:|;")| 2)
|
| Translating this:
| a '#:' prefix means the symbol does not belong to any package.
| '|...|' delimits symbols containing nonstandard characters.
| ';")' is the name of the symbol.
+---------------
Expanding on Daniel's translation... ;-}
MAKE-SYMBOL is not an exact equivalent to Scheme's STRING->SYMBOL, since
it always creates an *un*interned symbol [hence the "#:" prefix noise]
that will never be EQ to anything else one might ever read in, e.g.:
> (make-symbol "FOO")
#:FOO
> (eq '#:FOO '#:FOO)
NIL
> (eq '#:FOO (make-symbol "FOO"))
NIL
> (eq (make-symbol "FOO") (make-symbol "FOO"))
NIL
>
Probably the closest CL equivalent to STRING->SYMBOL is INTERN,
though it too is not exact, because of the second, optional package
argument (which defaults to the current package in *PACKAGE*),
but it's probably the right thing to use in the original example:
> (list 1 (intern (coerce (list #\; #\" #\)) 'string)) 2)
(1 |;")| 2)
>
which one will observe is the same as what MzScheme printed.
-Rob
-----
Rob Warnock <rp...@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
Thanks!