Whats about following enhancement suggestion? 
Author Message
 Whats about following enhancement suggestion?

Hi,

I thought about following enhancement of the 'global'-command
and I would be glad reading some comments on this thoughts!

My enhancement ideas:

old syntax of global:
   global varname ?varname ...?

new syntax of global:
   global varnamepattern ?varnamepattern ...?

new functionality of global:
 1. global uses glob-matching to identify the
    varnames to be global in the current scope
 2. if global is used in the global scope than
    the given varnames or varname patterns cause
    this variables to be global in every scope
    without using the global command
    This works like the public-command in Visual
    Basic.

example 1:
 source:
    set EXCEPTIONS(INVALIDARG) 1
    set EXCEPTIONSINFO(INVALIDARG) "ABC"

    proc aProc {} {
      global EXCEPTIONS

      puts $EXCEPTIONS(INVALIDARG)
      puts $EXCEPTIONSINFO(INVALIDARG)
    }

    aProc
 result:
    1
    ABC
example 2:
 source:
    set EXCEPTIONS(INVALIDARG) 1
    set EXCEPTIONSINFO(INVALIDARG) "ABC"

    proc aProc {} {
      global EXCEPTIONS

      puts $EXCEPTIONS(INVALIDARG)
      puts $EXCEPTIONSINFO(INVALIDARG)
    }

    aProc
 result:
    1
    can't read "EXCEPTIONSINFO(INVALIDARG)": no such variable
example 3:
 source:
    global EXCEPTIONS*

    proc aProc {} {
      set EXCEPTIONS(INVALIDARG) 1
      set EXCEPTIONSINFO(INVALIDARG) "BCA"
    }

    aProc

    puts $EXCEPTIONS(INVALIDARG)
    puts $EXCEPTIONSINFO(INVALIDARG)
 result:
    1
    BCA
example 4:
 source:
    global EXCEPTIONS

    proc aProc {} {
      set EXCEPTIONS(INVALIDARG) 1
      set EXCEPTIONSINFO(INVALIDARG) "BCA"
    }

    aProc

    puts $EXCEPTIONS(INVALIDARG)
    puts $EXCEPTIONSINFO(INVALIDARG)
 result:
    can't read "EXCEPTIONSINFO(INVALIDARG)": no such variable

So what do you thing of this idea?

Bye and thanks for your comments!

Martin Lemburg
____________________________________________

Martin Lemburg
Scharnweberstrasse 112 - D-13405 Berlin
Tel.  +49 (0) 30  417 837 66
Mob.  +49 (0) 179 395 40 95
Fax.  +49 (0) 441 800 990 6462



Thu, 09 May 2002 03:00:00 GMT  
 Whats about following enhancement suggestion?

Quote:
> I thought about following enhancement of the 'global'-command
> and I would be glad reading some comments on this thoughts!

> My enhancement ideas:

> old syntax of global:
>    global varname ?varname ...?

> new syntax of global:
>    global varnamepattern ?varnamepattern ...?
> new functionality of global:
>  1. global uses glob-matching to identify the
>     varnames to be global in the current scope
>  2. if global is used in the global scope than
>     the given varnames or varname patterns cause
>     this variables to be global in every scope
>     without using the global command

Good news!  This can already be done:

    proc globalpat {args} {
        foreach pattern $args {
            set varnames [info globals $pattern]
            if {[llength $varnames] != 0} {
               uplevel 1 global $varnames
            }
        }
    }

To use:

    proc hello {} {
        globalpat *tcl*
        puts $tcl_patchLevel
    }

  % hello
  8.2.2



Thu, 09 May 2002 03:00:00 GMT  
 Whats about following enhancement suggestion?

Quote:

> new syntax of global:
>    global varnamepattern ?varnamepattern ...?
> new functionality of global:
>  1. global uses glob-matching to identify the
>     varnames to be global in the current scope
>  2. if global is used in the global scope than
>     the given varnames or varname patterns cause
>     this variables to be global in every scope
>     without using the global command
>     This works like the public-command in Visual
>     Basic.

Don't like this because it makes it very difficult to see whether
a particular variable in a procedure is global or not and changes
to the list may break previously working procedures. This will
make integration of different packages much harder.

Also, global variables should be deprecated in all forms and
namespace variables should be recommended if and only if you
really need a global variable.

On a more subjective note, the fact that this idea comes from
Visual Basic (which probably based it on fortran) is enough to
kill it for me.

If you really need this functionality, like you are porting a
Visual Basic application (if you are three cheers to you) then you
can create your own function 'public' which does this for you.



Fri, 10 May 2002 03:00:00 GMT  
 Whats about following enhancement suggestion?

Quote:


> > ...
> Don't like this because ...

I strongly agree with Paul.

Jo?l

Sent via Deja.com http://www.deja.com/
Before you buy.



Fri, 10 May 2002 03:00:00 GMT  
 Whats about following enhancement suggestion?

Quote:


> >...

> Don't like this ...

Paul, you took the words out of my mouth.

--
+--------------------------------+---------------------------------------+

| Gerald W. Lester               | "The man who fights for his ideals is
|

|
|               Webmaster for http://www.mtolive-lcms.org
|
+--------------------------------+---------------------------------------+



Sat, 11 May 2002 03:00:00 GMT  
 Whats about following enhancement suggestion?
Ok - you all are right - my suggestion belongs not the tcl/tk philosophy
and sounds more like blasphemy.

So I must explain the backgrounds ...

... to convert programms of numeric-controlled-controllers for lathes,
mills and anything that could be controlled with NC-controllers we (my
company) want to use a converter - a tcl-converter.
We need to use a tcl-converter, because the tcl-NC-programms are exe-
cuted for simulation on a tcl-NC-controller!

Since DIN or ISO-conform languages don't have something like control-
structures, global/local variables and gotos it was easy to translate
or convert linear NC-programms.
But now we have to convert a NC-program build in a language simular to
BASIC or FORTRAN with dirty codings like GOTOs out of loops ...!
The language is heavly modular that means that every subroutine is a
seperate NC-programm.

So we need the capability to break more than one loop at a time (we got
a few ideas yet), to jump to defined labels and to declare "public"
variables!

Until now we redefined the while-/for-/foreach-commands execute the
loops under control and to replace any break-command inside the loops
by an own proc to process the break through several loop-levels.
We defined an repeat-until/do-while-construct and think about possibilities
to create a GOTO-/jump-proc.

Is there anybody who could help to think about a GOTO or is this blasphemy?

Thanks and use my email if you want to!

Bye

Martin Lemburg
--
____________________________________________

Martin Lemburg
Scharnweberstrasse 112 - D-22763 Berlin
Tel./Ph. +49 (30)  41783766
Fax.     +49 (441) 800 990 6462

    Martin Lemburg schrieb in Nachricht ...
    Hi,

    I thought about following enhancement of the 'global'-command
    and I would be glad reading some comments on this thoughts!

    My enhancement ideas:

    old syntax of global:
       global varname ?varname ...?

    new syntax of global:
       global varnamepattern ?varnamepattern ...?

    new functionality of global:
     1. global uses glob-matching to identify the
        varnames to be global in the current scope
     2. if global is used in the global scope than
        the given varnames or varname patterns cause
        this variables to be global in every scope
        without using the global command
        This works like the public-command in Visual
        Basic.

    example 1:
     source:
        set EXCEPTIONS(INVALIDARG) 1
        set EXCEPTIONSINFO(INVALIDARG) "ABC"

        proc aProc {} {
          global EXCEPTIONS

          puts $EXCEPTIONS(INVALIDARG)
          puts $EXCEPTIONSINFO(INVALIDARG)
        }

        aProc
     result:
        1
        ABC
    example 2:
     source:
        set EXCEPTIONS(INVALIDARG) 1
        set EXCEPTIONSINFO(INVALIDARG) "ABC"

        proc aProc {} {
          global EXCEPTIONS

          puts $EXCEPTIONS(INVALIDARG)
          puts $EXCEPTIONSINFO(INVALIDARG)
        }

        aProc
     result:
        1
        can't read "EXCEPTIONSINFO(INVALIDARG)": no such variable
    example 3:
     source:
        global EXCEPTIONS*

        proc aProc {} {
          set EXCEPTIONS(INVALIDARG) 1
          set EXCEPTIONSINFO(INVALIDARG) "BCA"
        }

        aProc

        puts $EXCEPTIONS(INVALIDARG)
        puts $EXCEPTIONSINFO(INVALIDARG)
     result:
        1
        BCA
    example 4:
     source:
        global EXCEPTIONS

        proc aProc {} {
          set EXCEPTIONS(INVALIDARG) 1
          set EXCEPTIONSINFO(INVALIDARG) "BCA"
        }

        aProc

        puts $EXCEPTIONS(INVALIDARG)
        puts $EXCEPTIONSINFO(INVALIDARG)
     result:
        can't read "EXCEPTIONSINFO(INVALIDARG)": no such variable

    So what do you thing of this idea?

    Bye and thanks for your comments!

    Martin Lemburg
    ____________________________________________

    Martin Lemburg
    Scharnweberstrasse 112 - D-13405 Berlin
    Tel.  +49 (0) 30  417 837 66
    Mob.  +49 (0) 179 395 40 95
    Fax.  +49 (0) 441 800 990 6462



Sun, 12 May 2002 03:00:00 GMT  
 Whats about following enhancement suggestion?

Quote:

> Ok - you all are right - my suggestion belongs not the tcl/tk philosophy
> and sounds more like blasphemy.

> So I must explain the backgrounds ...

> ... to convert programms of numeric-controlled-controllers for lathes,
> mills and anything that could be controlled with NC-controllers we (my
> company) want to use a converter - a tcl-converter.
> We need to use a tcl-converter, because the tcl-NC-programms are exe-
> cuted for simulation on a tcl-NC-controller!

> Since DIN or ISO-conform languages don't have something like control-
> structures, global/local variables and gotos it was easy to translate
> or convert linear NC-programms.
> But now we have to convert a NC-program build in a language simular to
> BASIC or FORTRAN with dirty codings like GOTOs out of loops ...!
> The language is heavly modular that means that every subroutine is a
> seperate NC-programm.

> So we need the capability to break more than one loop at a time (we got
> a few ideas yet), to jump to defined labels and to declare "public"
> variables!

> Until now we redefined the while-/for-/foreach-commands execute the
> loops under control and to replace any break-command inside the loops
> by an own proc to process the break through several loop-levels.
> We defined an repeat-until/do-while-construct and think about possibilities
> to create a GOTO-/jump-proc.

> Is there anybody who could help to think about a GOTO or is this blasphemy?

Ok, so you want to take Tcl, and turn it into another language. That actually
does fit in well with the Tcl philosophy of being able to redefine all the
commands.

Breaking out of several loops can easily be done by using error and catch.
break <n>
        This would generate an error with an exception code which is a list
        of some marker BREAK and the number <n>. The loop commands would
        catch errors, rethrowing errors which do not match. For those which
        did match they would decrement <n>, throwing a new error
        BREAK <n-1> if <n> is not zero, otherwise it would simply return.

As for goto there was a discussion on here about how to implement goto and
I seem to remember that quite a good solution was found by the end of it.



Mon, 13 May 2002 03:00:00 GMT  
 Whats about following enhancement suggestion?

Quote:

...
>> Is there anybody who could help to think about a GOTO or is this blasphemy?

>Ok, so you want to take Tcl, and turn it into another language. That actually
>does fit in well with the Tcl philosophy of being able to redefine all the
>commands.

>Breaking out of several loops can easily be done by using error and catch.
>break <n>
>       This would generate an error with an exception code which is a list
>       of some marker BREAK and the number <n>. The loop commands would
>       catch errors, rethrowing errors which do not match. For those which
>       did match they would decrement <n>, throwing a new error
>       BREAK <n-1> if <n> is not zero, otherwise it would simply return.

>As for goto there was a discussion on here about how to implement goto and
>I seem to remember that quite a good solution was found by the end of it.

I can't remember where this came from. It used to work under older Tcl, but I think that the
compiler is killing it today. The basic logic is that when a goto command is executed the
goto proc renames all existing commands to be do-nothings and then creates a special command of
the form lbl: to restore the pre-existing behaviour. Now seems that the compiler gets there
first for if in the example below.

proc goto lbl {
    rename foreach GRAB\ foreach
    rename info    GRAB\ info
    rename if      GRAB\ if
    rename string  GRAB\ string
    rename list    GRAB\ list
    rename proc    GRAB\ proc
    rename lindex  GRAB\ lindex
    rename puts    GRAB\ puts
    rename lsort   GRAB\ lsort

    rename rename  GRAB\ rename

    GRAB\ foreach c [GRAB\ info commands] {
        GRAB\ if {![GRAB\ string match GRAB* $c]} {
            GRAB\ rename $c [GRAB\ list DISABLE $c]
            GRAB\ proc $c args {}
        }
    }

    GRAB\ proc $lbl: args [GRAB\ list GRAB\ RESTORE $lbl]

Quote:
}

proc GRAB\ RESTORE {lbl} {
    GRAB\ rename GRAB\ rename rename

    rename GRAB\ foreach foreach
    rename GRAB\ info    info
    rename GRAB\ if      if
    rename GRAB\ string  string
    rename GRAB\ list    list
    rename GRAB\ proc    proc
    rename GRAB\ lindex  lindex
    rename GRAB\ puts    puts
    rename GRAB\ lsort   lsort

    foreach c [info commands "DISABLE *"] {
        rename [lindex $c 1] {}
        rename $c [lindex $c 1]
    }

    rename $lbl: {}

Quote:
}

proc anything {args} {
        }
#----------------------------------------------------------------------
#
# EXAMPLE USAGE
#

proc demo {} {
    puts "Hello."
    goto hell

    puts "Foo that funky bar, white boy."
    if {[anything happens]} {
        panic
    }

hell:
    puts "Bye bye."

Quote:
}

demo
--
Robin Becker


Tue, 14 May 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Enhancement suggestion (half-baked)

2. Simple View Composer Enhancement Suggestions

3. CW20: Enhancement \ Fixes : Suggestions

4. Inviting feature enhancement suggestions for gnuplotfortran

5. Enhancement suggestion regarding menus

6. Suggestion for Enhancement to Tcl

7. whats the word on apl94 ?

8. To See Whats Happen - Cobol Call Statistik

9. Whats the visual works class object?

10. whats wrong with smalltalk/x ?

11. Whats nawk ( compare to awk ? )

12. whats the matter with realnews?

 

 
Powered by phpBB® Forum Software