·······@gmail.com" <······@gmail.com> writes:
> How can I print escape-sequences in lisp. clisp does not whant to let
> me do
> (let ((string " "))
> (setf (aref str 0) 15))
Assuming your Lisp uses ASCII or some superset as its character code:
(write-char (code-char 15))
or
(format nil "~c" (code-char 15))
Also some Lisp's may provide names for those characters. For example
in Allegro:
(char-name (code-char 15)) ==> "^o"
If so you can use the name with #\:
(write-char #\^o)
-Peter
P.S. BTW, you should also note that modifying a literal object such as
" " has undefined consequences. If you really want to make a string
and modify it you should write:
(let ((string (make-string 1)))
(setf (char string 0) (code-char 15)))
--
Peter Seibel * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
Peter Seibel skrev:
> ·······@gmail.com" <······@gmail.com> writes:
>
> > How can I print escape-sequences in lisp. clisp does not whant to let
> > me do
> > (let ((string " "))
> > (setf (aref str 0) 15))
>
> Assuming your Lisp uses ASCII or some superset as its character code:
>
> (write-char (code-char 15))
>
> or
>
> (format nil "~c" (code-char 15))
>
> Also some Lisp's may provide names for those characters. For example
> in Allegro:
>
> (char-name (code-char 15)) ==> "^o"
>
> If so you can use the name with #\:
>
> (write-char #\^o)
argh! eh.. thanks.
Did not try (char-code 15). Not shure why :(
Peter Seibel wrote:
> ·······@gmail.com" <······@gmail.com> writes:
>
> > argh! eh.. thanks.
> > Did not try (char-code 15). Not shure why :(
>
> Note it's CODE-CHAR not CHAR-CODE. CHAR-CODE goes the other way.
>
> -Peter
Just to make sure the true lesson is not lost.
Strings in Lisp consist of CHARACTERS. 15 is not a CHARACTER, it is a
NUMBER. Putting numbers into Lisp strings is nonsensical.
CODE-CHAR and CHAR-CODE are ways to convert between a (typically
system-dependent) numerical coding of characters and the characters
themselves.
The confusion between characters and small integers is a symptom of C
programming.
> > argh! eh.. thanks.
> > Did not try (char-code 15). Not shure why :(
>
> Note it's CODE-CHAR not CHAR-CODE. CHAR-CODE goes the other way.
I read a Joel Spolsky article: Making Wrong Code Look Wrong
http://www.joelonsoftware.com/articles/Wrong.html
and it made me wonder about naming conversion routines.
Ought they to be named /from/ or /to/
For example:
(defun number-to-word (n)
(format nil "~R" n))
(defun word-from-number (n)
(format nil "~R" n))
(let* ((number 2)
(word1 (word-from-number number))
(word2 (number-to-word number)))
(list word1 word2))
=> ("two" "two")
In this example the /from/ convention makes it easier to
eyeball the code and spot wrong-way-round bugs
The /from/ convention seems to suit a variable on the left,
value on the right, prefix language, while the /to/
convention seems to suit a variable on the right, value on
the left, postfix language.
I feel tempted to draw ASCII arrows in my code and write my
conversion routines so that
(char<-code 97) and (code<-char #\a)
are correct.
The same considerations apply to the accessors made by
defstruct
(defstruct window background foreground)
(defun background-of-window (win)
(window-background win))
(let* ((window (make-window :background 'white :foreground 'black))
(background (background-of-window window))
(foreground (window-foreground window)))
(list foreground background))
(foreground (window-foreground window)) looks so
higgledy-piggledy, ABAB instead of AABB.
Alan Crowe
Edinburgh
Scotland
From: Joe Marshall
Subject: Re: vt100 Terminal Control Escape Sequences
Date:
Message-ID: <oe7ncp90.fsf@ccs.neu.edu>
Alan Crowe <····@cawtech.freeserve.co.uk> writes:
> The /from/ convention seems to suit a variable on the left,
> value on the right, prefix language, while the /to/
> convention seems to suit a variable on the right, value on
> the left, postfix language.
>
> I feel tempted to draw ASCII arrows in my code and write my
> conversion routines so that
>
> (char<-code 97) and (code<-char #\a)
>
> are correct.
>
> The same considerations apply to the accessors made by
> defstruct
>
> (defstruct window background foreground)
> (defun background-of-window (win)
> (window-background win))
>
> (let* ((window (make-window :background 'white :foreground 'black))
> (background (background-of-window window))
> (foreground (window-foreground window)))
> (list foreground background))
>
> (foreground (window-foreground window)) looks so
> higgledy-piggledy, ABAB instead of AABB.
There's a long tradition of doing it in from->to order and everyone
does it that way. I'm not sure that 'to<-from' is *so* much better
than from->to that it is worth being nonstandard.
Joe Marshall schrieb:
> Alan Crowe <····@cawtech.freeserve.co.uk> writes:
> There's a long tradition of doing it in from->to order and everyone
> does it that way. I'm not sure that 'to<-from' is *so* much better
> than from->to that it is worth being nonstandard.
Did you notice: Edinburgh.
Isn't this that Island where the car traffic also goes the other way?
Hallo Mr. Alan Crowe
Now, Scottland is a fine country on its way to Independence. Should be
time, to make some changes on the street also, hm?
stefan
Alan Crowe <····@cawtech.freeserve.co.uk> writes:
> I feel tempted to draw ASCII arrows in my code and write my
> conversion routines so that
>
> (char<-code 97) and (code<-char #\a)
But then normal order is from here to there.
----------->
So in right minded processors, you write:
move.w d0,d1
---->
or:
string->number
--------->
--
__Pasca Bourguignon__ http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink.