POV-Ray : Newsgroups : povray.pov4.discussion.general : Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0) Server Time
12 Oct 2024 08:01:55 EDT (-0400)
  Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0) (Message 1 to 10 of 25)  
Goto Latest 10 Messages Next 10 Messages >>>
From: William F Pokorny
Subject: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 27 Jun 2024 11:44:27
Message: <667d88db$1@news.povray.org>
Release R15 of the yuqk fork has an implementation supporting constant 
identifiers / macro parameters. They are indicated by using a leading 
'_' character in the name.

Aside: I have hopes this mechanism a step toward enabling the safe 
passing of function pointers into yuqk's inbuilt functions.

Attached a first pass at a little documentation for the feature.

Bill P.


Post a reply to this message


Attachments:
Download 'underscorereadonlyidentifiers.txt' (3 KB)

From: Bald Eagle
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 27 Jun 2024 12:05:00
Message: <web.667d8d8f4bc5dc757b170db125979125@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
> Release R15 of the yuqk fork has an implementation supporting constant
> identifiers / macro parameters. They are indicated by using a leading
> '_' character in the name.
>
> Aside: I have hopes this mechanism a step toward enabling the safe
> passing of function pointers into yuqk's inbuilt functions.
>
> Attached a first pass at a little documentation for the feature.
>
> Bill P.

Very nice - I hope that works out the way you/we/everyone would like.

"Parse Error:
Attempt to #undef a constant identifier.
The identifier is:
    '_V99'
Due the leading '_' the existing identifier can only be read.
Fatal error in parser: Cannot parse input."

Is that a scene-wide global thing?
Due to some need to actually undefine or redefine a variable, maybe the leading
underscore could be a safeguard, rather than a complete lockout.

Maybe have some mechanism by which you can do the equivalent of su in a shell to
override the protections set in place to prevent casual/inadvertent overwriting.

Only saying this because it might make some things pretty awkward to code from
scratch / covert from legacy scenes into yuqk.

I dunno - maybe doing scene development you might want to have the safeguard in
place for the main scene, but during experimentation you want to turn off the
protection, but not scene-wide, only in the little test block of code that
you're fiddling with.

Just a thought.


Post a reply to this message

From: ingo
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 27 Jun 2024 12:50:00
Message: <web.667d975d4bc5dc7517bac71e8ffb8ce3@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
> Release R15 of the yuqk fork has an implementation supporting constant
> identifiers / macro parameters. They are indicated by using a leading
> '_' character in the name.
>
> Aside: I have hopes this mechanism a step toward enabling the safe
> passing of function pointers into yuqk's inbuilt functions.
>
> Attached a first pass at a little documentation for the feature.

There are quite a lot of include files out there that use a starting underscore
to prevent name space collisions. Many of these variables are also variable and
not 'static/constant'. Would that break scene's and includes?


(Would, for example a '#let' keyword for immutables be an option, or is that an
awful lot more work.)

ingo


Post a reply to this message

From: jr
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 27 Jun 2024 13:30:00
Message: <web.667da1134bc5dc75c7a7971d6cde94f1@news.povray.org>
hi,

William F Pokorny <ano### [at] anonymousorg> wrote:
> Release R15 of the yuqk fork has an implementation supporting constant
> identifiers / macro parameters. They are indicated by using a leading
> '_' character in the name.

agree with ingo, a keyword would be "cleaner".  we already can write:

  #macro foo(optional a)  ...  #end

suggest a 'const' or such ?  ie

  #macro foo(a, const b, optional c)  ...  #end


regards, jr.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 27 Jun 2024 18:47:55
Message: <667dec1b$1@news.povray.org>
On 2024-06-27 11:44 (-4), William F Pokorny wrote:
> Release R15 of the yuqk fork has an implementation supporting constant
> identifiers / macro parameters. They are indicated by using a leading
> '_' character in the name.

I also agree with Ingo: a keyword or directive would be better, such as:

  #const MagicNumber = 12345;

I'm thinking a keyword modifier would be more flexible than a directive,
for example:

  #declare const GlobalVal = 12345;
  #local const LocalVal = 54321;


Post a reply to this message

From: Bald Eagle
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 27 Jun 2024 19:25:00
Message: <web.667df4b64bc5dc751f9dae3025979125@news.povray.org>
Cousin Ricky <ric### [at] yahoocom> wrote:
> On 2024-06-27 11:44 (-4), William F Pokorny wrote:
> > Release R15 of the yuqk fork has an implementation supporting constant
> > identifiers / macro parameters. They are indicated by using a leading
> > '_' character in the name.
>
> I also agree with Ingo: a keyword or directive would be better, such as:
>
>   #const MagicNumber = 12345;
>
> I'm thinking a keyword modifier would be more flexible than a directive,
> for example:
>
>   #declare const GlobalVal = 12345;
>   #local const LocalVal = 54321;

Hmmm.   Yes, but maybe no?
Why not just have another separate type of declaration?

#declare
#local
#constant

We've also discussed
#persistent

as well as PRAGMA

So maybe #constant can ONLY be changed by specifically using another #constant
directive.

I dunno - I'm not really a computer language person, but the pro's and cons of
each approach ought to be hashed out with an eye towards Pov-Ray 4.0

- BW


Post a reply to this message

From: ingo
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 28 Jun 2024 01:15:00
Message: <web.667e468a4bc5dc7517bac71e8ffb8ce3@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:


#macro Add(_immuInt, otherInt)
......
#end

#declare Res = Add(99,1)

#declare _immu = 99;

#declare Res = Add(_immu, 1)

In the second use of the macro, would it be required that the 'referenced' value
is also declared immutable?

ingo


Post a reply to this message

From: jr
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 28 Jun 2024 04:45:00
Message: <web.667e777b4bc5dc75c7a7971d6cde94f1@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> Cousin Ricky <ric### [at] yahoocom> wrote:
> > On 2024-06-27 11:44 (-4), William F Pokorny wrote:
> > > Release R15 of the yuqk fork has an implementation supporting constant
> > > identifiers / macro parameters. They are indicated by using a leading
> > > '_' character in the name.
> >
> > I also agree with Ingo: a keyword or directive would be better, such as:
> >
> >   #const MagicNumber = 12345;
> >
> > I'm thinking a keyword modifier would be more flexible than a directive,
> > for example:
> >
> >   #declare const GlobalVal = 12345;
> >   #local const LocalVal = 54321;

"modifier", yes.  +1.


> Hmmm.   Yes, but maybe no?
> Why not just have another separate type of declaration?

the keyword modifier, more often than not I think, would be in close proximity
to the variable where/when it's used.  an advantage.


> ...
> So maybe #constant can ONLY be changed by specifically using another #constant
> directive.

if a variable's value can/will change "at runtime", #constant would simply be
misleading.


> I dunno - I'm not really a computer language person, but the pro's and cons of
> each approach ought to be hashed out with an eye towards Pov-Ray 4.0

maybe "4.x" could have a revamped "SDL 2.0", with more "introspection" tools, so
we can write better, "type safe" code.


regards, jr.


Post a reply to this message

From: ingo
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 28 Jun 2024 05:25:00
Message: <web.667e80794bc5dc7517bac71e8ffb8ce3@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I dunno - I'm not really a computer language person, but the pro's and cons of
> each approach ought to be hashed out with an eye towards Pov-Ray 4.0
>

Just as an example how it works in an other language. In the Nim programming
language the following will not work as all proc parameters are immutable int
types. With Nim procs immutable arguments is the default, unless one uses "var":

proc dothing(a: int, b: int): int =
  a = a + b
  return a

let
  a = 1
  b = 2

let res = dothing(a, b)


This one will work as c is declared and assigned a value, c is immutable (let)

proc dothing(a: int, b: int): int =
  let c = a + b
  return c

let
  a = 1
  b = 2

let res = dothing(a, b)


This will work as a is now of type var int, a mutable variable:

proc dothing(a: var int, b: int): int =
  a = a + b
  return a

var  a = 1
let  b = 2

a = dothing(a, b)

In the last example 'a' is 'var' in the proc and 'a' has to be "declared" as
'var', else the Nim compiler nags.

Changing a variable "declared" using 'let' into a 'var', or the other way
around, is not possible.

N.B. the last two examples can coexist next to each other in one file/program.
Depending on whether 'a' is a 'var' or not, the compiler chooses the proper
proc.

ingo


Post a reply to this message

From: William F Pokorny
Subject: Re: Suggest v4.0 read only identifiers. (yuqk R15 v0.6.9.0)
Date: 28 Jun 2024 09:12:10
Message: <667eb6aa$1@news.povray.org>
On 6/27/24 18:47, Cousin Ricky wrote:
> On 2024-06-27 11:44 (-4), William F Pokorny wrote:
>> Release R15 of the yuqk fork has an implementation supporting constant
>> identifiers / macro parameters. They are indicated by using a leading
>> '_' character in the name.
> 
> I also agree with Ingo: a keyword or directive would be better, such as:
> 
>    #const MagicNumber = 12345;
> 
> I'm thinking a keyword modifier would be more flexible than a directive,
> for example:
> 
>    #declare const GlobalVal = 12345;
>    #local const LocalVal = 54321;
> 

Thanks, everyone, for the feedback & thinking toward v4.0.

The yuqk fork is intended to be a playpen for features like this. 
Nothing about any given change or feature is set in stone. It might be 
the current implementation for read only variables gets dumped in part 
or in total after using it for while. I think it a decent approach, but 
I've not used it nearly enough myself to know. It is, likely, the only 
sort of global-ish thing doable with respect to identifier constant-ness 
given the state of our current Scene Description Language (SDL).

With our SDL and parser, we don't have a cleanly scoped and typed 
'variable' declaration system which allows more naturally for the 
propagation and maintenance of constant information. (Any v4.0 SDL 
re-work should probably treat scene identifiers complete apart from the 
language variables)

My initial runs at some constant identifier support started with the 
idea of all macro parameters being considered constant. However, I ran 
across cases where users had macros which used the pass by reference and 
change behavior.

I then started to look at a new 'const' keyword only with macro 
parameters while thinking about how I might extend its usage before 
concluding. There are a great many complications due how our language 
and parser work which drive the need for language refinement or ugly, 
complicated code infrastructure. I dropped the whole idea for years.

With yuqk, I've been forced to create prefixed language SDL keywords to 
fix bugs and enable features. Over time, I started to see it's more or 
less the same kind of weak scoping of functionality in our SDL. Where I 
adopted prefixed keywords the source code too became more understandable 
and manageable. I now plan, over time, to broadly adopt SDL keyword 
prefixes. With this next R15 yuqk release I'll have three in keyword 
prefixes in play with ii_ (input image), ip_ (internal 
pattern/perturbation) and it_ (internal turbulence).

One day, not long ago, it hit me that maybe identifier prefixes would be 
a way we could implement reasonably broad, useful constant-ness - though 
not completely robust, constant-ness. When I started to really look at 
implementing the idea, it turned out it was an amount of code work I 
could manage.

While working in yuqk, the features implemented are often not exactly 
what I'd wish for in v4.0! They are what I can manage and/or am forced 
to do in the context of the yuqk/POV-Ray implementation as it is.


---
(BW) > Is that a scene-wide global thing?

Currently, it's always on and acts depending on context and what's 
defined in each context. There isn't yet a way to configure with the 
feature off as there is with no lower case identifier checking - which 
is on by default in yuqk.

I think you're right, I need to go work on that configuration option 
before releasing R15. We should be able to create executable(s) with the 
checking off.

As for users switching the checking on and off on the fly... I think, 
such control runs counter to the aim of the constant-ness feature itself.

---
(ingo, jr, et al)

I realize there is a fair bit of _xyz parameter and identifier usage. 
It's in a lot of my own stuff too. Much of that will break - sometimes 
while pointing out existing exposures too. I haven't played enough to 
have a feel for the level of pain.

Given I'm going to delay to implement a build configuration option for 
this feature, do you think some other prefix would be better? ('_r', 
'ro_', 'r_', ?)

---
(jr)

Remember yuqk reduced the functionality of the 'optional' keyword to 
just macro parameters due bugs and that when I really looked at broader 
use, I found a new world space for confusing, extremely difficult to 
debug, SDL bugs.

---

The larger view is the yuqk fork is breaking compatibility with official 
POV-Ray releases.

I don't do it lightly because I want to be able to run scenes aimed at 
official releases too, but breakage is unavoidable given I want to 
address certain bugs, features and deficiencies.

Bill P.


Aside 1: I have still bugs and issues with the current global / local 
dictionary behavior in v3.8+ to sort... Our implementation doesn't match 
our documentation and we probably need a #top (or #upid (upvar n)) 
directive alongside #directive and #local.


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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