Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  List questions

mikl at linux-france.org
Posted: Thu Sep 09, 1999 8:44 pm Reply with quote
Guest
I was very surprised with the result of the following commands :

19> [40].
"("
20> [45].
"-"
21> [60].
"<"
22> [80].
"P"


In fact, the result is displayed as a character corresponding to the
ascii code in the list.

This is quite surprising at first. In a complex command I search for a
bug because the function was not supposed to return strings.

I guess this has no consequence on the program logic, but you must be
very careful to avoid be trapped by what you see.


Have funs->

--
Mickael Remond
mikl_at_linux-france.org
ICQ : 2265396


Post generated using Mail2Forum (http://m2f.sourceforge.net)
crd at inversenet.com
Posted: Thu Sep 09, 1999 9:14 pm Reply with quote
Guest
Since Erlang has no separate type for text characters, a text string is just
a list of integers. Because of this, it has no sure way of knowing whether
any arbitrary list of integers is meant to be a text string, so when
displaying them, it guesses. Your lists below are composed entirely of
integers that correspond to printable ASCII characters, so it figures they
might be meant to be strings, and displays them as such. (The actual
criterion may be a bit different; I haven't looked at the code. But I
believe that's the basic idea.)

Craig

----- Original Message -----
From: Mickael Remond <mikl_at_linux-france.org>
To: <erlang-questions_at_erlang.org>
Sent: Thursday, 9 September 1999 10:35 pm
Subject: List questions


>
> I was very surprised with the result of the following commands :
>
> 19> [40].
> "("
> 20> [45].
> "-"
> 21> [60].
> "<"
> 22> [80].
> "P"
>
>
> In fact, the result is displayed as a character corresponding to the
> ascii code in the list.
>
> This is quite surprising at first. In a complex command I search for a
> bug because the function was not supposed to return strings.
>
> I guess this has no consequence on the program logic, but you must be
> very careful to avoid be trapped by what you see.
>
>
> Have funs->
>
> --
> Mickael Remond
> mikl_at_linux-france.org
> ICQ : 2265396
>



Post generated using Mail2Forum (http://m2f.sourceforge.net)
patrickdlogan at home.com
Posted: Thu Sep 09, 1999 9:19 pm Reply with quote
Guest
Mickael Remond writes:
>
> I was very surprised with the result of the following commands :
>
> 19> [40].
> "("
> 20> [45].
> "-"
> 21> [60].
> "<"
> 22> [80].
> "P"

Those of us raised on late night TV in America in the 1970s will
simply quote:

"It's a dessert topping *and* a floor wax!"

What this means for Erlang is a list of ASCII integers is a list of
numbers *and* a string!

Now where did I put my Bass-O-Matic?

--
Patrick Logan patrickdlogan_at_home.com


Post generated using Mail2Forum (http://m2f.sourceforge.net)
tobbe at serc.rmit.edu.au
Posted: Thu Sep 09, 1999 9:47 pm Reply with quote
Guest
> I was very surprised with the result of the following commands :
>
> 19> [40].
> "("

For many years we had the following behaviour in the shell:

19> "(".
[40]

Until we got fed up with it. So nowadays the shell tries to
be nice and do it for you whenever possible.

Cheers /Tobbe
--
Torbj
klacke at bluetail.com
Posted: Fri Sep 10, 1999 7:52 am Reply with quote
Guest
> Those of us raised on late night TV in America in the 1970s will
> simply quote:
>
> "It's a dessert topping *and* a floor wax!"
>

Uhhh... we're all lost in Europe, I can imagine a
disgusting commercial though.

As for the:

> > 19> [40].
> > "("

behaviour, I'd say it's almost a bug, and it should be fixed.

The proper solution is to subtag integers as characters
(that is: to introduce a builtin char type) which has
the characteristics of an integer except that a new
guard test like:

f(C) when char(C) ->

returns true for chars but not for ints, and

$X + 2.

should also return a char .... and so on.


I think the OTP folks are/have been doing something like this ????


In an old implementation of Erlang where Tony Rogvall and
I were experimenting with something we called the "bitsyntax"

(briefly described at: http://www.bluetail.com/klacke/binaries.ps)

we implemented a scheme with subtaggged integers, it never made it into
any releases though. This was done in "rage" by Tony since he
got fed up with the weird printouts from the shell.


Cheers

/klacke








Post generated using Mail2Forum (http://m2f.sourceforge.net)
rv at bluetail.com
Posted: Fri Sep 10, 1999 8:22 am Reply with quote
Guest
Klacke <klacke_at_bluetail.com> writes:
> > Those of us raised on late night TV in America in the 1970s will
> > simply quote:
> >
> > "It's a dessert topping *and* a floor wax!"
>
>Uhhh... we're all lost in Europe, I can imagine a
>disgusting commercial though.
>
>As for the:
>
> > > 19> [40].
> > > "("
>
>behaviour, I'd say it's almost a bug, and it should be fixed.
>
>The proper solution is to subtag integers as characters
>(that is: to introduce a builtin char type) which has
>the characteristics of an integer except that a new
>guard test like:
>
>f(C) when char(C) ->
>
>returns true for chars but not for ints, and
>
>$X + 2.
>
>should also return a char .... and so on.
>
>
>I think the OTP folks are/have been doing something like this ????

This has been discussed many times and made it into Standard Erlang
(which only exists as a spec). There were plans how characters could
be introduced into OTP and still be backwards compatible (this is as
trivial as it sounds). I don't know if it is still in the pipe-line.

The current solution in which the shell prints lists of integers as
strings if the values are within range is definitely not perfect but
probably better than always printing them as lists.

For those who are interested the actual work is done in io_lib:fwrite
with the ~p and ~P options. RTFM.

Robert




Post generated using Mail2Forum (http://m2f.sourceforge.net)

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum