• where is the TCL "macro" command ?

    From aotto1968@aotto1968@t-online.de to comp.lang.tcl on Fri Jun 28 08:37:37 2024
    From Newsgroup: comp.lang.tcl

    Hi, the following code is ugly:

    proc block {args} {
    set code [lindex $args end]
    set args [lrange $args 0 end-1]
    foreach {var val} $args {
    uplevel [list push $var $val]
    }
    uplevel $code
    foreach {var val} $args {
    uplevel [list pop $var]
    }
    }

    I want to have

    macro block {args} {
    local code var val
    set code [lindex $args end]
    set args [lrange $args 0 end-1]
    foreach {var val} $args {
    push $var $val
    }
    eval $code
    foreach {var val} $args {
    pop $var
    }
    }

    the "macro" command evaluate the code IN the Frame of the calling "proc" arguments and "local" declared variables are local, all other variables
    are always in the frame of the calling "proc"


    mfg
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From aotto1968@aotto1968@t-online.de to comp.lang.tcl on Fri Jun 28 09:05:03 2024
    From Newsgroup: comp.lang.tcl


    well the "args" in "prog" should be improved ...

    proc block {args} {
    set code [lindex $args end]
    set args [lrange $args 0 end-1]
    ...
    }

    should be

    proc block {args code} {
    ...
    }

    "args" always collect as much as possible arguments
    { args code } first set the defined "code" from the "end" and
    all remaining arguments got to "args"

    On 28.06.24 08:37, aotto1968 wrote:
    Hi, the following code is ugly:

      proc block {args} {
        set code [lindex $args end]
        set args [lrange $args 0 end-1]
        foreach {var val} $args {
          uplevel [list push $var $val]
        }
        uplevel $code
        foreach {var val} $args {
          uplevel [list pop $var]
        }
      }

    I want to have

      macro block {args} {
        local code var val
        set code [lindex $args end]
        set args [lrange $args 0 end-1]
        foreach {var val} $args {
          push $var $val
        }
        eval $code
        foreach {var val} $args {
          pop $var
        }
      }

    the "macro" command evaluate the code IN the Frame of the calling "proc" arguments and "local" declared variables are local, all other variables
    are always in the frame of the calling "proc"


    mfg

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Jun 28 09:23:30 2024
    From Newsgroup: comp.lang.tcl

    * aotto1968 <aotto1968@t-online.de>
    | should be

    | proc block {args code} {
    | ...
    | }

    | "args" always collect as much as possible arguments
    | { args code } first set the defined "code" from the "end" and
    | all remaining arguments got to "args"

    Note that the TCL 'args' works differently: it is only 'magic' if it is
    the *last* entry in the argument list.

    https://www.tcl.tk/man/tcl8.6/TclCmd/proc.htm
    (*emphasis* added by me) :
    There is one special case to permit procedures with variable numbers of
    arguments. If the *last* formal argument has the name “args”, then a
    call to the procedure may contain more actual arguments than the proce-
    dure has formal arguments. In this case, all of the actual arguments
    starting at the one that would be assigned to args are combined into a
    list (as if the list command had been used); this combined value is as-
    signed to the local variable args.

    HTH
    R'
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Rich@rich@example.invalid to comp.lang.tcl on Fri Jun 28 16:18:14 2024
    From Newsgroup: comp.lang.tcl

    aotto1968 <aotto1968@t-online.de> wrote:
    the "macro" command evaluate the code IN the Frame of the calling "proc" arguments and "local" declared variables are local, all other variables
    are always in the frame of the calling "proc"

    Tcl (standard Tcl) has no "macro" capability such as you would
    typically find with a LISP.

    You may be looking for the "sugar" package:

    https://wiki.tcl-lang.org/page/Sugar

    Which is a Tcl extension to add some amount of LISP like "macro"
    capability to Tcl.

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Christian Gollwitzer@auriocus@gmx.de to comp.lang.tcl on Fri Jun 28 20:58:04 2024
    From Newsgroup: comp.lang.tcl

    Am 28.06.24 um 09:23 schrieb Ralf Fassel:
    * aotto1968 <aotto1968@t-online.de>
    | should be

    | proc block {args code} {
    | ...
    | }

    | "args" always collect as much as possible arguments
    | { args code } first set the defined "code" from the "end" and
    | all remaining arguments got to "args"

    Note that the TCL 'args' works differently: it is only 'magic' if it is
    the *last* entry in the argument list.

    Yes, but it would indeed be useful; hence TIP 288 https://core.tcl-lang.org/tips/doc/trunk/tip/288.md

    (unfortunately, rejected for 9.0)

    Christian
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From aotto1968@aotto1968@t-online.de to comp.lang.tcl on Sat Jun 29 08:05:49 2024
    From Newsgroup: comp.lang.tcl

    Sometimes tcl feels like the UDSSR "lada" car
    → everything is perfect and nothing have to be changed.

    I already mentioned that tcl needs a "pragma" to activate a incompatible extension on a
    per script basis

    example:

    pragma add args-everywhere

    On 28.06.24 20:58, Christian Gollwitzer wrote:
    Am 28.06.24 um 09:23 schrieb Ralf Fassel:
    * aotto1968 <aotto1968@t-online.de>
    | should be

    |     proc block {args code} {
    |       ...
    |     }

    | "args" always collect as much as possible arguments
    | { args code } first set the defined "code" from the "end" and
    | all remaining arguments got to "args"

    Note that the TCL 'args' works differently: it is only 'magic' if it is
    the *last* entry in the argument list.

    Yes, but it would indeed be useful; hence TIP 288 https://core.tcl-lang.org/tips/doc/trunk/tip/288.md

    (unfortunately, rejected for 9.0)

        Christian

    --- Synchronet 3.20a-Linux NewsLink 1.114