POV-Ray : Newsgroups : povray.general : POV crash with functions : Re: POV crash with functions Server Time
4 Aug 2024 02:17:47 EDT (-0400)
  Re: POV crash with functions  
From: Thorsten Froehlich
Date: 11 Nov 2003 13:38:52
Message: <3fb12cbc$1@news.povray.org>
In article <edn### [at] tritonimagicode> , Christoph Hormann 
<chr### [at] gmxde>  wrote:

>> This isn't legal syntax and POV-Ray cannot currently detect this properly.
>
> Isn't there a possibility to prevent the crash?

Not without making macros aware of what they are returning.

Actually, thinking about this again, I think the following should work as
well (sorry, I cannot test it right now):

#macro F_Plane ()
    #local fn_p=function (x,y,z) { y };
    fn_p;
#end

The reason I suspect this might work is because it practically completes the
copy assignment prior to leaving the macro.  Thus, the parser is no longer
waiting to be able to figure out if the above is a copy or a evaluation.

>> To do what you want, use #declare instead of #local like this:
>>
>> #macro F_Plane ()
>>    #undef fn_p
>>    #declare fn_p=function (x,y,z) { y };
>>    fn_p
>> #end
>
> Note this is an undocumented feature.  In fact function declarations are
> not listed in the #declare documentation at all:

True.  And it shouldn't be documented for now as I am not sure if it should
be allowed or not.  Macros should only return "complete" unambiguous
statements.  The workaround only works because a #declared function isn't
destroyed after leaving the macro like a #local function.  The parser cannot
detect either case, but as it doesn't destroy the #declared function when
leaving the macro, the code works as expected.  I suppose even doing
    #local F1= F_Plane()(1,2,3);
would work in this case.  I really don't want to endorse this syntax, and I
won't promise future versions of POV-Ray will still allow it.  So if my
suggestion with the semicolon does work, that would be the recommended way
of handling this.

    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

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