Idiomatically determine all the characters that can be used for symbols: Difference between revisions
Idiomatically determine all the characters that can be used for symbols (view source)
Revision as of 17:52, 23 November 2014
, 9 years ago→{{header|Racket}}
m (racket BEFORE rexx!) |
|||
Line 161:
=={{header|Racket}}==
[http://docs.racket-lang.org/guide/symbols.html Symbols in the Racket Guide] states that:
<lang racket>▼
<blockquote>Any string (i.e., any character sequence) can be supplied to <code>string->symbol</code> to obtain
the corresponding symbol.</blockquote>
[http://docs.racket-lang.org/reference/reader.html#%28part._parse-symbol%29 Reading Symbols] defines
what symbols can be "read" without needing quoting.
The docuementation for
[http://docs.racket-lang.org/reference/characters.html#%28def._%28%28quote._~23~25kernel%29._integer-~3echar%29%29 <code>integer->char</code>]
says that a character must lie in the ranges: 0 to 55295, and 57344 to 1114111.
That's too much to be printing out here... call <code>(main)</code> yourself, at home.
▲<lang racket>#lang racket
;; Symbols that don't need to be specially quoted:
(printf "~s~%" '(a a-z 3rd ...---... .hidden-files-look-like-this))
;; Symbols that do need to be specially quoted:
(define bar-sym-list
`(|3|
|i have a space|
|i've got a quote in me|
|i'm not a "dot on my own", but my neighbour is!|
|.|
,(string->symbol "\u03bb")
,(string->symbol "my characters aren't even mapped in unicode \U10e443")))
(printf "~s~%" bar-sym-list)
(printf "~a~%" bar-sym-list)
(define (main)
(for
((c (sequence-map
integer->char
(in-sequences (in-range 0 (add1 55295))
(in-range 57344 (add1 1114111)))))
(i (in-naturals 1)))
(when (zero? (modulo i 80)) (newline))
(display (list->string (list c)))))
</lang>
{{out}}
<pre>(a a-z 3rd ...---... .hidden-files-look-like-this)
(|3| |i have a space| |i've got a quote in me| |i'm not a "dot on my own", but my neighbour is!| |.| λ |my characters aren't even mapped in unicode |)
(3 i have a space i've got a quote in me i'm not a "dot on my own", but my neighbour is! . λ my characters aren't even mapped in unicode )</pre>
The output to <code>(main)</code> is massive, and probably not dissimilar to Tcl's (anyone want to compare?)
|