From e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa Mon Sep 17 00:00:00 2001 From: Roberto I Date: Sat, 8 Nov 2025 11:43:42 -0300 Subject: Global initialization checks name conflict Initialization "global a = 10" raises an error if global 'a' is already defined, that is, it has a non-nil value. --- manual/manual.of | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'manual') diff --git a/manual/manual.of b/manual/manual.of index 0127df02..eaf0ce78 100644 --- a/manual/manual.of +++ b/manual/manual.of @@ -1660,9 +1660,15 @@ The declaration can include an initialization: @producname{stat}@producbody{@Rw{global} attnamelist @bnfopt{@bnfter{=} explist}} } -If present, an initial assignment has the same semantics +If there is no initialization, +local variables are initialized with @nil; +global variables are left unchanged. +Otherwise, the initialization gets the same adjustment of a multiple assignment @see{assignment}. -Otherwise, all local variables are initialized with @nil. +Moreover, for global variables, +the initialization will raise a runtime error +if the variable is already defined, +that is, it has a non-nil value. The list of names may be prefixed by an attribute (a name between angle brackets) @@ -2312,8 +2318,10 @@ global function f () @rep{body} end } translates to @verbatim{ -global f; f = function () @rep{body} end +global f; global f = function () @rep{body} end } +The second @Rw{global} makes the assignment an initialization, +which will raise an error if that global is already defined. The @emphx{colon} syntax is used to emulate @def{methods}, -- cgit v1.2.3-55-g6feb