[M3devel] [modula3/cm3] Quake scoping issue (#19)
Rodney M. Bates
rodney_bates at lcwb.coop
Sat Aug 26 18:40:41 CEST 2017
This example suggests another point, not mentioned so far:
test_var = 0
readonly proc P ( test_var ) is
readonly proc Q ( ) is
write(format("In Q, test_var = %s\n", test_var))
end %Q
write(format("In P, test_var = %s\n", test_var))
Q ( )
end %P
P (123)
Q()
Produces:
--- building in ../AMD64_LINUX ---
In P, test_var = 123
In Q, test_var = 0
In Q, test_var = 0
The decl of 'Q' is located inside 'P', but not only is its name ('Q') declared in
the global scope, but also, nonlocal references inside 'Q' (e.g., 'test_var')
are looked up directly in the global scope as well. It is if the entire decl
of 'Q' were pulled outside of 'P'.
Except..., for the matter of declare-before-use, which is probably as if the decl
of 'Q' stayed where it is. At this point, I am feeling like this is starting
to be too much attention to waste on the dark corners of the semantics of Quake.
<soapbox>
I have always felt the often bizarre and often ill-defined semantics of dynamically-
typed, interpreted, scripting languages are inevitably a mess, and people should
not be wasting so much time writing anything very complicated in any of them.
The current fad of using Python to teach new young coders in schools is, IMO,
very short-sighted.
At least the designers of Quake admitted up front that it was only intended to have
minimal capability, just adequate for the limited needs of the Modula3 build system.
</soapbox>
On 08/25/2017 07:55 PM, JC Chu wrote:
> I understand from §7.2 and your comment that, when “m3makefile2” is included, it is interpreted inside the local scope created when `map_proc` is called, where `list` is not bound to a procedure. In fact, even if “m3makefile2” didn’t define `list` itself, the same error would still occur. (That said, if procedures can only be defined in the global scope, shouldn’t they only be searched there as well?)
>
> However, by the same argument, the behavior of the following makefile is a bit unexpected to me.
>
> test_var = 0
> readonly proc call (f, test_var) is return f() end
> readonly proc write_test_var () is
> write(format("test_var = %s\n"), test_var)
> end
> readonly proc eval (_) is end
> eval(call(write_test_var, 123))
>
> Here, `write_test_var` is evaluated in its own scope, which is inside the scope of `call`, where `test_var` = 123. The actual output, though, is 0.
>
> — JC
>
> -----Original Message-----
> From: Rodney M. Bates [mailto:rbatesjk at lcwb.coop]
> Sent: Friday, August 25, 2017 23:40
> To: reply+00655cb4faee270b469769c158f8bcd114e2942747144a0292cf0000000115b6154992a169ce0f0c9468 at reply.github.com; m3devel <m3devel at elegosoft.com>; jcchu >> JC Chu <jcchu at acm.org>
> Subject: Re: [modula3/cm3] Quake scoping issue (#19)
>
> According to Quake, 7.3, "Procedures may be defined in the global scope only".
> Apparently, from experiment, this means that, although the procedure definition
> itself can be located inside a local scope, its name is declared in the global
> scope.
>
> So, if you don't import libm3, your 'list' declaration is not a duplicate, thus
> produces no error, and becomes declared in the global scope. But the call on
> 'list' resolves to the formal parameter 'list', of 'map_proc', which is found
> in the local scope, and whose value is the list '[ m3makefile2 ]', not a
> procedure, and thus not callable.
>
> Any suitable renaming of either the parameter or the procedure, so that the two
> meanings of 'list' have different names, works as expected.
>
> I'll grant that having a procedure declaration located in a local scope but
> declaring its name in the global one is peculiar, and this is a peculiar
> effect of that rule.
>
> I have made a note to explain this better in the Quake documentation.
>
> On 08/23/2017 11:17 PM, jcchu wrote:
>> See demo.zip <https://github.com/modula3/cm3/files/1247702/demo.zip>.
>>
>> —
>> You are receiving this because you are subscribed to this thread.
>> Reply to this email directly, view it on GitHub <https://github.com/modula3/cm3/issues/19>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGVctCYptEcKU12OG82H67xEwMAkKPkNks5sbPlJgaJpZM4PA3zO>.
>>
> _______________________________________________
> M3devel mailing list
> M3devel at elegosoft.com
> https://m3lists.elegosoft.com/mailman/listinfo/m3devel
>
--
Rodney Bates
rodney.m.bates at acm.org
More information about the M3devel
mailing list