rgbds
rgbds copied to clipboard
[Feature request] Allow symbols to be assigned by value
Numeric and string symbols can be "backed up" before they are purged:
DEF N EQU 42
DEF OLD_N EQU N
PURGE N
DEF S EQUS "hello"
DEF OLD_S EQUS "{S}"
PURGE S
However, macros cannot. It would be useful to do so, in order to free up a particular symbol that happens to be a macro, for example one from a library. (Maybe I really want a label in the sym file named "lb" or "struct".)
I'm not sure what a good syntax would be. Some suggestions:
MACRO old_mac DEF mac(conflicts with named parameters if we ever add those, likeMACRO lb hi, lo)DEF old_mac MACRO mac(conflicts with the single-line macro syntax proposal in #902)DEF old_mac DEF mac(not obvious; could work for all symbol types)DEF old_mac EQUM mac(new keyword, IMO excessive for a minor feature)
My slight preference is for DEF old_mac DEF mac: it's awkward wording but doesn't add a new keyword or limit other features, and it could even work for other symbols (DEF old_string DEF string, DEF Alias DEF Label, etc). Arguably it's readable as "define old_sym as the definition of sym".
I personally like the def foo def bar idea (particularly if it applies to any symbol type), but I'm not too sure if that's the right syntax. I'd say that introducing a new keyword shouldn't be that scary, particularly if it's unlikely to collide; I'd go with copydef old_mac, mac.
"assign" or "defcopy" could also work.
I would appreciate having this for all symbols, not just macros. I've defined a number of macros for working with lists, and they have to be separately defined for lists of numbers and of strings. Some differences are real, like == vs strcmp, but many are just def x equ {sym} versus def x equs "{sym}". If I could do assign x, sym or def x def sym for both, they could share most of their code.
Also, an advantage to the def foo def bar syntax is that it could also extend to redef foo def bar, which does come up in my use case.
Sounds like too niche an usage, imo. I'm okay with saving macros, though we may want a different mechanism than this (I believe more in proper scoping than bodges like this). Depending on what we end up with, it may make sense to generalize it more symbol types (e.g. copy new = old), but we'll see then.