• Lexical Binding

    From Lawrence D'Oliveiro@21:1/5 to All on Tue Jun 4 05:59:08 2024
    In GXScript, I have renamed “def”, “load”, “store” and “where” to “ddef”,
    “dload”, “dstore” and “dwhere” (“d” for “dynamic”) and added corresponding
    lexically-bound variants “ldef”, “lload”, “lstore” and “lwhere”. In
    effect, GXScript is a “block-structured” language.

    Example:

    /Count 99 ddef

    {
    /Count 1 ldef
    3
    {
    /Count dup lload 1 add lstore
    (local Count = ) print /Count lload =
    (global Count = ) print /Count dload =
    (whichever Count = ) print Count =
    }
    repeat
    } exec

    produces output

    local Count = 2
    global Count = 99
    whichever Count = 2
    local Count = 3
    global Count = 99
    whichever Count = 3
    local Count = 4
    global Count = 99
    whichever Count = 4

    and you can define function factories, e.g.

    /Count 99 ddef

    /metatry
    { # provides context for nonlocals
    dup
    /Name exch ldef
    /Count 0 ldef
    { # actual proc
    /Count dup lload 1 add lstore
    /Count dup dload 1 add dstore
    Name =
    (local Count = ) print /Count lload =
    (global Count = ) print /Count dload =
    (whichever Count = ) print Count =
    }
    }
    ddef

    /try1 metatry ddef
    /try2 metatry ddef

    try1
    try2
    try1
    try2

    produces output

    try1
    local Count = 1
    global Count = 100
    whichever Count = 1
    try2
    local Count = 1
    global Count = 101
    whichever Count = 1
    try1
    local Count = 2
    global Count = 102
    whichever Count = 2
    try2
    local Count = 2
    global Count = 103
    whichever Count = 2

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)