Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The most important early product on the way to developing a good product is an imperfect version.


devel / comp.lang.tcl / Re: quoting difficulty

SubjectAuthor
* quoting difficultyet4
+* Re: quoting difficultyet4
|+- Re: quoting difficultyYa Hu
|`* Re: quoting difficultyRich
| `* Re: quoting difficultyet4
|  `* Re: quoting difficultyRich
|   +* Re: quoting difficultyet4
|   |`* Re: quoting difficultyLuc
|   | `- Re: quoting difficultyet4
|   `* Re: quoting difficultyRalf Fassel
|    `- Re: quoting difficultyRich
`- Re: quoting difficultysaitology9

1
quoting difficulty

<tgo7mm$1u47$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!YN2ulY6LKp1eoOUw2OJ8ig.user.46.165.242.91.POSTED!not-for-mail
From: tclnews@rocketship1.me (et4)
Newsgroups: comp.lang.tcl
Subject: quoting difficulty
Date: Sat, 24 Sep 2022 17:34:30 -0700
Organization: Aioe.org NNTP Server
Message-ID: <tgo7mm$1u47$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="63623"; posting-host="YN2ulY6LKp1eoOUw2OJ8ig.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: et4 - Sun, 25 Sep 2022 00:34 UTC

I have a text entry where I want to be able to enter an arbitrary command to execute at global level with both the input command and the result written out using puts. The string to execute is sent as an arg to a procedure.

I've tried several methods, using [after 0] and also [uplevel #0] and I'm stumped. I've resorted to trial and error hoping it would eventually work without success.

Any ideas?

In my tests, arg is

$foobar + 5

and foobar is global and 10, I want to have it output the result: 15

Here are several attempts, to no avail:

% set foobar 10
10

------------------------
% proc test {arg} {
uplevel #0 [list puts "result of $arg is\n [list eval $arg]"]
}
% test {$foobar + 5}
result of $foobar + 5 is
eval {$foobar + 5}

------------------------

% proc test {arg} {
uplevel #0 [list puts "result of $arg is\n [eval $arg]"]
} % test {$foobar + 5}
can't read "foobar": no such variable

------------------------

% proc test {arg} {
uplevel #0 [list puts "result of $arg is\n [$arg]"]
} % test {$foobar + 5}
invalid command name "$foobar + 5"

--------------------------

% proc test {arg} {
uplevel #0 [list puts "result of $arg is\n \[list $arg\]"]
} % test {$foobar + 5}
result of $foobar + 5 is
[list $foobar + 5]

Re: quoting difficulty

<tgo849$2ll$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!YN2ulY6LKp1eoOUw2OJ8ig.user.46.165.242.91.POSTED!not-for-mail
From: tclnews@rocketship1.me (et4)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sat, 24 Sep 2022 17:41:44 -0700
Organization: Aioe.org NNTP Server
Message-ID: <tgo849$2ll$1@gioia.aioe.org>
References: <tgo7mm$1u47$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="2741"; posting-host="YN2ulY6LKp1eoOUw2OJ8ig.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: et4 - Sun, 25 Sep 2022 00:41 UTC

On 9/24/2022 5:34 PM, et4 wrote:
> I have a text entry where I want to be able to enter an arbitrary command to execute at global level with both the input command and the result written out using puts. The string to execute is sent as an arg to a procedure.
>
> I've tried several methods, using [after 0] and also [uplevel #0] and I'm stumped. I've resorted to trial and error hoping it would eventually work without success.
>
> Any ideas?
>
> In my tests, arg is
>
> $foobar + 5
>
> and foobar is global and 10, I want to have it output the result: 15
>
>
> Here are several attempts, to no avail:
>
>
> % set foobar 10
> 10
>
> ------------------------
> % proc test {arg} {
>      uplevel #0 [list puts "result of $arg is\n [list eval $arg]"]
>  }
> % test {$foobar + 5}
> result of $foobar + 5 is
>  eval {$foobar + 5}
>
> ------------------------
>
>
> % proc test {arg} {
>     uplevel #0 [list puts "result of $arg is\n [eval $arg]"]
> }
> % test {$foobar + 5}
> can't read "foobar": no such variable
>
> ------------------------
>
>
> % proc test {arg} {
>     uplevel #0 [list puts "result of $arg is\n [$arg]"]
> }
> % test {$foobar + 5}
> invalid command name "$foobar + 5"
>
> --------------------------
>
> % proc test {arg} {
>     uplevel #0 [list puts "result of $arg is\n \[list $arg\]"]
> }
>  % test {$foobar + 5}
> result of $foobar + 5 is
>  [list $foobar + 5]

In all these tests, I should have been trying:

test {expr $foobar + 5}

but it doesn't seem to work with all my attempts

Re: quoting difficulty

<b8ba5522-c916-492d-bff3-94494681dcc5n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:59c6:0:b0:35d:19f4:c1e2 with SMTP id f6-20020ac859c6000000b0035d19f4c1e2mr10892502qtf.55.1664069346717;
Sat, 24 Sep 2022 18:29:06 -0700 (PDT)
X-Received: by 2002:ae9:eb8f:0:b0:6cf:5f08:b3d2 with SMTP id
b137-20020ae9eb8f000000b006cf5f08b3d2mr10064917qkg.322.1664069346541; Sat, 24
Sep 2022 18:29:06 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 24 Sep 2022 18:29:06 -0700 (PDT)
In-Reply-To: <tgo849$2ll$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=94.143.243.19; posting-account=SKJpMwoAAAC-rOO8mAwJg3LDXYdZJvzF
NNTP-Posting-Host: 94.143.243.19
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b8ba5522-c916-492d-bff3-94494681dcc5n@googlegroups.com>
Subject: Re: quoting difficulty
From: 41r1k16@gmail.com (Ya Hu)
Injection-Date: Sun, 25 Sep 2022 01:29:06 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Ya Hu - Sun, 25 Sep 2022 01:29 UTC

воскресенье, 25 сентября 2022 г. в 03:41:49 UTC+3, et4:
> On 9/24/2022 5:34 PM, et4 wrote:
> > I have a text entry where I want to be able to enter an arbitrary command to execute at global level with both the input command and the result written out using puts. The string to execute is sent as an arg to a procedure.
> >
> > I've tried several methods, using [after 0] and also [uplevel #0] and I'm stumped. I've resorted to trial and error hoping it would eventually work without success.
> >
> > Any ideas?
> >
> > In my tests, arg is
> >
> > $foobar + 5
> >
> > and foobar is global and 10, I want to have it output the result: 15
> >
> >
> > Here are several attempts, to no avail:
> >
> >
> > % set foobar 10
> > 10
> >
> > ------------------------
> > % proc test {arg} {
> > uplevel #0 [list puts "result of $arg is\n [list eval $arg]"]
> > }
> > % test {$foobar + 5}
> > result of $foobar + 5 is
> > eval {$foobar + 5}
> >
> > ------------------------
> >
> >
> > % proc test {arg} {
> > uplevel #0 [list puts "result of $arg is\n [eval $arg]"]
> > }
> > % test {$foobar + 5}
> > can't read "foobar": no such variable
> >
> > ------------------------
> >
> >
> > % proc test {arg} {
> > uplevel #0 [list puts "result of $arg is\n [$arg]"]
> > }
> > % test {$foobar + 5}
> > invalid command name "$foobar + 5"
> >
> > --------------------------
> >
> > % proc test {arg} {
> > uplevel #0 [list puts "result of $arg is\n \[list $arg\]"]
> > }
> > % test {$foobar + 5}
> > result of $foobar + 5 is
> > [list $foobar + 5]
> In all these tests, I should have been trying:
>
>
> test {expr $foobar + 5}
>
>
> but it doesn't seem to work with all my attempts

proc t a {
set res [uplevel 1 expr [list $a]]
puts "result of \$arg is $res" ;
return $res
}

Re: quoting difficulty

<tgodoj$36rnj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sun, 25 Sep 2022 02:17:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <tgodoj$36rnj$1@dont-email.me>
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org>
Injection-Date: Sun, 25 Sep 2022 02:17:55 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="7c141a11a2d8c356857ab3dba442ab95";
logging-data="3370739"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ogwIslT+KqKmYGgJj0JpZ"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:fEHP3evo/VEwoZ0CgAAlJhW0C6k=
 by: Rich - Sun, 25 Sep 2022 02:17 UTC

et4 <tclnews@rocketship1.me> wrote:
> On 9/24/2022 5:34 PM, et4 wrote:
>> I have a text entry where I want to be able to enter an arbitrary
>> command to execute at global level with both the input command and
>> the result written out using puts. The string to execute is sent as
>> an arg to a procedure.
>>
>> I've tried several methods, using [after 0] and also [uplevel #0]
>> and I'm stumped. I've resorted to trial and error hoping it would
>> eventually work without success.
>>
>> Any ideas?
>>
>> In my tests, arg is
>>
>> $foobar + 5
>>
>> and foobar is global and 10, I want to have it output the result: 15
>
>
> In all these tests, I should have been trying:
>
> test {expr $foobar + 5}
>
> but it doesn't seem to work with all my attempts

$ rlwrap tclsh
% proc test {args} {
uplevel #0 eval {*}$args
}
% set foobar 10
10
% test {expr $foobar + 5}
15
%

But, note, you are currently walking down a path that will eventually
lead to you directly to "quoting hell"
(https://wiki.tcl-lang.org/page/Quoting+hell).

Re: quoting difficulty

<tgojq7$1a7g$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!YN2ulY6LKp1eoOUw2OJ8ig.user.46.165.242.91.POSTED!not-for-mail
From: tclnews@rocketship1.me (et4)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sat, 24 Sep 2022 21:01:10 -0700
Organization: Aioe.org NNTP Server
Message-ID: <tgojq7$1a7g$1@gioia.aioe.org>
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org>
<tgodoj$36rnj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="43248"; posting-host="YN2ulY6LKp1eoOUw2OJ8ig.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: et4 - Sun, 25 Sep 2022 04:01 UTC

On 9/24/2022 7:17 PM, Rich wrote:
> et4 <tclnews@rocketship1.me> wrote:
>> On 9/24/2022 5:34 PM, et4 wrote:
>>> I have a text entry where I want to be able to enter an arbitrary
>>> command to execute at global level with both the input command and
>>> the result written out using puts. The string to execute is sent as
>>> an arg to a procedure.
>>>
>>> I've tried several methods, using [after 0] and also [uplevel #0]
>>> and I'm stumped. I've resorted to trial and error hoping it would
>>> eventually work without success.
>>>
>>> Any ideas?
>>>
>>> In my tests, arg is
>>>
>>> $foobar + 5
>>>
>>> and foobar is global and 10, I want to have it output the result: 15
>>
>>
>> In all these tests, I should have been trying:
>>
>> test {expr $foobar + 5}
>>
>> but it doesn't seem to work with all my attempts
>
> $ rlwrap tclsh
> % proc test {args} {
> uplevel #0 eval {*}$args
> }
> % set foobar 10
> 10
> % test {expr $foobar + 5}
> 15
> %
>
> But, note, you are currently walking down a path that will eventually
> lead to you directly to "quoting hell"
> (https://wiki.tcl-lang.org/page/Quoting+hell).

Thanks Rich.

I see what you mean, I think I'm already there:

% proc test {args} {
uplevel #0 eval {*}$args
}

% test {puts hello}
hello

% test {puts "hello there"}
can not find channel named "hello"

% test {puts \"hello there\"}
hello there

% test {set foo "bar baz"}
wrong # args: should be "set varName ?newValue?"

(kits) 23 % test {set foo "bar"}
bar

This has to be do-able, since the windows console and linux interactive mode can run any arbitrary commands. I even tried a thread::send back to the main thread to see if that would work, and couldn't get to go.

I couldn't figure out how to use Ya Hu's since it only uses expr, which was only just one example. I need it to do any command, it's supposed to be like a one-line console from a text entry.

Re: quoting difficulty

<tgokgf$1gik$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.91.POSTED!not-for-mail
From: saitology9@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sun, 25 Sep 2022 00:13:02 -0400
Organization: Aioe.org NNTP Server
Message-ID: <tgokgf$1gik$1@gioia.aioe.org>
References: <tgo7mm$1u47$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="49748"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Sun, 25 Sep 2022 04:13 UTC

On 9/24/22 8:34 PM, et4 wrote:
> I have a text entry where I want to be able to enter an arbitrary
> command to execute at global level with both the input command and the
> result written out using puts. The string to execute is sent as an arg
> to a procedure.
>
> I've tried several methods, using [after 0] and also [uplevel #0] and
> I'm stumped. I've resorted to trial and error hoping it would eventually
> work without success.
>
> Any ideas?
>
> In my tests, arg is
>
> $foobar + 5
>
> and foobar is global and 10, I want to have it output the result: 15

Since you are passing full commands, how about this:

% proc test x {uplevel #0 $x}

Note that for math expressions, you will need to put them in [expr]
properly.

Re: quoting difficulty

<tgphuk$3arva$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sun, 25 Sep 2022 12:35:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <tgphuk$3arva$1@dont-email.me>
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org> <tgodoj$36rnj$1@dont-email.me> <tgojq7$1a7g$1@gioia.aioe.org>
Injection-Date: Sun, 25 Sep 2022 12:35:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="7c141a11a2d8c356857ab3dba442ab95";
logging-data="3502058"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DopL5MtQDMD0JwExY0oAH"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:I9PT0JwncHrv5SQfEA9ctlEs3Io=
 by: Rich - Sun, 25 Sep 2022 12:35 UTC

et4 <tclnews@rocketship1.me> wrote:
> On 9/24/2022 7:17 PM, Rich wrote:
>> et4 <tclnews@rocketship1.me> wrote:
>>> On 9/24/2022 5:34 PM, et4 wrote:
>>>> I have a text entry where I want to be able to enter an arbitrary
>>>> command to execute at global level with both the input command and
>>>> the result written out using puts. The string to execute is sent as
>>>> an arg to a procedure.
>
> This has to be do-able, since the windows console and linux
> interactive mode can run any arbitrary commands.

When building commands, use [list]. You should almost always use [list]
for building up commands.

Plus, with an entry (or other Tk widget) you don't have the problem of
the Tcl code parser also 'interpreting' the code, before your eval
thereof, which is what starts to generate quoting hell situations.

I.e.:

#!/usr/bin/wish

entry .e
button .b -text run -command [list button-pushed .e]
pack .e .b -side top

proc button-pushed {w} {
set cmd [$w get]
set result [run $cmd]
puts result=$result
$w delete 0 end
}

proc run {cmd} {
return [uplevel #0 [list eval $cmd]]
}

set foo 10

Then, putting this into the entry and pressing the 'run' button gives:

puts "hello foo + 5 = [expr {$foo+5}]"

this result in my rxvt window:

hello foo + 5 = 15
result=

Re: quoting difficulty

<tgq3gu$5rv$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!YN2ulY6LKp1eoOUw2OJ8ig.user.46.165.242.91.POSTED!not-for-mail
From: tclnews@rocketship1.me (et4)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sun, 25 Sep 2022 10:35:26 -0700
Organization: Aioe.org NNTP Server
Message-ID: <tgq3gu$5rv$1@gioia.aioe.org>
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org>
<tgodoj$36rnj$1@dont-email.me> <tgojq7$1a7g$1@gioia.aioe.org>
<tgphuk$3arva$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="6015"; posting-host="YN2ulY6LKp1eoOUw2OJ8ig.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: et4 - Sun, 25 Sep 2022 17:35 UTC

On 9/25/2022 5:35 AM, Rich wrote:
> et4 <tclnews@rocketship1.me> wrote:
>> On 9/24/2022 7:17 PM, Rich wrote:
>>> et4 <tclnews@rocketship1.me> wrote:
>>>> On 9/24/2022 5:34 PM, et4 wrote:
>>>>> I have a text entry where I want to be able to enter an arbitrary
>>>>> command to execute at global level with both the input command and
>>>>> the result written out using puts. The string to execute is sent as
>>>>> an arg to a procedure.
>>
>> This has to be do-able, since the windows console and linux
>> interactive mode can run any arbitrary commands.
>
> When building commands, use [list]. You should almost always use [list]
> for building up commands.
>
> Plus, with an entry (or other Tk widget) you don't have the problem of
> the Tcl code parser also 'interpreting' the code, before your eval
> thereof, which is what starts to generate quoting hell situations.
>
> I.e.:
>
> #!/usr/bin/wish
>
> entry .e
> button .b -text run -command [list button-pushed .e]
> pack .e .b -side top
>
> proc button-pushed {w} {
> set cmd [$w get]
> set result [run $cmd]
> puts result=$result
> $w delete 0 end
> }
>
> proc run {cmd} {
> return [uplevel #0 [list eval $cmd]]
> }
>
> set foo 10
>
> Then, putting this into the entry and pressing the 'run' button gives:
>
> puts "hello foo + 5 = [expr {$foo+5}]"
>
> this result in my rxvt window:
>
> hello foo + 5 = 15
> result=
>

Thanks Rich. Your example is now in my tips/tricks scrap book. Generally I do go to [list] but couldn't get the rest to work.

I've got another entry where I need to go uplevel inside a proc that issued a call to me (as a breakpoint). I'll try out your code there, though I will need to use a different uplevel. I also have an up/down/mousewheel history for the text entry and a button to repeat the last command. So, I can get the text to execute from several places.

BTW, I've got you to thank for the indirection I'm using to get the value of the textvariable (set val [set $var]) from a post of yours a year or two back.

Here's what I get now with your test case:

result for 【 set foo 10 】
【10】

result for 【 puts "hello foo + 5 = [expr {$foo+5}]" 】
hello foo + 5 = 15
【】

result for 【 puts "hello foo + 5 = [expr {$fooxx+5}]" 】
can't read "fooxx": no such variable

result for 【 puts "hello foo + 5 = [exprxxx {$foo+5}]" 】
invalid command name "exprxxx"

Re: quoting difficulty

<20220925171959.3e332113@lud1.home>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!SynNhSOhVxkQA3jiZdpSZw.user.46.165.242.75.POSTED!not-for-mail
From: no@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sun, 25 Sep 2022 17:19:59 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20220925171959.3e332113@lud1.home>
References: <tgo7mm$1u47$1@gioia.aioe.org>
<tgo849$2ll$1@gioia.aioe.org>
<tgodoj$36rnj$1@dont-email.me>
<tgojq7$1a7g$1@gioia.aioe.org>
<tgphuk$3arva$1@dont-email.me>
<tgq3gu$5rv$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="482"; posting-host="SynNhSOhVxkQA3jiZdpSZw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Sun, 25 Sep 2022 20:19 UTC

I don't understand the many suggestions of using [list] and upvar.

I have this code that works just fine:

entry $::w.frame0.aliasbox
$::w.frame0.aliasbox configure -takefocus 1
$::w.frame0.aliasbox configure -width $::ALIASWIDTH
$::w.frame0.aliasbox configure -background $::ALIASBG
$::w.frame0.aliasbox configure -foreground $::ALIASFG
$::w.frame0.aliasbox configure -textvariable ::INPUT

later on,

eval {*}$::INPUT

Note that $::INPUT may be an alias that will be resolved
by an external list... or a proc (also defined externally),
which seems to be what you want.

I never needed upvar and [list] definitely does not work
for me because it causes the entire proc and arguments
to be treated like a single block of text, as if
proc arguments were "proc arguments".

--
Luc
>>
**************************
On Sun, 25 Sep 2022 10:35:26 -0700, et4 wrote:

> On 9/25/2022 5:35 AM, Rich wrote:
> > et4 <tclnews@rocketship1.me> wrote:
> >> On 9/24/2022 7:17 PM, Rich wrote:
> >>> et4 <tclnews@rocketship1.me> wrote:
> >>>> On 9/24/2022 5:34 PM, et4 wrote:
> >>>>> I have a text entry where I want to be able to enter an
> >>>>> arbitrary command to execute at global level with both the
> >>>>> input command and the result written out using puts. The
> >>>>> string to execute is sent as an arg to a procedure.
> >>
> >> This has to be do-able, since the windows console and linux
> >> interactive mode can run any arbitrary commands.
> >
> > When building commands, use [list]. You should almost always use
> > [list] for building up commands.
> >
> > Plus, with an entry (or other Tk widget) you don't have the problem
> > of the Tcl code parser also 'interpreting' the code, before your
> > eval thereof, which is what starts to generate quoting hell
> > situations.
> >
> > I.e.:
> >
> > #!/usr/bin/wish
> >
> > entry .e
> > button .b -text run -command [list button-pushed .e]
> > pack .e .b -side top
> >
> > proc button-pushed {w} {
> > set cmd [$w get]
> > set result [run $cmd]
> > puts result=$result
> > $w delete 0 end
> > }
> >
> > proc run {cmd} {
> > return [uplevel #0 [list eval $cmd]]
> > }
> >
> > set foo 10
> >
> > Then, putting this into the entry and pressing the 'run' button
> > gives:
> >
> > puts "hello foo + 5 = [expr {$foo+5}]"
> >
> > this result in my rxvt window:
> >
> > hello foo + 5 = 15
> > result> >
>
> Thanks Rich. Your example is now in my tips/tricks scrap book.
> Generally I do go to [list] but couldn't get the rest to work.
>
> I've got another entry where I need to go uplevel inside a proc that
> issued a call to me (as a breakpoint). I'll try out your code there,
> though I will need to use a different uplevel. I also have an
> up/down/mousewheel history for the text entry and a button to repeat
> the last command. So, I can get the text to execute from several
> places.
>
> BTW, I've got you to thank for the indirection I'm using to get the
> value of the textvariable (set val [set $var]) from a post of yours a
> year or two back.
>
> Here's what I get now with your test case:
>
> result for 【 set foo 10 】
> 【10】
>
> result for 【 puts "hello foo + 5 = [expr {$foo+5}]" 】
> hello foo + 5 = 15
> 【】
>
> result for 【 puts "hello foo + 5 = [expr {$fooxx+5}]" 】
> can't read "fooxx": no such variable
>
> result for 【 puts "hello foo + 5 = [exprxxx {$foo+5}]" 】
> invalid command name "exprxxx"
>

Re: quoting difficulty

<tgqgo8$1u98$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!YN2ulY6LKp1eoOUw2OJ8ig.user.46.165.242.91.POSTED!not-for-mail
From: tclnews@rocketship1.me (et4)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Sun, 25 Sep 2022 14:21:11 -0700
Organization: Aioe.org NNTP Server
Message-ID: <tgqgo8$1u98$1@gioia.aioe.org>
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org>
<tgodoj$36rnj$1@dont-email.me> <tgojq7$1a7g$1@gioia.aioe.org>
<tgphuk$3arva$1@dont-email.me> <tgq3gu$5rv$1@gioia.aioe.org>
<20220925171959.3e332113@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="63784"; posting-host="YN2ulY6LKp1eoOUw2OJ8ig.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: et4 - Sun, 25 Sep 2022 21:21 UTC

On 9/25/2022 1:19 PM, Luc wrote:
> I don't understand the many suggestions of using [list] and upvar.
>
> I have this code that works just fine:
>
> entry $::w.frame0.aliasbox
> $::w.frame0.aliasbox configure -takefocus 1
> $::w.frame0.aliasbox configure -width $::ALIASWIDTH
> $::w.frame0.aliasbox configure -background $::ALIASBG
> $::w.frame0.aliasbox configure -foreground $::ALIASFG
> $::w.frame0.aliasbox configure -textvariable ::INPUT
>
> later on,
>
> eval {*}$::INPUT
>
> Note that $::INPUT may be an alias that will be resolved
> by an external list... or a proc (also defined externally),
> which seems to be what you want.
>
> I never needed upvar and [list] definitely does not work
> for me because it causes the entire proc and arguments
> to be treated like a single block of text, as if
> proc arguments were "proc arguments".
>
>

But where is your eval running, i.e. is it at global level or from within a proc, or even a proc called by another a proc?

In my case with this posting I wanted it to run in global context, hence the uplevel #0. An after 0 would also run in global context.

In my other case, I need uplevel 1 to access locals in the proc that called me. The text entry lets me run any command at all inside the waiting proc.

With both uplevel and after, there's generally some tricky quoting stuff needed, and often [list] is the right approach. But even then, it can still be tricky, as this thread has shown.

Re: quoting difficulty

<ygasfkeblb1.fsf@akutech.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Mon, 26 Sep 2022 10:18:42 +0200
Lines: 10
Message-ID: <ygasfkeblb1.fsf@akutech.de>
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org>
<tgodoj$36rnj$1@dont-email.me> <tgojq7$1a7g$1@gioia.aioe.org>
<tgphuk$3arva$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net cGHs7KRZM8AjsXr2zR3H/QIFi+2W/WbmFm3/UO3ZDH2rgWkg0=
Cancel-Lock: sha1:/3egy5bqsFzuX96nIRDibgGFaeg= sha1:JEf5xboef9gpndetdvWJQVpmdRE=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)
 by: Ralf Fassel - Mon, 26 Sep 2022 08:18 UTC

* Rich <rich@example.invalid>
| return [uplevel #0 [list eval $cmd]]

Since [uplevel] does an eval on it's own, wouldn't

return [uplevel #0 $cmd]

be the same?

R'

Re: quoting difficulty

<tgt19s$3qkkm$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: quoting difficulty
Date: Mon, 26 Sep 2022 20:15:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <tgt19s$3qkkm$1@dont-email.me>
References: <tgo7mm$1u47$1@gioia.aioe.org> <tgo849$2ll$1@gioia.aioe.org> <tgodoj$36rnj$1@dont-email.me> <tgojq7$1a7g$1@gioia.aioe.org> <tgphuk$3arva$1@dont-email.me> <ygasfkeblb1.fsf@akutech.de>
Injection-Date: Mon, 26 Sep 2022 20:15:56 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="6d4c8dca26b60617d0fd1cc98ad2360a";
logging-data="4018838"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5SfbKkV4s1v7+Fa8fGoU8"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:Pq74XMq3jFZhzqxaowebdX8QdnE=
 by: Rich - Mon, 26 Sep 2022 20:15 UTC

Ralf Fassel <ralfixx@gmx.de> wrote:
> * Rich <rich@example.invalid>
> | return [uplevel #0 [list eval $cmd]]
>
> Since [uplevel] does an eval on it's own, wouldn't
>
> return [uplevel #0 $cmd]
>
> be the same?

Yeah, it would. No need for wrapping in 'list' in that case.


devel / comp.lang.tcl / Re: quoting difficulty

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor