Am 19.12.22 um 16:45 schrieb Luc:
> On Mon, 19 Dec 2022 15:52:43 +0100, Christian Gollwitzer wrote:
>
>> Yes it is pure hell. There are a few "programming languages" like this
>> (e.g. SPECS instrument control system) which have no local variables and
>> it becomes hell whenever you decide to import a library written by
>> someone else.
>
>
> I'm pretty sure there is a very large number of programs/scripts out there
> that will never ever interact with any external libraries or packages or
> remote machines and will never be shared. That kind of use exists, it's very
> common and cannot (and should not) be prevented.
I mentioned the SPECS thing exactly because this started as a language
for scripts which does not require external libraries etc. It is a
specialised language for driving scientific equipment to acquire data. A
colleague had written some advanced measurement procedures in it, then
wanted to integrate a new detector. The vendor of this detector provides
SPECs macros - which then, of course, used variable names which collided
with the script from my colleague. In the end, we threw everything
overboard and switched to a more sane system. That was easier then to
untangle the codes.
>
> What also cannot be prevented is that someone begins a script/program with
> some kind of inventory of all variables used in the program and making them
> all globals with the 'global' command. Any possible implementation of what
> I asked would merely automate something that already can be done although
> in a tedious manner.
>
I'm still not sure I understand WHY you would want to have something
like that. However, I'm quite sure that there are better solutions. One
of them could be the use of an object system. There, you declare
variables once, but you don't have to repeat the "variable x" or "global
x" in each and every proc.
E.g.:
oo::class create testglobals {
variable x
variable y
method setxy {x_ y_} {
set x $x_
set y $y_
}
method print {} {
puts "x: $x y: $y"
}
}
testglobals create B
B setxy 3 4
B print
As you can see here, in both methods setxy and print, you can access the
variables "x" and "y" without specially annotating them. However, since
they are marked as a variable in the class declaration, you could some
other variable "set i 7" in one of them without interfering with other
parts of the code.
Christian