Re: E Style
Thomas Leonard <[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <[email protected]> |
On 5 December 2010 20:23, Bill Frantz <[email protected]> wrote: > In trying to write an E program (to actually do something useful > to me), I noted the apparent lack of the C construct: > > (bool ? true_value : false_value) > > What I have working now is: > > def location := ( if (filename =~ `@{x}Cave@{y}`) { 0 } > else if \ > (filename =~ `@{x}Frosty@{y}`) { 1 } > else if \ > (filename =~ `@{x}TTT@{y}`) { 2 } > else \ > { -1 }) > if (location == -1) {throw(`ERROR: Filename "$filename" > yields $location for offset`)} > > (The backslashes seem to be needed.) > > Is there a cleaner way to code this fragment? How about: def location := switch (filename) { match `@{x}Cave@{y}` { 0 } match `@{x}Frosty@{y}` { 1 } match `@{x}TTT@{y}` { 2 } match _ { throw(`ERROR: Filename "$filename" yields -1 for offset`) } } -- Dr Thomas Leonard http://0install.net/ GPG: 9242 9807 C985 3C07 44A6 8B9A AE07 8280 59A5 3CC1 GPG: DA98 25AE CAD0 8975 7CDA BD8E 0713 3F96 CA74 D8BA _______________________________________________ e-lang mailing list [email protected] http://www.eros-os.org/mailman/listinfo/e-lang