POV-Ray : Newsgroups : povray.newusers : Using conditional expression in functions. How to write step functions? : Re: Using conditional expression in functions. How to write step functions? Server Time
8 Jul 2024 00:16:36 EDT (-0400)
  Re: Using conditional expression in functions. How to write step functions?  
From: Warp
Date: 18 Dec 2009 11:41:06
Message: <4b2bb0a2@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.