POV-Ray

The Persistence of Vision Raytracer (POV-Ray).

This is the legacy Bug Tracking System for the POV-Ray project. Bugs listed here are being migrated to our github issue tracker. Please refer to that for new reports or updates to existing ones on this system.

Attached to Project: POV-Ray
Opened by Mike H - 2010-06-09
Last edited by William F Pokorny - 2016-11-28

FS#124 - variable number of parameters in macros

Many programming languages support an indeterminate number of parameters in functions/macros.

JavaScript for instance supports an “arguments” object.

Lua for instance supports the “args” object.

I would like to see that added to POV as well.

Here’s an JavaScript example:

function ArgTest(a, b){
   var i, s = "The ArgTest function expected ";
   var numargs = arguments.length;     //Get number of arguments passed.
   var expargs = ArgTest.length;       //Get number of arguments expected.
   if (expargs < 2)
      s += expargs + " argument. ";
   else
      s += expargs + " arguments. ";
   if (numargs < 2)
      s += numargs + " was passed.";
   else
      s += numargs + " were passed.";
   s += "\n\n"
   for (i =0 ; i < numargs; i++){      //Get argument contents.
   s += "  Arg " + i + " = " + arguments[i] + "\n";
   }
   return(s);                          //Return list of arguments.
}
Closed by  William F Pokorny
Monday, 28 November 2016, 12:32 GMT
Reason for closing:  Implemented
Additional comments about closing:  

Available in 3.7.1 master branch since commit a572730 was Christoph Lipka, Wed Jun 24 15:18:28 2015 +0200, message: Implement mechanisms to allow omission of macro parameters.

Also documented in:

http://wiki.povray.org/content/ Reference:User_Defined_Macros#Optional_P arameters

Grimbert Jérôme commented on Thursday, 10 June 2010, 12:11 GMT

Macros never allow variable number of argument (but you might get some macro with 1,2,3.... arguments, as long as you define all versions and the macro processor supports them as different). (they all get inspiration from cpp)

Functions with variable number of parameter... use an array instead! (with or w/o the min & max indexes to use)

Admin
Christoph Lipka commented on Friday, 18 June 2010, 20:35 GMT

renamed the task

Admin
Christoph Lipka commented on Friday, 18 June 2010, 20:39 GMT

I think rather than implement support for an indeterminate number of macro parameters, it would be more helpful to allow for optional macro parameters. (It could neatly fit into the existing POV-Ray syntax using the "#if (defined(...))" construct.)

Mike H commented on Sunday, 20 June 2010, 00:13 GMT

What's the difference between "indeterminate" and "optional"? Also, having to check for each parameter by hand is a lot of tedious extra work. Other languages already have a more streamlined and natural way of doing this.

Thorsten Fröhlich commented on Sunday, 20 June 2010, 08:01 GMT

You are confusing macros with functions. They are expanded in place, which is different from a function.

Mike H commented on Sunday, 20 June 2010, 08:25 GMT

I'm not confusing macros with functions. You just think I'm confusing macros with functions. I'm asking that macros have the ability to have optional parameters. Nowhere did I mention functions.

Thorsten Fröhlich commented on Friday, 25 June 2010, 19:39 GMT

The suggestion made by Christoph Lipka seems good and well suited for macros. However, i think it is way to late in the 3.7 release cycle to modify the parser. Changes there tend to produce unwanted side effects that are extremely hard to track down.

Mike H commented on Friday, 25 June 2010, 21:54 GMT

"Macros never allow variable number of argument (but you might get some macro with 1,2,3.... arguments, as long as you define all versions and the macro processor supports them as different)."

Manually overloading the macros you mean.

Loading...

Available keyboard shortcuts

Tasklist

Task Details

Task Editing