POV-Ray : Newsgroups : povray.advanced-users : passing variable to macro for use in #for statement : Re: passing variable to macro for use in #for statement Server Time: 19 Jan 2019 04:56:35 GMT
  Re: passing variable to macro for use in #for statement  
From: clipka
Date: 20 Sep 2018 19:58:03
Am 20.09.2018 um 20:56 schrieb Kenneth:

>>     #macro FormatKeyword(Format)
>>       #if (Format = "png")
>>         png
>>       #elif (Format = "jpeg")
>>         jpeg
>>       ....
>>       #end
>>     #end

> A couple of questions/observations, though: The docs say two things at
> " The if...else...end Directives" (in v3.7.1 beta 9's help file--
> although I haven't yet checked the online wiki):
> "...an optional #elseif clause is now supported."

Whoops, my bad: It's `#elseif`. The construct isn't too uncommon in
programming languages, but the languages can't agree on whether it
should be `elseif`, `elsif` or `elif` (or a variation thereof as the
programming language's meta-structure permits, such as POV-Ray's `#elseif`).

Examples of Elseif-Languages:

- Ada
- Visual Basic

Examples of Elsif-Languages:

- Perl
- Ruby

Examples of Elif-Languages:

- C/C++ Preprocessor
- Python
- Unix shell scripts

> The even shorter keyword  #elif  (for #elseif) is not mentioned there (even
> though it works); and, its keyword 'color' in scsne code looks like a
> 'non'-keyword. Should both of those little errors be fixed?

Actually, no, it doesn't work: That's a mirage. If you examine it more
carefully, you'll find that the construct only behaves as expected if
both the `#if` condition and `#elif` conditionoid happen to be false;
because in that case the bogus `#elif` statement will simply be skipped.
If the `#if` condition happens to be true, the parser will parse the
`#if` branch and then crash right into the `#elif` like a brick wall,
and if the `#elif` conditionoid happens to be true, the parser will
still skip over it and enter the `#else` branch.

> More importantly, I've never had a problem using nested #if's (when including
> all of the #else keywords, anyway.) I *think* my macro is a good demonstration
> of what the docs mean by nested #ifs as explained there(?) So are the new
> keywords #elseif and #elif designed to eliminate any *possible* nested-#ifs
> problems (along with being 'shorthand' versions of such constructs)? Just
> curious.

Properly nested `#if` statements are not a problem. The problem
described in the docs specifically relates to nesting an `#if` in the
/condition/ of an enclosing `#if`.

Post a reply to this message

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