Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #318: Your EMAIL is now being delivered by the USPS.


comp / comp.lang.tcl / Re: where is the TCL "macro" command ?

SubjectAuthor
* where is the TCL "macro" command ?aotto1968
+* Re: where is the TCL "macro" command ?aotto1968
|`* Re: where is the TCL "macro" command ?Ralf Fassel
| `* Re: where is the TCL "macro" command ?Christian Gollwitzer
|  `- Re: where is the TCL "macro" command ?aotto1968
`- Re: where is the TCL "macro" command ?Rich

1
Subject: where is the TCL "macro" command ?
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 28 Jun 2024 06:37 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: where is the TCL "macro" command ?
Date: Fri, 28 Jun 2024 08:37:37 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <v5llnh$37llc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 28 Jun 2024 08:37:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c76961bfecfe5181df2c9568727b09d5";
logging-data="3397292"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19i1+B+BTSOmKG5+ojly58fOLEEnfvqi4M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tsUvt2TC50h0MZtBJ0rbf9ryWrY=
Content-Language: en-US
View all headers

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

Subject: Re: where is the TCL "macro" command ?
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 28 Jun 2024 07:05 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: where is the TCL "macro" command ?
Date: Fri, 28 Jun 2024 09:05:03 +0200
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <v5lnav$37llc$2@dont-email.me>
References: <v5llnh$37llc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 28 Jun 2024 09:05:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c76961bfecfe5181df2c9568727b09d5";
logging-data="3397292"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+h2XYLIm5RkC4OZ9lXVHOv+sSQenHjE2E="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yF7g5AURNHVj4IgSE9dTCCvblDU=
In-Reply-To: <v5llnh$37llc$1@dont-email.me>
Content-Language: en-US
View all headers

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

Subject: Re: where is the TCL "macro" command ?
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Fri, 28 Jun 2024 07:23 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: where is the TCL "macro" command ?
Date: Fri, 28 Jun 2024 09:23:30 +0200
Lines: 26
Message-ID: <ygar0chttsd.fsf@akutech.de>
References: <v5llnh$37llc$1@dont-email.me> <v5lnav$37llc$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net m8k/J+hL7TF+MlW9jqNLQQEN4sNzl9NjPe0ab/2GNQVAWnGTo=
Cancel-Lock: sha1:DfRGO+bJkvdNDasyqJilV9b+jGU= sha1:aFSuHq2RCRrZfXD/XdUGpaXdYAs= sha256:Mwlam+aYC8BjxakZBMTv5qIOfF51i7qdIESxlsJolmw=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* 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'

Subject: Re: where is the TCL "macro" command ?
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 28 Jun 2024 16:18 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: where is the TCL "macro" command ?
Date: Fri, 28 Jun 2024 16:18:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <v5mno6$3dht6$2@dont-email.me>
References: <v5llnh$37llc$1@dont-email.me>
Injection-Date: Fri, 28 Jun 2024 18:18:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="100d8aac9b0387cc56bdc40c71667406";
logging-data="3590054"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Z8n58YvWPKaQRb+59viwg"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:fvLSGJJo+9bLxPDuynapO1tzCKQ=
View all headers

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.

Subject: Re: where is the TCL "macro" command ?
From: Christian Gollwitzer
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 28 Jun 2024 18:58 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: where is the TCL "macro" command ?
Date: Fri, 28 Jun 2024 20:58:04 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <v5n13s$3fdlt$1@dont-email.me>
References: <v5llnh$37llc$1@dont-email.me> <v5lnav$37llc$2@dont-email.me>
<ygar0chttsd.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 28 Jun 2024 20:58:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="22d6777b5c707f7cb6c3ff9239a468d6";
logging-data="3651261"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ma3Ftv0/yj7/A7SjFpxXDG5xSPE1nOac="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Z5fmyxZm21cMfFR1yYi+3FsKs5M=
In-Reply-To: <ygar0chttsd.fsf@akutech.de>
View all headers

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

Subject: Re: where is the TCL "macro" command ?
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sat, 29 Jun 2024 06:05 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: where is the TCL "macro" command ?
Date: Sat, 29 Jun 2024 08:05:49 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <v5o87t$3ppap$1@dont-email.me>
References: <v5llnh$37llc$1@dont-email.me> <v5lnav$37llc$2@dont-email.me>
<ygar0chttsd.fsf@akutech.de> <v5n13s$3fdlt$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 29 Jun 2024 08:05:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c9fe028220d78dd2394e55b67ed5934c";
logging-data="3990873"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+y3zVa3pu8N/DjipiPGBNz0PMDszBYoPU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:RiANh/Y4eLGzW5pRbLrmLH4tHJs=
In-Reply-To: <v5n13s$3fdlt$1@dont-email.me>
Content-Language: en-US
View all headers

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

1

rocksolid light 0.9.8
clearnet tor