|
|
Evgenij Gagauz <nomail@nomail> wrote:
> Is there a way to use an conditional expression in function?
> For example, how can I write something like that (the code isn't compilable):
> #local =
> function(a) {
> #if (a < .1)
> 1
> #else
> 0
> #end
> }
> The compiler says that it doesn't know anything about "a".
Because 'a' is not a declared identifier. (Function parameters have nothing
to do with declared identifiers and are invisible to any # commands.)
> Ok, the "#if" condition is calculated only once, but function will be calculated
> many times. I try to rewrite the function:
> #local =
> function(a) {
> (a < .1) ? 1 : 0
> }
The ?: syntax is not supported by user-defined functions.
> Shall I use the "select" function?
That's what it was created for.
> Unfortunatly I can't see a good way for modelling function like this:
> ___----_-__- with the "select" function.
If you can express it with ?:, you can express it with select().
--
- Warp
Post a reply to this message
|
|