Re: Simple program: who can write a shorter code?
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Wed, 04 Jul 2007 02:33:20 +0200
tar@xxxxxxxxxxxxx (Thomas A. Russ) writes:
Edi Weitz <spamtrap@xxxxxxxxxx> writes:
On Mon, 02 Jul 2007 15:56:46 -0000, "Anton V. Belyaev" <anton.belyaev@xxxxxxxxx> wrote:
I encountered a simple task: to write a function, which takes a
string and outputs ASCII codes of its characters, separated with
dots.
(defun foo (string)
(format nil "~{~A~^.~}" (map 'list #'char-code string)))
Pedantic comment:
This might not solve the original specification, because CHAR-CODE in
Common Lisp is not at all guaranteed to give you ASCII code values. At
the time of the standardization, the main competitor was EBCDIC. Today,
one could perhaps get one of the Unicode codepoint representations
instead.
The only sure way to get ASCII would be to write your own ASCII-CODE
function to translate characters into their ASCII codes. Unfortunately,
even that wouldn't be completely portable, because the required set of
supported characters in Common Lisp is only a subset of ASCII, so you
wouldn't necessarily be able to write all of ASCII.
But happily, all the printable characters of ASCII are in the standard
lisp character set, so you'll be able to convert to ASCII codes all
the standard characters you can put in a lisp string.
Control codes are not characters, they're CODES, after all.
But assuming that you have enough characters, including the control
characters, you could write this ASCII-CODE function as follows:
(defun ascii-code (char)
(position char *ascii-string*))
where *ASCII-STRING* is a constant string with all of the characters in
order.
--
Thomas A. Russ, USC/Information Sciences Institute
--
__Pascal Bourguignon__ http://www.informatimago.com/
NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
.
- Follow-Ups:
- Re: Simple program: who can write a shorter code?
- From: Thomas A. Russ
- Re: Simple program: who can write a shorter code?
- From: Edi Weitz
- Re: Simple program: who can write a shorter code?
- References:
- Simple program: who can write a shorter code?
- From: Anton V. Belyaev
- Re: Simple program: who can write a shorter code?
- From: Edi Weitz
- Re: Simple program: who can write a shorter code?
- From: Thomas A. Russ
- Simple program: who can write a shorter code?
- Prev by Date: Re: Is Lisp a Blub?
- Next by Date: Re: Non-standard method combinations: what good are they?
- Previous by thread: Re: Simple program: who can write a shorter code?
- Next by thread: Re: Simple program: who can write a shorter code?
- Index(es):
Relevant Pages
|