Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Gort, klaatu nikto barada." -- The Day the Earth Stood Still


devel / comp.lang.tcl / Passing parameters to procedure

SubjectAuthor
* Passing parameters to proceduresnosniv
+- Passing parameters to procedureRich
`- Passing parameters to procedureRobert Heller

1
Passing parameters to procedure

<2da0be59-7939-42a3-922c-6e8e009f176dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a0c:b213:0:b0:56e:aa1e:1c63 with SMTP id x19-20020a0cb213000000b0056eaa1e1c63mr369434qvd.45.1676726659187;
Sat, 18 Feb 2023 05:24:19 -0800 (PST)
X-Received: by 2002:a5b:88a:0:b0:897:b93b:41c8 with SMTP id
e10-20020a5b088a000000b00897b93b41c8mr1592562ybq.64.1676726658788; Sat, 18
Feb 2023 05:24:18 -0800 (PST)
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: Sat, 18 Feb 2023 05:24:18 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=82.1.128.13; posting-account=gstOigoAAADV9pmzZL58qQ436SKV3SBu
NNTP-Posting-Host: 82.1.128.13
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2da0be59-7939-42a3-922c-6e8e009f176dn@googlegroups.com>
Subject: Passing parameters to procedure
From: nivpars...@gmail.com (snosniv)
Injection-Date: Sat, 18 Feb 2023 13:24:19 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2764
 by: snosniv - Sat, 18 Feb 2023 13:24 UTC

I generate a set of entry widgets & checkboxes as below:

##-----------------------------------------------------------------------------
## Labels & Entry for MultiBlock Rows 1 to 10
##-----------------------------------------------------------------------------
## Grid placement for all the rows
##-----------------------------------------------------------------------------
for {set xxx 0} {$xxx < 10} {incr xxx} {

label $f4a.lb_TIM_$xxx -text "Time" -font {Arial 8 bold} -background white -foreground black
label $f4a.lb_SPC_$xxx -text " " -font {Arial 8 bold}
entry $f4a.enMINS_$xxx -textvar MB_mins_$xxx -width 2 -validate all -vcmd {ValidInt %P}
entry $f4a.enSECS_$xxx -textvar MB_secs_$xxx -width 2 -validate all -vcmd {ValidInt %P}
entry $f4a.enPWR_$xxx -textvar MB_power_$xxx -width 3 -validate all -vcmd {ValidInt %P}
entry $f4a.enCAD_$xxx -textvar MB_cad_$xxx -width 3 -validate all -vcmd {ValidInt %P}
checkbutton $f4a.cbSEL_$xxx -var MB_sel_$xxx -background white -foreground red

grid $f4a.lb_TIM_$xxx -row [expr $xxx + 1] -column 0
grid $f4a.enMINS_$xxx -row [expr $xxx + 1] -column 1
grid $f4a.lb_SPC_$xxx -row [expr $xxx + 1] -column 2
grid $f4a.enSECS_$xxx -row [expr $xxx + 1] -column 3
grid $f4a.enPWR_$xxx -row [expr $xxx + 1] -column 4
grid $f4a.enCAD_$xxx -row [expr $xxx + 1] -column 5
grid $f4a.cbSEL_$xxx -row [expr $xxx + 1] -column 6
}

All that works fine, generating 10 rows each with 4 entries & a checkbox, so 50 data points.
I cannot see to pass all that info to the procedure that works on the data except to pass all 50 individually, which is not great & pretty inelegant!

Is there a nice clean way to pass the data to the proc?

TIA, Kev P.

Re: Passing parameters to procedure

<tsqo57$1o00$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Passing parameters to procedure
Date: Sat, 18 Feb 2023 14:42:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <tsqo57$1o00$1@dont-email.me>
References: <2da0be59-7939-42a3-922c-6e8e009f176dn@googlegroups.com>
Injection-Date: Sat, 18 Feb 2023 14:42:48 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="61b097a8d4dbc1cecf96201d44eed020";
logging-data="57344"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+I+OUSB1Yf2QYjZZJn9tSE"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:+R9sM6uvQxJhlr+p1e3ETdGxnno=
 by: Rich - Sat, 18 Feb 2023 14:42 UTC

snosniv <nivparsons@gmail.com> wrote:
> All that works fine, generating 10 rows each with 4 entries & a
> checkbox, so 50 data points. I cannot see to pass all that info to
> the procedure that works on the data except to pass all 50
> individually, which is not great & pretty inelegant!
>
> Is there a nice clean way to pass the data to the proc?

A list of 50 elements.

A nested list of four columns, each containing ten rows.

A Tcllib matrix of 10x4 (or 4x10) elements (man matrix).

Re: Passing parameters to procedure

<GIidnaWLj659eW3-nZ2dnZfqn_WdnZ2d@giganews.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!69.80.99.23.MISMATCH!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 18 Feb 2023 14:46:56 +0000
MIME-Version: 1.0
From: hel...@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.15)
Subject: Re: Passing parameters to procedure
In-Reply-To: <2da0be59-7939-42a3-922c-6e8e009f176dn@googlegroups.com>
References: <2da0be59-7939-42a3-922c-6e8e009f176dn@googlegroups.com>
Newsgroups: comp.lang.tcl
Content-Type: text/plain; charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <GIidnaWLj659eW3-nZ2dnZfqn_WdnZ2d@giganews.com>
Date: Sat, 18 Feb 2023 14:46:56 +0000
Lines: 87
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-xxOHFUya3uWpdNBd3FQlc5v5C1lqTux9dCklqugqVrA6p3OndedSegu0UilKM0gwGug6I6IglXykYUK!ldhWLRA+QsZU+G5Y9WWDcmxFb0uztY8oxLPjzWyo/JffOPBJJbKhaSp2GzanFPaUMbyy84zbXSmf!mXM=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Received-Bytes: 5325
 by: Robert Heller - Sat, 18 Feb 2023 14:46 UTC

At Sat, 18 Feb 2023 05:24:18 -0800 (PST) snosniv <nivparsons@gmail.com> wrote:

>
> I generate a set of entry widgets & checkboxes as below:
>
> ##-----------------------------------------------------------------------------
> ## Labels & Entry for MultiBlock Rows 1 to 10
> ##-----------------------------------------------------------------------------
> ## Grid placement for all the rows
> ##-----------------------------------------------------------------------------
> for {set xxx 0} {$xxx < 10} {incr xxx} {
>
> label $f4a.lb_TIM_$xxx -text "Time" -font {Arial 8 bold} -background white -foreground black
> label $f4a.lb_SPC_$xxx -text " " -font {Arial 8 bold}
> entry $f4a.enMINS_$xxx -textvar MB_mins_$xxx -width 2 -validate all -vcmd {ValidInt %P}
> entry $f4a.enSECS_$xxx -textvar MB_secs_$xxx -width 2 -validate all -vcmd {ValidInt %P}
> entry $f4a.enPWR_$xxx -textvar MB_power_$xxx -width 3 -validate all -vcmd {ValidInt %P}
> entry $f4a.enCAD_$xxx -textvar MB_cad_$xxx -width 3 -validate all -vcmd {ValidInt %P}
> checkbutton $f4a.cbSEL_$xxx -var MB_sel_$xxx -background white -foreground red
>
>
> grid $f4a.lb_TIM_$xxx -row [expr $xxx + 1] -column 0
> grid $f4a.enMINS_$xxx -row [expr $xxx + 1] -column 1
> grid $f4a.lb_SPC_$xxx -row [expr $xxx + 1] -column 2
> grid $f4a.enSECS_$xxx -row [expr $xxx + 1] -column 3
> grid $f4a.enPWR_$xxx -row [expr $xxx + 1] -column 4
> grid $f4a.enCAD_$xxx -row [expr $xxx + 1] -column 5
> grid $f4a.cbSEL_$xxx -row [expr $xxx + 1] -column 6
> }
>
> All that works fine, generating 10 rows each with 4 entries & a checkbox, so 50 data points.
> I cannot see to pass all that info to the procedure that works on the data except to pass all 50 individually, which is not great & pretty inelegant!
>
> Is there a nice clean way to pass the data to the proc?

All of the data is already in 50 global variables (that is what the
-textvariable and -variable options do). You don't really need to "pass"
anything at all -- the proc can just do something like:

proc process {} {
for {set xxx 0} {$xxx < 10} {incr xxx} {
global MB_mins_$xxx MB_secs_$xxx MB_power_$xxx MB_cad_$xxx MB_sel_$xxx
}

# processing here, accessing MB_mins_0 ... MB_mins_9, MB_secs_0 ...
# MB_secs_9, MB_power_0 ... MB_power_9, MB_cad_0 ... MB_cad_9, and MB_sel_0
# ... MB_sel_9 as needed.
}

Note: rather then use 50 "uniquely" named globals, using a single global array
might be better and easier to deal with (avoids having to deal with
dereferencing generated variable names).

entry $f4a.enMINS_$xxx -textvar data(MB_mins,$xxx) -width 2 -validate all -vcmd {ValidInt %P}
entry $f4a.enSECS_$xxx -textvar data(MB_secs,$xxx) -width 2 -validate all -vcmd {ValidInt %P}
entry $f4a.enPWR_$xxx -textvar data(MB_power,$xxx) -width 3 -validate all -vcmd {ValidInt %P}
entry $f4a.enCAD_$xxx -textvar data(MB_cad,$xxx) -width 3 -validate all -vcmd {ValidInt %P}
checkbutton $f4a.cbSEL_$xxx -var data(MB_sel,$xxx) -background white -foreground red

Then your processing proc would look like:

proc process {} {
global data

# Data accessed as:
#
# data(MB_mins,0), data(MB_mins,1), ... data(MB_mins,9)
# data(MB_secs,0), data(MB_secs,1), ... data(MB_secs,9)
# data(MB_power,0), data(MB_power,1), ... data(MB_power,9)
# data(MB_cad,0), data(MB_cad,1), ... data(MB_cad,9)
# data(MB_sel,0), data(MB_sel,1), ... data(MB_sel,9)

}

>
> TIA, Kev P.
>
>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor