POV-Ray : Newsgroups : povray.documentation.inbuilt : Mysterious function argument : Mysterious function argument Server Time
5 Dec 2021 14:33:30 EST (-0500)
  Mysterious function argument  
From: Cousin Ricky
Date: 30 Sep 2021 09:39:42
Message: <6155be1e$1@news.povray.org>
The reference manual (section 3.3.1.8.3, or 2.3.1.8.3 in the wiki) gives
the following as a legal function definition:

  #declare foo3 = function(k1, k2, z, y) { x + y * z + k1 * y + k2 }

The function body refers to x, even though x is not one of the declared
arguments.  But the function still works, somehow.  The following scene

----------[BEGIN SCENE]----------
#version max (3.5, min (3.8, version));
global_settings { assumed_gamma 1 }
#declare foo3 = function(k1, k2, z, y) { x + y * z + k1 * y + k2 }
#declare G = foo3 (1, 2, 3, 4);
#debug concat ("G = ", str (G, 0, 1), "\n")
-----------[END SCENE]-----------

yields the output:

G = 18.0

Manually working through the function yields
  x + y * z + k1 * y + k2
= x + 4 * 3 + 1 * 4 + 2
= x + 12 + 4 + 2
= x + 18

This suggests that POV-Ray pre-assigned 0 to x.  That this construction
is given as an example suggests that this is a significant feature
(however inadvisable to use), and not just a parser glitch.  Shouldn't
there be some explanation of this feature?


Post a reply to this message

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