Hello [EMAIL PROTECTED]!

On 19-Gen-00, you wrote:

 b> a perl example:

 b> #!/usr/bin/perl

 b>  $n1 = 1;
 b> sub readFile { local( $name) = @_;
 b>    if ($a1) { 
 b>         local( $n1) = 300; 
 b>         doincl();
 b>             } 
 b>    doincl();
 b> }
 b> sub doincl {
 b>    print ("includelevel: $n1 $name\n");
 b>    $n1 += 1;
 b> }
 b> $a1 = 0; readFile("zzz");
 b> $a1 = 1; readFile("this");
 b> $a1 = 0; readFile("that");

I am not sure if I understand correctly the code above... anyway,
I'd like to try. What about this:

    n1: 1

    read-file: func [
        n
    ] [
        local [name: n] [
            if a1 [
                local [n1: 300] [
                    do-include
                ]
            ]
            do-include
        ]
    ]

    do-include: func [] [
        print ["includelevel:" n1 name]
        n1: n1 + 1
    ]
    
    a1: 0 read-file "zzz"
    a1: 1 read-file "this"
    a1: 0 read-file "that"

...where 'local was defined as:

    local: func [
        locals [block!]
        code [block!]
        /local lwords orig-values
    ] [
        lwords: make block! 10
        orig-values: make block! 10
        foreach item locals [
            if all [
                set-word? :item
                (item: to word! :item
                none? find lwords item) 
            ] [
                insert tail lwords item
                insert tail orig-values get/any item
            ]
        ]
        do locals
        do code
        set lwords orig-values
    ]

Result:

includelevel: 1 zzz
includelevel: 300 this
includelevel: 2 this
includelevel: 3 that

May I ask, do you really think this is useful? I think you can
achieve the same result avoiding to use global values and using
functions... Like:

    global-level: 1

    read-file: func [
        name condition
    ] [
        if condition [
            do-include name 300
        ]
        global-level: do-include name global-level
    ]

    do-include: func [
        name level
    ] [
        print ["includelevel:" level name]
        level + 1
    ]
    
    read-file "zzz" false
    read-file "this" true
    read-file "that" false

which results in:

includelevel: 1 zzz
includelevel: 300 this
includelevel: 2 this
includelevel: 3 that

Regards,
    Gabriele.
-- 
o--------------------) .-^-. (----------------------------------o
| Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila |
| GIESSE on IRC     \ \-\_/-/ /  http://www.amyresource.it/AGI/ |
o--------------------) `-v-' (----------------------------------o

Reply via email to