Re: Simple program: who can write a shorter code?



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.
.



Relevant Pages

  • Re: Writing extended ascii characters to text file.
    ... John ... so in order to get real ASCII codes you should use the GetBytes ... >> I am just trying to port an existing simple encryption routine to C#. ... >> however when I encrypt the file, several characters are corrupted. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple program: who can write a shorter code?
    ... (defun foo (string) ... The only sure way to get ASCII would be to write your own ASCII-CODE ... function to translate characters into their ASCII codes. ...
    (comp.lang.lisp)
  • Re: "a" or "an" before "h----"
    ... I fear not, as plain text means "characters with the ASCII codes 0--127, ... moved beyond ASCII codes 0--127 as The One And Only Standard, ...
    (alt.usage.english)
  • Unicode and ASCII codes
    ... strTmp contains not only standart set of characters (ASCII codes from 1-127) ... I need to output this string to the file - WHERE EVERY CHARACTER REPRESEND ... bite and from the extended table 2 bites. ...
    (microsoft.public.dotnet.languages.vb)
  • CHR$() and international characters.
    ... In PB/WIN v8.04 I would like to construct a string using ASCII codes, ... On the other hand these characters prints correctly to the screen in PBCC, ... With the numerously number of international customers, ...
    (comp.lang.basic.powerbasic)