POV-Ray : Newsgroups : povray.programming : Overloading identifiers : Overloading identifiers Server Time
29 Jul 2024 00:23:54 EDT (-0400)
  Overloading identifiers  
From: Nieminen Mika
Date: 28 Jan 1999 08:49:18
Message: <36b06ade.0@news.povray.org>
I have an idea:

  In C++ you can overload functions, ie. you can specify functions with
same names but different kind or amount of arguments. For example:

int Abs(int n);
double Abs(double x);

  If you now call the function Abs() with an integer argument, it will call
the first function, while if you call it with a double argument it will call
the second.
  Why not apply this same idea to povray?
  Suppose you have, for example:

#declare Gold=<.8,.5,.2>;
#declare Gold=
  pigment
  { color Gold
  }
#declare Gold=
  texture
  { pigment { Gold }
    finish { Metal }
  }
#declare Gold=
  interior
  { (whatever would the interior of a golden object look like...)
  }
#declare Gold=
  material
  { texture { Gold }
    interior { Gold }
  }


  Now you would use 'Gold' anywhere in a material statement and it will work.
For example, if you want a gold-colored object, you would just type:

object { MyObject pigment { Gold } }

  If you want the same object as really golden:

object { MyObject texture { Gold } }

  (this would add also the metallic finish)
  Supposing that gold would be transparent, ie. it has an interior, then
you would type:

object { MyObject material { Gold } }

  If you want a gold-colored light source you would type:

light_source { <a,b,c> color Gold }


  Of course overloading #macros would be even more interesting and handy.

  I think this kind of addition will make no harm to the current version
since this is a fully backwards compatible system.
  What do you think?
  Are there any places where you can put an identifier and where it isn't
unambiguous which kind of identifier it is?

-- 
main(i){char*_="BdsyFBThhHFBThhHFRz]NFTITQF|DJIFHQhhF";while(i=
*_++)for(;i>1;printf("%s",i-70?i&1?"[]":" ":(i=0,"\n")),i/=2);} /*- Warp. -*/


Post a reply to this message

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