POV-Ray : Newsgroups : povray.general : Github repository with useful macros : Re: Github repository with useful macros Server Time
4 May 2024 03:23:30 EDT (-0400)
  Re: Github repository with useful macros  
From: jr
Date: 22 May 2021 12:15:00
Message: <web.60a92d96985098ff79819d986cde94f1@news.povray.org>
hi,

William F Pokorny <ano### [at] anonymousorg> wrote:
> ...
> Note. In v3.8 with optional macro parameters, parameter names can
> collide. This an additional reason I'm chasing the no (a-z,0-9,_)
> identifiers checking in the povr branch.
>
> //---
> #version 3.8;
>
> #local Filename = "File99"
>
> #macro Mcr00(_string, optional Filename)
>    //#ifndef(local.Filename)
>      #ifndef(Filename)
>          #local Filename = "File00";
>      #end
>      #debug concat("00 File name: ",Filename," String: ",_string,"\n")
> #end
>
> #macro Mcr01(_string, optional _filename)
>    //#ifndef(local._filename)
>      #ifndef(_filename)
>          #local Filename = "File01";
>      #else
>          #local Filename = _filename;
>      #end
>      #debug concat("01 File name: ",Filename," String: ",_string,"\n")
> #end
>
> Mcr00("abc",Filename)
> Mcr01("abc",Filename)
>
> Mcr00("xyz",Wildname) // oops
> Mcr01("xyz",Wildname)
>
> #error "Stop early"
> //---

may be I'm too dense, but what goes wrong at 'oops'?  since 'Mcr00' only looks
for 'Filename', which exists, it'll use that.  and 'Wildname' isn't defined, so
'Mcr01' also appear (to me) to do the correct thing.  did I misread yr point?

I changed the code to use 'local' as I would, and see nothing .. unexpected in
the output.


regards, jr.


jr@swift:1:20210522$ c### [at] t5pov
#version 3.8;

global_settings {assumed_gamma 1}
box {0,1}

#local Filename = "File99"

#macro Mcr00(_string, optional _filename)
  #ifndef(local._filename)
    #local _filename = "File00";
  #end
  #debug concat("00 File name: ",_filename," String: ",_string,"\n")
#end

#macro Mcr01(_string, optional _filename)
  #ifndef(local._filename)
    #local _filename = "File01";
  #end
  #debug concat("01 File name: ",_filename," String: ",_string,"\n")
#end

Mcr00("abc",Filename)
Mcr01("abc",Filename)

Mcr00("lmn",)
Mcr01("lmn",)

Mcr00("xyz",bad_name)
Mcr01("xyz",bad_name)

#error "Stop early"


jr@swift:2:20210522$ povparse t5.pov
Persistence of Vision(tm) Ray Tracer Version 3.8.0-alpha.10064268.unofficial
  ...
==== [Parsing...] ==========================================================
00 File name: File99 String: abc
01 File name: File99 String: abc
00 File name: File00 String: lmn
01 File name: File01 String: lmn
00 File name: File00 String: xyz
01 File name: File01 String: xyz
File 't5.pov' line 31: Parse Error: Parse halted by #error directive: Stop early


Post a reply to this message

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