Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The meek are contesting the will.


devel / comp.lang.tcl / Re: "uplevel" in "proc" → missing more general "macro"-solution

SubjectAuthor
* "uplevel" in "proc" → missing more generaaotto1968
+* Re: "uplevel" in "proc" → missing more general "maheinrichmartin
|+- Re: "uplevel" in "proc" → missing more gChristian Gollwitzer
|`- Re: "uplevel" in "proc" → missing more gGerald Lester
`- Re: "uplevel" in "proc" → missing more gGerald Lester

1
"uplevel" in "proc" → missing more general "macro"-solution

<tb67lc$1346h$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19687&group=comp.lang.tcl#19687

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: "uplevel"_in_"proc"_→_missing_more_genera
l_"macro"-solution
Date: Tue, 19 Jul 2022 14:22:03 +0200
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <tb67lc$1346h$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 19 Jul 2022 12:22:04 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="7d6cc13c84b513824e214acea41814cf";
logging-data="1151185"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RJZWYvB+NZCO3Ps34MKrcaeEO4Y1vCEQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Cancel-Lock: sha1:NxhcFmED5NDGKgB5Qdff0dU1T+A=
Content-Language: en-US
 by: aotto1968 - Tue, 19 Jul 2022 12:22 UTC

Hi,

an *uplevel-proc* is an *proc* which evaluate the entire content
*uplevel* → example:

proc Format_Return_Error_Check {hdl err} {
uplevel "Format_Error_Check $hdl $err ; set retM void"
}

This simulate a *CPP*-Macro like behavior in *TCL*.

The easy solution to just lice a normal *proc*-body like:

proc Format_Return_Error_Check {hdl err} {
upvar retM retM
Format_Error_Check $hdl $err
set retM void
}

is not really a solution because the "upvar" in a sub-*proc* like
*Format_Error_Check* is broken because *Format_Return_Error_Check*
return an extra call-frame.

solution:

It should be possible to create a *proc* witch *not* add an extra
*level* to the call-frame, a good name would be *macro* :

macro Format_Return_Error_Check {hdl err} {
Format_Error_Check $hdl $err
set retM void
}

The following features should be present:

1) A *macro* argument variable (hdl err) is *only* visible in the macro-body
2) A other variable (retM) is from the calling-call-frame
3) A *macro* deos NOT add a call-frame → an *upvar* in
*Format_Error_Check* should call he calling-call-frame and not the
macro-body-frame

mfg

Re: "uplevel" in "proc" → missing more general "macro"-solution

<9d80c5c6-80b2-44b6-b78d-b5e67fceffa2n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19691&group=comp.lang.tcl#19691

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:4b48:0:b0:31e:fa8c:8555 with SMTP id e8-20020ac84b48000000b0031efa8c8555mr5977208qts.416.1658300192316;
Tue, 19 Jul 2022 23:56:32 -0700 (PDT)
X-Received: by 2002:a05:6870:418d:b0:10c:1a0b:75ea with SMTP id
y13-20020a056870418d00b0010c1a0b75eamr1704763oac.287.1658300192053; Tue, 19
Jul 2022 23:56:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 19 Jul 2022 23:56:31 -0700 (PDT)
In-Reply-To: <tb67lc$1346h$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.234.112; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.234.112
References: <tb67lc$1346h$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9d80c5c6-80b2-44b6-b78d-b5e67fceffa2n@googlegroups.com>
Subject: Re:_"uplevel"_in_"proc"_→_missing_more_general_"ma
cro"-solution
From: martin.heinrich@frequentis.com (heinrichmartin)
Injection-Date: Wed, 20 Jul 2022 06:56:32 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3625
 by: heinrichmartin - Wed, 20 Jul 2022 06:56 UTC

On Tuesday, July 19, 2022 at 2:22:08 PM UTC+2, aotto1 wrote:
> Hi,
>
> an *uplevel-proc* is an *proc* which evaluate the entire content
> *uplevel* → example:
>
> proc Format_Return_Error_Check {hdl err} {
> uplevel "Format_Error_Check $hdl $err ; set retM void"
> }
>
> This simulate a *CPP*-Macro like behavior in *TCL*.

Tcl has quite some nice features that can help to prevent duplicate code beyond putting it in a proc. Here are some that are crossing my mind.

1. uplevel

If you stick to your pattern, you are looking for [catch {uplevel 1 {...}} result options], then [dict incr options -level; return {*}$options $result].
You could even write your own proc "macro" that adds this wrapper to the code before actually creating the proc.

2. upvar

As uplevel has a performance penalty (cannot be optimized), upvar'ing well-known or passed variable names should be preferred over uplevel. The catch-wrapper is still needed for generic code.

3. inject code

Sometimes, I am using [proc name args [format {} $inject1 ...]]. I am using it for one-time-setup/config and also to prevent duplicate code.
Pro: Tcl sees a constant proc body and can fully optimize it.
Con: An extra level of escaping, but % is normally not a factor.

4. rewrite code

Just recently, I was injecting a code fix to a foreign proc while initializing my code. This pattern could be extended to rewrite "macros".

apply {{} {
set name this_proc
# build args like for proc
set args [lmap arg [info args $name] {
if {[info default $name $arg default]} {
list $arg $default
} else {
list $arg
}
}]
set body [info body $name]
# re-write to allow $client with parameters
# (braces around proc make my code doc scanner ignore this one)
{proc} $name $args [string map {{invoke $client } {invoke {*}$client }} $body]
log warn "$name was re-written!"
}}

Pro: Tcl sees a constant proc body and can fully optimize it.
Con (for non-Tclers): Might not feel like the natural way of coding ;-)

5. eval

Instead of uplevel, do uplevel without context change: eval.

6. packages/libs

Iirc, there are also a few Tcl packages that hook in to do magic to your code. Others may have names at hand.

HTH
Martin

Re: "uplevel" in "proc" → missing more general "macro"-solution

<tbbn8f$2dlk3$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19697&group=comp.lang.tcl#19697

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: "uplevel" in "proc" → missing more g
eneral_"macro"-solution
Date: Thu, 21 Jul 2022 16:18:14 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <tbbn8f$2dlk3$1@dont-email.me>
References: <tb67lc$1346h$1@dont-email.me>
<9d80c5c6-80b2-44b6-b78d-b5e67fceffa2n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 21 Jul 2022 14:18:56 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="d59361c2e223d3a3bac200934765b6bf";
logging-data="2545283"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VRPjm8TaHRtXq1Y3a2v1I/QElDVnB5wc="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
Cancel-Lock: sha1:olIkBqMK2hJL45WEm0uv0bs+CQM=
In-Reply-To: <9d80c5c6-80b2-44b6-b78d-b5e67fceffa2n@googlegroups.com>
 by: Christian Gollwitzer - Thu, 21 Jul 2022 14:18 UTC

Am 20.07.22 um 08:56 schrieb heinrichmartin:
> On Tuesday, July 19, 2022 at 2:22:08 PM UTC+2, aotto1 wrote:

>>
>> This simulate a *CPP*-Macro like behavior in *TCL*.
>

> 6. packages/libs
>
> Iirc, there are also a few Tcl packages that hook in to do magic to your code. Others may have names at hand.
>

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

Christian

Re: "uplevel" in "proc" → missing more general "macro"-solution

<tbh7hs$1buo$2@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19701&group=comp.lang.tcl#19701

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!JNQqFS25rnmZhNEZ11/SOA.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.Lester@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: "uplevel" in "proc" → missing more g
eneral_"macro"-solution
Date: Sat, 23 Jul 2022 11:27:35 -0500
Organization: KnG Consulting, LLC
Message-ID: <tbh7hs$1buo$2@gioia.aioe.org>
References: <tb67lc$1346h$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="45016"; posting-host="JNQqFS25rnmZhNEZ11/SOA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Gerald Lester - Sat, 23 Jul 2022 16:27 UTC

On 7/19/22 07:22, aotto1968 wrote:
> Hi,
>
> an *uplevel-proc* is an *proc* which evaluate the entire content
> *uplevel* → example:
>
>   proc Format_Return_Error_Check {hdl err} {
>     uplevel "Format_Error_Check $hdl $err ; set retM void"
>   }
>
> This simulate a *CPP*-Macro like behavior in *TCL*.
>
> The easy solution to just lice a normal *proc*-body like:
>
>   proc Format_Return_Error_Check {hdl err} {
>     upvar retM retM
>     Format_Error_Check $hdl $err
>     set retM void
>   }
>
> is not really a solution because the "upvar" in a sub-*proc* like
> *Format_Error_Check* is broken because *Format_Return_Error_Check*
> return an extra call-frame.
>
> solution:
>
> It should be possible to create a *proc* witch *not* add an extra
> *level* to the call-frame, a good name would be *macro* :
>
>   macro Format_Return_Error_Check {hdl err} {
>     Format_Error_Check $hdl $err
>     set retM void
>   }
>
> The following features should be present:
>
> 1) A *macro* argument variable (hdl err) is *only* visible in the
> macro-body
> 2) A other variable (retM) is from the calling-call-frame
> 3) A *macro* deos NOT add a call-frame → an *upvar* in
> *Format_Error_Check* should call he calling-call-frame and not the
> macro-body-frame
>
> mfg

Create a TIP with a sample implementations.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

Re: "uplevel" in "proc" → missing more general "macro"-solution

<tbhf60$dgh$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19702&group=comp.lang.tcl#19702

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!JNQqFS25rnmZhNEZ11/SOA.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.Lester@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: "uplevel" in "proc" → missing more g
eneral_"macro"-solution
Date: Sat, 23 Jul 2022 13:37:46 -0500
Organization: KnG Consulting, LLC
Message-ID: <tbhf60$dgh$1@gioia.aioe.org>
References: <tb67lc$1346h$1@dont-email.me>
<9d80c5c6-80b2-44b6-b78d-b5e67fceffa2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="13841"; posting-host="JNQqFS25rnmZhNEZ11/SOA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Gerald Lester - Sat, 23 Jul 2022 18:37 UTC

On 7/20/22 01:56, heinrichmartin wrote:
> On Tuesday, July 19, 2022 at 2:22:08 PM UTC+2, aotto1 wrote:
>> Hi,
>>
>> an *uplevel-proc* is an *proc* which evaluate the entire content
>> *uplevel* → example:
>>
>> proc Format_Return_Error_Check {hdl err} {
>> uplevel "Format_Error_Check $hdl $err ; set retM void"
>> }
>>
>> This simulate a *CPP*-Macro like behavior in *TCL*.
>
> Tcl has quite some nice features that can help to prevent duplicate code beyond putting it in a proc. Here are some that are crossing my mind.
>
> 1. uplevel
>
> If you stick to your pattern, you are looking for [catch {uplevel 1 {...}} result options], then [dict incr options -level; return {*}$options $result].
> You could even write your own proc "macro" that adds this wrapper to the code before actually creating the proc.
>
> 2. upvar
>
> As uplevel has a performance penalty (cannot be optimized), upvar'ing well-known or passed variable names should be preferred over uplevel. The catch-wrapper is still needed for generic code.
>
> 3. inject code
>
> Sometimes, I am using [proc name args [format {} $inject1 ...]]. I am using it for one-time-setup/config and also to prevent duplicate code.
> Pro: Tcl sees a constant proc body and can fully optimize it.
> Con: An extra level of escaping, but % is normally not a factor.
>
> 4. rewrite code
>
> Just recently, I was injecting a code fix to a foreign proc while initializing my code. This pattern could be extended to rewrite "macros".
>
> apply {{} {
> set name this_proc
> # build args like for proc
> set args [lmap arg [info args $name] {
> if {[info default $name $arg default]} {
> list $arg $default
> } else {
> list $arg
> }
> }]
> set body [info body $name]
> # re-write to allow $client with parameters
> # (braces around proc make my code doc scanner ignore this one)
> {proc} $name $args [string map {{invoke $client } {invoke {*}$client }} $body]
> log warn "$name was re-written!"
> }}
>
> Pro: Tcl sees a constant proc body and can fully optimize it.
> Con (for non-Tclers): Might not feel like the natural way of coding ;-)
>
> 5. eval
>
> Instead of uplevel, do uplevel without context change: eval.
>
> 6. packages/libs
>
> Iirc, there are also a few Tcl packages that hook in to do magic to your code. Others may have names at hand.
>
> HTH
> Martin

And then there is the Object Orient features.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+


devel / comp.lang.tcl / Re: "uplevel" in "proc" → missing more general "macro"-solution

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor