Comprehending List Comprehensions - Thanks!

Peter Caven <>
Tue Nov 27 05:52:57 CET 2001


Many thanks to Uffe and Håkan!
I see now that I'll need to be careful about any strings returned from a
generator.

By the way - Erlang is a very nice language!
I get the same kind of liberated feeling with Erlang as I do when programing
in Python.

-- Peter.


----- Original Message -----
From: "Ulf Wiger" <>
To: "Peter Caven" <>
Cc: <>
Sent: Monday, November 26, 2001 7:28 AM
Subject: Re: Comprehending List Comprehensions


>
> The following comprehension is probably what you're after:
>
> [{string:substr("1+1-2", Start, Length}) ||
>   {Start, Length} <- [{1,1}, {2,2}, {4,2}]].
>
> In your example below, Token <- string:substr(...) generates
> Token from the string output by string:substr/2, essentially
> setting Token = <char>, for each character in the string.
>
> /Uffe
>
> On Mon, 26 Nov 2001, Peter Caven wrote:
>
> >Hello,
> >I am at the early stages of learning Erlang and I've encountered what
seems
> >to be strange behaviour in list comprehensions. The expression:
> >
> >[{Token} || {Start, Length} <- [{1,1},{2,2},{4,2}], Token <-
> >string:substr("1+1-2", Start, Length)]
> >
> >returns:
> >
> >[{49},{43},{49},{45},{50}]
> >
> >when I expected it to return:
> >
> >[{"1"},{"+1"},{"-2"}]
> >
> >Can someone please point out where my mistake is?
> >
> >Thanks,
> >Peter.
> >
> >
>
> --
> Ulf Wiger, Senior Specialist,
>    / / /   Architecture & Design of Carrier-Class Software
>   / / /    Strategic Product & System Management
>  / / /     Ericsson Telecom AB, ATM Multiservice Networks
>




More information about the erlang-questions mailing list