ASCII codes in Maxima



Am 26 Nov 2005 um 19:55 hat Alasdair McAndrew geschrieben:

> Is there any way of converting between characters and their ascii
> codes?  So that, for example, "a" <-> 97, and "&" <-> 38?
> 
> thanks,
> Alasdair
> 

Yes,
I have contributed a string package 'stringproc', which also includes some I/O-functions. 
It will be included in 5.9.3.
At the moment, download it from www.biomates.net
This is a web page hosted by Maxima developer Mario Rodríguez Riotorto.
There you find two versions, one for 5.9.1 and one for 5.9.2.

The functions you are looking for:  

(%i10) load("stringproc1");  ( 5.9.1 ! )
(%o10) 	                    D:\home\maxima\stringproc1.lisp
(%i11) ascii(38);
(%o11) 				       &
(%i12) cint("a");
(%o12) 				      97

ascii is a function, which is based on function ascii at lisp level in maxima.
You can just call this function with ?ascii (without loading 'stringproc').

(%i13) ?ascii(38);
(%o13) 
(%i14) ?ascii(98);
(%o14) 				       b

With the exception of ascii(38) the '&', because this character is characteristic for 
Maxima strings on lisp level and is stripped off when printed.

Mario told me, there might be problems with function ascii when Maxima is using clisp.

Hope it works

Volker van Nek