POV-Ray : Newsgroups : povray.advanced-users : ifdef() Server Time
28 Dec 2024 14:00:17 EST (-0500)
  ifdef() (Message 1 to 5 of 5)  
From: Jaap Frank
Subject: ifdef()
Date: 3 Mar 2004 11:32:31
Message: <4046089f$1@news.povray.org>
Hello,

I'm using the following construct for my code:

#declare A = array[2];
#declare B = array[2];

#declare B[0]=A;
#declare B[1]=A;
#declare B[0][0] = 18;

#ifdef (B[0][0])
 #debug "This is defined"
#end

If you use this the parser stops in the line #ifdef (B[0][0]) with the
cursor between [0] and [0] and says that it expects a closing bracket ')'.
(1)
There is no problem with assigning a value but testing is obviously not
possible.
You can circumvent this with:

#declare T=B[0];
#ifdef(T[0])
 #debug "This is defined"
#end

My question is why you can assign a value but can't test the existence of
the value in one step. Shouldn't it work as I was expecting?

Jaap Frank

PS  This is with the windows version 3.5.
       With 3.6 the cursor stops one character earlier.


Post a reply to this message

From: Marc Roth
Subject: Re: ifdef()
Date: 3 Mar 2004 11:48:38
Message: <40460c66@news.povray.org>
Jaap Frank wrote:

> Hello,
> 
> I'm using the following construct for my code:
> 
> #declare A = array[2];
> #declare B = array[2];
> 
> #declare B[0]=A;
> #declare B[1]=A;
> #declare B[0][0] = 18;

why don't you use a two-dimensional instead of asigning one array to the 
other?
#declare A = array[2][2];
this works well for me. but maybe i misunderstood you...
bye,
	Marc


Post a reply to this message

From: Jaap Frank
Subject: Re: ifdef()
Date: 3 Mar 2004 12:09:56
Message: <40461164@news.povray.org>
"Marc Roth" <mar### [at] rothconsultcom> wrote in message
news:40460c66@news.povray.org...
> Jaap Frank wrote:    [..]

> why don't you use a two-dimensional instead of asigning
> one array to the other?
> #declare A = array[2][2];
> this works well for me. but maybe i misunderstood you...
> bye,
> Marc

I've simplified the problem to show what I mean, but in reality my arrays
are build that way in order to be able to transfer parts of my arrays to a
macro that uses only a part of the total array. Like #declare T=B[0];   in
my example.
I've to test if the array value already exists to prefent
dubbel calculations.

This is by the way the method to put different kind of variables in one
array, so you can pass lots of different things in one array to a macro:
#declare A = array[2] { 2.05, 3.0058}
#declare B = array[2] { <1,2,3>, <4,5,6>}
#declare C = array[2]
#declare C[0] = A;
#declare C[1] = B;

#declare F =C[0][1]   // Is a float
#declare V = C[1][0]  // Is a vector

Thanks for your reaction,

Jaap Frank


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: ifdef()
Date: 3 Mar 2004 12:19:44
Message: <404613b0@news.povray.org>
In article <4046089f$1@news.povray.org> , "Jaap Frank" <jjf### [at] xs4allnl> 
wrote:

> There is no problem with assigning a value but testing is obviously not
> possible.

You cannot test if an array element is defined, that does not make sense at
because the array is either defined or not, independent of the elements.
The manual at no point claims what you want to do would be possible.  If you
want to know if a specific element exists, you should use the array size,
and simply not add elements that do not contain the information you do not
want to store in the first place.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Jaap Frank
Subject: Re: ifdef()
Date: 3 Mar 2004 13:04:47
Message: <40461e3f@news.povray.org>
"Thorsten Froehlich" <tho### [at] trfde> wrote in message
news:404613b0@news.povray.org...
> In article <4046089f$1@news.povray.org> , "Jaap Frank" <jjf### [at] xs4allnl>
> wrote:
>
> > There is no problem with assigning a value but testing is obviously not
> > possible.
>
> You cannot test if an array element is defined, that does not make sense
at
> because the array is either defined or not, independent of the elements.
> The manual at no point claims what you want to do would be possible.  If
you
> want to know if a specific element exists, you should use the array size,
> and simply not add elements that do not contain the information you do not
> want to store in the first place.
>
>     Thorsten

Thorsten, I'm sorry for talking about defining, I ment assigning:

| From the manual:
|
| The #ifdef and #ifndef directives can be used to determine whether
| a specific element of an array has been assigned.
|
| #declare MyArray=array[10]
| //#declare MyArray[0]=7;
| #ifdef(MyArray[0])
|    #debug "first element is assigned\n"
| #else
|    #debug "first element is not assigned\n"
|  #end

You can assign an value in one step in my example, but you can't test
in one step if a value is assigned.
Is it wrong to expect that the test could be done in one step?
(By the way, I can't follow your last sentence, it contains to
many negations, but I think you mean something like you can't test
something that's not existing.)

Jaap Frank


Post a reply to this message

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