POV-Ray : Newsgroups : povray.general : declare a variable in a function : Re: declare a variable in a function Server Time
23 Jun 2021 00:26:48 EDT (-0400)
  Re: declare a variable in a function  
From: Tor Olav Kristensen
Date: 4 Apr 2021 19:45:00
Message: <web.606a4ed5db16780d6f19eb189db30a9@news.povray.org>
ingo <ing### [at] tagpovrayorg> wrote:
> in news:web.6067a28edb16780d6f19eb189db30a9@news.povray.org Tor Olav
> Kristensen wrote:
>
> > I'm sorry, but I have no recollection of such a feature.
>
> Maybe it was this "abuse" I was thinking of:
>
>
> #declare Ramp = function(Freq, Tick, SRate){
>   mod(Tick, SRate/Freq) * (Freq/SRate)
> }
>
> #declare TriOsc = function(Freq, Amp, Tick, SRate) {
>   #local TriSelect = function(R) {
>     select(
>       R - 0.25,
>       R,
>       select(
>         R - 0.75,
>         0.5 - R,
>         R - 1
>       )
>     )
>   };
>   4*Amp*TriSelect(Ramp(Freq,Tick,SRate))
> };
>
> It adds nothing but keeping the functions together in one block,

Well, that code added more than nothing for me:
It added a moment of confusion.

I would not recommend writing it like that. The most important reason is that it
could lead new POV-Ray users to believe that the variable that holds the
TriSelect function is local to the TriOsc function.

My understanding is that it is only local to the file that holds this code.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

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