[erlang-questions] Idiom for multiple case matches
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
Mon Nov 10 20:34:59 CET 2008
David Mercer skrev:
> Actually, using Ulf's ct_expand parse transform, the results on the set look
> much better:
>
> 1000000 Iterations
> Virding: Run-Time/Wall-Clock: 94/94 milliseconds
> Cronqvist: Run-Time/Wall-Clock: 141/140 milliseconds
> Mercer: Run-Time/Wall-Clock: 843/844 milliseconds
>
> That's a 17x speed-up!
Of course, it's still pretty slow for this particular
problem, but hopefully people are able to extrapolate. (:
>
> However, now I get a compile warning:
>
> ./test.erl:0: Warning: variable 'V42' is unused
>
> I don't know enough about parse transforms to debug. Is there any
> documentation on creating them?
Not much, but it's fairly simple at one level.
Mod:parse_transform(Forms, Options) -> NewForms
The module in question makes use of syntax_tools, which is
documented.
To get rid of the warning, perhaps the simplest way ought to
be to replace the call on lines 141-143:
VarNames = erl_syntax_lib:new_variable_names(
Arity,
erl_syntax_lib:variables(Form)),
to
VarNames = erl_syntax_lib:new_variable_names(
Arity,
fun(I) ->
list_to_atom(
lists:concat(
["__", ?MODULE_STRING,
integer_to_list(I)]))
end,
erl_syntax_lib:variables(Form)),
...or something like that. I haven't tested it.
BR,
Ulf W
>
> DBM
>
>> -----Original Message-----
>> From: Ulf Wiger (TN/EAB) [mailto:ulf.wiger@REDACTED]
>> Sent: Monday, November 10, 2008 12:30
>> To: dmercer@REDACTED
>> Cc: 'Erlang Questions'
>> Subject: Re: [erlang-questions] Idiom for multiple case matches
>>
>>
>> So try it with the absolutely wonderful and indispensable
>> parse transform utility ct_expand. ;-)
>>
>> http://forum.trapexit.org/viewtopic.php?p=20260#20260
>>
>>
>> BR,
>> Ulf W
>>
>>
>> David Mercer skrev:
>>> For completeness, I did run some benchmarking. I hesitate to put my
>> name to
>>> my solution, since it was suggested in jest, but I am vindicated because
>> it
>>> performed as expected:
>>>
>>> 1,000,000 Iterations:
>>> Virding: Run-Time/Wall-Clock: 94/94 milliseconds
>>> Cronqvist: Run-Time/Wall-Clock: 141/141 milliseconds
>>> Mercer: Run-Time/Wall-Clock: 14547/14547 milliseconds
>>>
>>> Cheers,
>>>
>>> David
>>>
>>>> -----Original Message-----
>>>> From: David Mercer [mailto:dmercer@REDACTED]
>>>> Sent: Monday, November 10, 2008 11:05
>>>> To: 'mats cronqvist'; 'Michael Radford'
>>>> Cc: 'Hynek Vychodil'; 'Erlang Questions'
>>>> Subject: RE: [erlang-questions] Idiom for multiple case matches
>>>>
>>>> Since this is, semantically, a set operation, should we not perhaps use
>>>> sets:is_element/2 instead? Something like:
>>>>
>>>> vowels() -> sets:from_list("aeiou").
>>>> is_vowel(C) -> sets:is_element(C, vowels()).
>>>>
>>>> Just kidding, of course... (Obvious efficiency issues.) :-)
>>>>
>>>> DBM
>>>>
>>>> P.S. No, Mats, I did not benchmark this. :-)
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list