POV-Ray : Newsgroups : povray.pov4.discussion.general : A Feature of Possible Use Server Time
21 Nov 2024 15:12:35 EST (-0500)
  A Feature of Possible Use (Message 1 to 4 of 4)  
From: John VanSickle
Subject: A Feature of Possible Use
Date: 21 Apr 2009 07:55:00
Message: <49edb414$1@news.povray.org>
Pardon me if this has already been suggested.

Most macro writers could make the idiot-proofing of their macros much 
more thorough by having a feature by which it is possible to test an 
argument passed to the macro to determine if it is of the expected type.

Not only can this be used to give better feedback in an error message, 
macro writers could also use it to make a macro more flexible for the 
end user.

Here's one I though up just now:

#macro FunHouse(Paint)
   #if(type(Paint)="texture")
     #local txtPaint=Paint;
   #else_if(type(Paint)="pigment") // yeah, the SDL could use an
                                     // else-if statement, if it
                                     // doesn't already have one
     #local txtPaint=texture { pigment { Paint } }
   #else
     #debug "Invalid object passed as Paint parameter to FunHouse().\n"
     #local txtPaint=texture { }
   #end
   union {
      /// several objects here to make a fun house
      texture { txtPaint }
   }
#end

I suggest passing a string back only because it's more human-readable 
for comparisons, and more easily allows for future expansion of the 
feature (such as stating whether the object is an array of something, or 
just a something).

Regards,
John


Post a reply to this message

From: Reactor
Subject: Re: A Feature of Possible Use
Date: 21 Apr 2009 14:30:00
Message: <web.49ee0ffd811cc9b481734cd40@news.povray.org>
John VanSickle <evi### [at] hotmailcom> wrote:
> Pardon me if this has already been suggested.
>
> Most macro writers could make the idiot-proofing of their macros much
> more thorough by having a feature by which it is possible to test an
> argument passed to the macro to determine if it is of the expected type.
>
> Not only can this be used to give better feedback in an error message,
> macro writers could also use it to make a macro more flexible for the
> end user.
>
> Here's one I though up just now:
>
> #macro FunHouse(Paint)
>    #if(type(Paint)="texture")
>      #local txtPaint=Paint;
>    #else_if(type(Paint)="pigment") // yeah, the SDL could use an
>                                      // else-if statement, if it
>                                      // doesn't already have one
>      #local txtPaint=texture { pigment { Paint } }
>    #else
>      #debug "Invalid object passed as Paint parameter to FunHouse().\n"
>      #local txtPaint=texture { }
>    #end
>    union {
>       /// several objects here to make a fun house
>       texture { txtPaint }
>    }
> #end
>
> I suggest passing a string back only because it's more human-readable
> for comparisons, and more easily allows for future expansion of the
> feature (such as stating whether the object is an array of something, or
> just a something).
>
> Regards,
> John

Agreed, but I think the type() operator should return a string of the objects
type, in which case you'd have to use string compare.  Being able to determine
the type could also be handy for permitting greater flexibility in macros and
text file reading and writing operations.


-Reactor


Post a reply to this message

From: clipka
Subject: Re: A Feature of Possible Use
Date: 21 Apr 2009 18:25:00
Message: <web.49ee4713811cc9b4c3ad972c0@news.povray.org>
John VanSickle <evi### [at] hotmailcom> wrote:
> Pardon me if this has already been suggested.

The idea is indeed not new: Something along these lines is implemented in
MegaPOV. Unfortunately, it doesn't seem to be on the agenda for regular POV
3.7.

I'd consider this a good thing to have in a POV 4 SDL, at any rate.

>    #else_if(type(Paint)="pigment") // yeah, the SDL could use an
>                                      // else-if statement, if it
>                                      // doesn't already have one

POV 3.6 SDL doesn't, but I consider it an essential of any well-designed syntax
to allow for something like an else-if - whether implicitly due to the overall
language design (like C for instance) or explicitly due to a dedicated
statement (like C's preprocessor language).


Post a reply to this message

From: ingo
Subject: Re: A Feature of Possible Use
Date: 24 Apr 2009 15:12:00
Message: <Xns9BF7D7A3B8D0seed7@news.povray.org>
in news:49edb414$1@news.povray.org John VanSickle wrote:

> Pardon me if this has already been suggested.
> 
> Most macro writers could make the idiot-proofing of their macros much
> more thorough by having a feature by which it is possible to test an 
> argument passed to the macro to determine if it is of the expected
> type. 


http://docs.python.org/tutorial/errors.html#handling-exceptions

Ingo


Post a reply to this message

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