[M3devel] [modula3/cm3] Quake scoping issue (#19)

Rodney M. Bates rodney_bates at lcwb.coop
Mon Aug 28 21:55:27 CEST 2017



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.
                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>

No, you are trying to apply dynamic scoping interpretation.  In dynamic scoping, the next
outer scope around a procedure is its caller, as your statement says, and which can vary
with different calls.

In static scoping, the next outer scope of a procedure is determined solely by the textual
location of its definition, not where it's called from.  So the only scope it is inside
of is the global one, here.

The unusual, "bizarre" rule, which is independent of static scoping itself is, even when
the definition is located inside another inner scope (it could only be a for statement
or such), its containing scope is the global one.  But with or without this rule, it's
only about the location of the definition, not a call.

I also think I might possibly understand why include leads you to similar expectations.
include is done once when the definition of the procedure is seen, not when it is called.
So that too, has nothing to do with the scope of the call.

> — 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