From: ······@gmail.com
Subject: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <1124821826.326105.199970@g43g2000cwa.googlegroups.com>
How can I print escape-sequences in lisp. clisp does not whant to let
me do 
(let ((string " "))
   (setf (aref str 0) 15))

From: Peter Seibel
Subject: Re: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <m28xysts6u.fsf@gigamonkeys.com>
·······@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/
From: ······@gmail.com
Subject: Re: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <1124823532.980780.88000@g47g2000cwa.googlegroups.com>
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 :(
From: Peter Seibel
Subject: Re: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <m24q9gtqly.fsf@gigamonkeys.com>
·······@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


-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: ··············@hotmail.com
Subject: Re: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <1124909531.772976.91390@o13g2000cwo.googlegroups.com>
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.
From: Alan Crowe
Subject: Re: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <86wtmb7egr.fsf@cawtech.freeserve.co.uk>
> > 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.
From: lin8080
Subject: Re: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <430CE1C6.37895809@freenet.de>
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
From: Pascal Bourguignon
Subject: Re: vt100 Terminal Control Escape Sequences
Date: 
Message-ID: <87y86r31dp.fsf@thalassa.informatimago.com>
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.