[erlang-questions] Erlang case statement questions

Keith Irwin keith.irwin@REDACTED
Tue Jun 2 00:12:23 CEST 2009


Actually, you don't need PQ at all. You can just return the value of the
case expression itself.
K

On Mon, Jun 1, 2009 at 3:11 PM, Keith Irwin <keith.irwin@REDACTED> wrote:

> Also, PQ is thrown away after the end if the statement.
> Maybe:
>
> analyze(N) ->
>   PQ = case (N rem 9) of
>               1 -> [{1,1}, {2,5}, {4,7}, {8,8}]
>               % etc, etc
>            end,
>   do_something_with(PQ).
>
>
> On Mon, Jun 1, 2009 at 12:05 PM, Tony Rogvall <tony@REDACTED> wrote:
>
>> Also.  9 rem 9 = 0!
>> So I guess your cases should be from 0 to 8 or something similar.
>>
>> /Tony
>>
>>
>> On 1 jun 2009, at 19.51, Nahuel Greco wrote:
>>
>>  End the last clause without the semicolon.
>>>
>>> Saludos,
>>> Nahuel Greco.
>>>
>>>
>>>
>>> On Mon, Jun 1, 2009 at 2:48 PM, Greg Perry <Greg.Perry@REDACTED>
>>> wrote:
>>>
>>>> Ok I've put together a simple module declaration but I am getting an
>>>> error on this case statement.  What am I doing wrong with this?  N is an
>>>> integer that gets passed to the module, based upon the return of N rem
>>>> 9, PQ then gets assigned the list of items on the right:
>>>>
>>>> ----------
>>>>
>>>> analyze(N) ->
>>>>  case (N rem 9) of
>>>>     1 -> PQ = [{1,1}, {2,5}, {4,7}, {8,8}];
>>>>     2 -> PQ = [{1,2}, {4,5}, {7,8}];
>>>>     3 -> PQ = [{1,3}, {2,6}, {3,4}, {3,7}, {5,6}, {6,8}];
>>>>     4 -> PQ = [{1,4}, {2,2}, {5,8}, {7,7}];
>>>>     5 -> PQ = [{1,5}, {2,7}, {4,8}];
>>>>     6 -> PQ = [{1,6}, {2,3}, {3,5}, {3,8}, {4,6}, {6,7}];
>>>>     7 -> PQ = [{1,7}, {2,8}, {4,4}, {5,5}];
>>>>     8 -> PQ = [{1,8}, {2,4}, {5,7}];
>>>>     9 -> PQ = [{1,9}, {2,9}, {3,3}, {3,6}, {3,9}, {4,9}, {5,9}, {6,6},
>>>> {6,9}, {7,9}, {8,9}, {9,9}];
>>>>  end.
>>>>
>>>> ----------
>>>>
>>>> I used the example in Joe's Programming Erlang book for the case
>>>> statement, but got something wrong obviously.
>>>>
>>>> Thanks in advance,
>>>>
>>>> Greg
>>>>
>>>>
>>>>
>>>>
>>>> ________________________________________________________________
>>>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>>>> erlang-questions (at) erlang.org
>>>>
>>>>
>>> ________________________________________________________________
>>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>>> erlang-questions (at) erlang.org
>>>
>>>
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>>
>


More information about the erlang-questions mailing list