|
|
On 6/29/24 01:00, jr wrote:
> hi,
>
> just a couple of thoughts.
>
> William F Pokorny <ano### [at] anonymousorg> wrote:
>> ...
>> One day, not long ago, it hit me that maybe identifier prefixes would be
>> a way we could implement reasonably broad, useful constant-ness - ...
>>
>> 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_', ?)
>
> "democracy" eh ?! </grin>. given those options, 'ro_' would be my choice, as
> it's "mnemonic".
>
Yeah, and ro_ fits with my keyword prefix direction too.
>
>> 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.
>
> having read ingo's Nim language examples, I really like the "everything is
> immutable unless" approach. safe. perhaps all macro args (as you wrote
> somewhere) ought to be "ro" by default, and an explicit 'upvar N' required for
> every exception ? (that (upvar N) :-) would be _seriously_ nice to have)
>
I've been thinking about those examples too & my response to Ingo's
question. I failed / bailed on my initial attempts to make a macro
parameters constant always - but success would have meant a SDL change
much more likely to break current code than an 'ro_' prefix. I hadn't
thought much at all about a keyword to change defaulted read-only to
something mutable via a new keyword.
It might be we could check that the mutability of the parameter in the
macro matches the caller's ID mutability, but there are limits to how
much checking like that we can do given SDL isn't compiled and linked.
We'd be paying the price of the overhead on every call to the macro.
From what I've seen people mostly use the macro 'pass by reference and
change' and '#declare ID' as mechanisms to return multiple values or to
define what they want global as with the yuqk munction concept compiling
users functions only once. (We now have the tuple return and assignment
mechanisms in v3.8.)
Another thing which might be possible nearer term, would be to make
mixed use of #declare and #local with the same variable name inside
macros illegal in yuqk (or in just the debug compile).
See the attached file for a few examples of how mixing one identifier
name with both #local and #declare can result in instability. The macro
parameter - change by reference - issue aside.
We should mention too, for those stumbling across this thread later,
that a good solution for all the macro-ish exposures to inadvertent
identifier change is to use functions when dealing with just math and a
return a value.
Bill P.
Post a reply to this message
Attachments:
Download 'instabilitywithlocalanddeclareuse.txt' (3 KB)
|
|