[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Select (Switch) Case statement
- From: Mark Hamburg <mhamburg@...>
- Date: Wed, 01 Sep 2004 10:34:24 -0700
That's seriously twisted. But pretty cool.
Mark
on 9/1/04 10:27 AM, Michael Roth at mroth@nessie.de wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello all,
>
> 10 programmers result in 20 solution... That's my suggestion:
>
> function switch(actual)
> local found = false
> local case = function(expected)
> if expected == actual then
> found = true
> return true
> end
> end
> local default = function()
> return not found
> end
> return case, default
> end
>
> Usage:
>
> for i = 1, 4 do
> local case, default = switch(i)
>
> if case(2) then
> print("two")
> end
>
> if case(3) then
> print("three")
> end
>
> if default() then
> print("default:", i)
> end
> end