[racket] Strings as lists

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Sat Mar 3 12:45:30 EST 2012

Stepping back for a moment here: why do you want strings as charlists? It seems to me that the only real reason one would want to do that is the lack of general iteration facilities. You may want to look into the "for" macros and the "in-string" sequence generator.
-Ian
----- Original Message -----
From: Timothy Farland <twfarland at googlemail.com>
To: users at racket-lang.org
Sent: Sat, 3 Mar 2012 04:13:25 -0500 (EST)
Subject: [racket] Strings as lists

Hi racket folk, lisp neophyte here (just finished HTDP),

I would like to use Haskell-style strings in my racket, where a string is
defined as either '() or (cons character string), and is read from and
displayed by values enclosed by double quotes.

i.e: "string" is understood as '(#\s #\t #\r #\i #\n #\g) and '(#\s #\t #\r
#\i #\n #\g) is displayed as "string".

.. so one could do, for example (car "string") => #\s, or (cdr "string") =>
"tring" etc.

I've made altered versions of the basic list processing functions that act
differently when given strings or lists, so they achieve this, but at the
cost of a lot of runtime checks.

For a better approach I suspect one would need to deal with the 'reader,'
but looking at the documentation, it seems a bit beyond my current
understanding.

Has anyone else seen or built a language extension that achieves this, or
could anyone point me to some next-step resources that will bring me up to
the level where I can understand the reader documentation? Or is my
enterprise here misguided?

Many thanks

-- 
Tim Farland
e:twfarland at gmail.com


Posted on the users mailing list.