Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Power is danger. -- The Centurion, "Balance of Terror", stardate 1709.2


devel / comp.lang.tcl / Re: Recommended way to import files?

SubjectAuthor
* Recommended way to import files?Mark
`* Re: Recommended way to import files?Ralf Fassel
 `* Re: Recommended way to import files?Mark
  +* Re: Recommended way to import files?Mark
  |`* Re: Recommended way to import files?Mark
  | `* Re: Recommended way to import files?Rich
  |  `* Re: Recommended way to import files?Schelte
  |   `- Re: Recommended way to import files?Rich
  `- Re: Recommended way to import files?Ralf Fassel

1
Recommended way to import files?

<6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:190c:b0:75b:2c31:8f74 with SMTP id bj12-20020a05620a190c00b0075b2c318f74mr2251167qkb.8.1685606095834;
Thu, 01 Jun 2023 00:54:55 -0700 (PDT)
X-Received: by 2002:a05:622a:1a18:b0:3f4:d2e4:3a71 with SMTP id
f24-20020a05622a1a1800b003f4d2e43a71mr2306265qtb.13.1685606095636; Thu, 01
Jun 2023 00:54:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 1 Jun 2023 00:54:55 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=31.125.17.241; posting-account=C1gZvwoAAAAojE_ZgHdwZjGSuZg6QpNd
NNTP-Posting-Host: 31.125.17.241
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com>
Subject: Recommended way to import files?
From: m.n.summerfield@googlemail.com (Mark)
Injection-Date: Thu, 01 Jun 2023 07:54:55 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: Mark - Thu, 1 Jun 2023 07:54 UTC

Suppose I have a project:

app.tcl
liba.tcl
libb.tcl

and in app.tcl I use functions from liba.tcl and libb.tcl (in namespaces liba:: and libb:: respectively).

Is there a standard recommended way to import these files?

At the moment I do this (in app.tcl):

set name [info script]
if {[file type $name] == "link"} {
set name [file readlink $name]
} set ::APP_PATH [file normalize [file dirname $name]]

foreach filename {
liba.tcl
liba.tcl
} {
source -encoding utf-8 $::APP_PATH/$filename
}

But this seems a bit cumbersome.

Re: Recommended way to import files?

<ygamt1jbm39.fsf@akutech.de>

  copy mid

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

  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: Recommended way to import files?
Date: Thu, 01 Jun 2023 10:52:58 +0200
Lines: 37
Message-ID: <ygamt1jbm39.fsf@akutech.de>
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net QyxgOFeDbBlk21U/rU4B6gKMw9fAATPNJmKTzNImqUlHraXr8=
Cancel-Lock: sha1:g8xzM0eqWYiKC2EE1aDLSUVkc+Q= sha1:YXikHoFmp0bFB+XHdRraJyYu838=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Thu, 1 Jun 2023 08:52 UTC

* Mark <m.n.summerfield@googlemail.com>
| Suppose I have a project:
>
| app.tcl
| liba.tcl
| libb.tcl
>
| and in app.tcl I use functions from liba.tcl and libb.tcl (in
| namespaces liba:: and libb:: respectively).
>
| Is there a standard recommended way to import these files?

I think I would make liba and libb packages:

- liba.tcl
package provide liba 1.0

- libb.tcl
package provide libb 1.0

- new file: pkgIndex.tcl
package ifneeded liba 1.0 [list source -encoding utf-8 [file join $dir liba.tcl]]
package ifneeded libb 1.0 [list source -encoding utf-8 [file join $dir libb.tcl]]

- app.tcl
# optional (if not installed in auto_path)
lappend auto_path [file dirname [info script]]
# load liba and libb
package require liba
package require libb

If 'liba' and 'libb' are not only short versions for demo purposes,
maybe it would be a good idea to name the packages with some prefix
(app_liba etc), since plain 'liba' and 'libb' are rather generic...

HTH
R'

Re: Recommended way to import files?

<3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:1a28:b0:75b:2dd1:9835 with SMTP id bk40-20020a05620a1a2800b0075b2dd19835mr2624375qkb.3.1685611309141;
Thu, 01 Jun 2023 02:21:49 -0700 (PDT)
X-Received: by 2002:a05:6214:5651:b0:623:85e7:434d with SMTP id
mh17-20020a056214565100b0062385e7434dmr1256666qvb.6.1685611308932; Thu, 01
Jun 2023 02:21:48 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 1 Jun 2023 02:21:48 -0700 (PDT)
In-Reply-To: <ygamt1jbm39.fsf@akutech.de>
Injection-Info: google-groups.googlegroups.com; posting-host=31.125.17.241; posting-account=C1gZvwoAAAAojE_ZgHdwZjGSuZg6QpNd
NNTP-Posting-Host: 31.125.17.241
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com> <ygamt1jbm39.fsf@akutech.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com>
Subject: Re: Recommended way to import files?
From: m.n.summerfield@googlemail.com (Mark)
Injection-Date: Thu, 01 Jun 2023 09:21:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 41
 by: Mark - Thu, 1 Jun 2023 09:21 UTC

On Thursday, June 1, 2023 at 9:53:03 AM UTC+1, Ralf Fassel wrote:
> * Mark <m.n.sum...@googlemail.com>
> | Suppose I have a project:
> >
> | app.tcl
> | liba.tcl
> | libb.tcl
> >
> | and in app.tcl I use functions from liba.tcl and libb.tcl (in
> | namespaces liba:: and libb:: respectively).
> >
> | Is there a standard recommended way to import these files?
> I think I would make liba and libb packages:
>
> - liba.tcl
> package provide liba 1.0
>
> - libb.tcl
> package provide libb 1.0
>
> - new file: pkgIndex.tcl
> package ifneeded liba 1.0 [list source -encoding utf-8 [file join $dir liba.tcl]]
> package ifneeded libb 1.0 [list source -encoding utf-8 [file join $dir libb.tcl]]
>
> - app.tcl
> # optional (if not installed in auto_path)
> lappend auto_path [file dirname [info script]]
> # load liba and libb
> package require liba
> package require libb
>
> If 'liba' and 'libb' are not only short versions for demo purposes,
> maybe it would be a good idea to name the packages with some prefix
> (app_liba etc), since plain 'liba' and 'libb' are rather generic...
>
> HTH
> R'

Thanks. Although it actually seems more involved that what I've been doing.
Also, in pkgIndex.tcl where does $dir's value come from?

Re: Recommended way to import files?

<76ee7fea-ccbb-412c-b220-d33971d94775n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:b28:b0:626:13bf:f399 with SMTP id w8-20020a0562140b2800b0062613bff399mr142403qvj.3.1685616566110;
Thu, 01 Jun 2023 03:49:26 -0700 (PDT)
X-Received: by 2002:a05:6214:192f:b0:626:1d5f:359e with SMTP id
es15-20020a056214192f00b006261d5f359emr1277092qvb.3.1685616565925; Thu, 01
Jun 2023 03:49:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.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: Thu, 1 Jun 2023 03:49:25 -0700 (PDT)
In-Reply-To: <3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=31.125.17.241; posting-account=C1gZvwoAAAAojE_ZgHdwZjGSuZg6QpNd
NNTP-Posting-Host: 31.125.17.241
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com>
<ygamt1jbm39.fsf@akutech.de> <3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <76ee7fea-ccbb-412c-b220-d33971d94775n@googlegroups.com>
Subject: Re: Recommended way to import files?
From: m.n.summerfield@googlemail.com (Mark)
Injection-Date: Thu, 01 Jun 2023 10:49:26 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mark - Thu, 1 Jun 2023 10:49 UTC

Splitting an application into multiple files must surely be a common requirement (and common practice). So I'm assuming that how to do this is documented. But where?

Re: Recommended way to import files?

<04705bdd-8e4a-4ae9-b173-99bf1b48f85dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:448b:b0:75b:27ee:9334 with SMTP id x11-20020a05620a448b00b0075b27ee9334mr2431180qkp.6.1685617851187;
Thu, 01 Jun 2023 04:10:51 -0700 (PDT)
X-Received: by 2002:a05:620a:1709:b0:75c:b403:264 with SMTP id
az9-20020a05620a170900b0075cb4030264mr2706040qkb.4.1685617851000; Thu, 01 Jun
2023 04:10:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.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: Thu, 1 Jun 2023 04:10:50 -0700 (PDT)
In-Reply-To: <76ee7fea-ccbb-412c-b220-d33971d94775n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=31.125.17.241; posting-account=C1gZvwoAAAAojE_ZgHdwZjGSuZg6QpNd
NNTP-Posting-Host: 31.125.17.241
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com>
<ygamt1jbm39.fsf@akutech.de> <3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com>
<76ee7fea-ccbb-412c-b220-d33971d94775n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <04705bdd-8e4a-4ae9-b173-99bf1b48f85dn@googlegroups.com>
Subject: Re: Recommended way to import files?
From: m.n.summerfield@googlemail.com (Mark)
Injection-Date: Thu, 01 Jun 2023 11:10:51 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2088
 by: Mark - Thu, 1 Jun 2023 11:10 UTC

Anyway, here's the structure I'm using and which seems to work based on your advice.

# file: pkgIndex.tcl
set dir [file dirname [info script]]
package ifneeded app 1.0 [list source -encoding utf-8 [file join $dir app.tcl]]
package ifneeded util 1.0 [list source -encoding utf-8 [file join $dir util.tcl]]

# file: myapp.tcl # this is the file that's to be invoked, e.g., ./myapp.tcl
lappend auto_path [file dirname [info script]]
package require app
app::main

# file: app.tcl
package provide app 1.0
package require util
namespace eval app {}

proc app::main {} {
puts "app.tcl main [util::commas 1234567890]"
}

# file: util.tcl
package provide util 1.0
namespace eval util {}

proc util::commas {x} {
regsub -all \\d(?=(\\d{3})+([regexp -inline {\.\d*$} $x]$)) $x {\0,}
}

Re: Recommended way to import files?

<u5a56r$2pukr$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Recommended way to import files?
Date: Thu, 1 Jun 2023 13:07:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <u5a56r$2pukr$1@dont-email.me>
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com> <ygamt1jbm39.fsf@akutech.de> <3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com> <76ee7fea-ccbb-412c-b220-d33971d94775n@googlegroups.com> <04705bdd-8e4a-4ae9-b173-99bf1b48f85dn@googlegroups.com>
Injection-Date: Thu, 1 Jun 2023 13:07:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2e1b42c0ffb3bcc398f181960b2d840e";
logging-data="2947739"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+5oE+8U3wdsGSIZVTvcpmt"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.19 (x86_64))
Cancel-Lock: sha1:UKBZd7lpEcPUdvZ4zsOqbAj8ZW4=
 by: Rich - Thu, 1 Jun 2023 13:07 UTC

Mark <m.n.summerfield@googlemail.com> wrote:
> Anyway, here's the structure I'm using and which seems to work based
> on your advice.
>

If you are willing to restrict your filenames to a particular pattern,
the module system is even easier to use than creating 'packages'.

man tm

for the manpage on the module system.

You'd name the files

liba-1.0.0.tm
libb-1.0.0.tm

And include a "package provide" with the same version number inside.

And in your app.tcl you'd tell tm where to search:

tcl::tm::path add [file dirname [info script]]

And then you can just do:

package require liba
package require libb

in app.tcl to pull both in.

Re: Recommended way to import files?

<nnd$6d1f5eb5$4c94a4ba@9ad37996d1fc318a>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Date: Thu, 1 Jun 2023 15:25:47 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Subject: Re: Recommended way to import files?
Newsgroups: comp.lang.tcl
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com>
<ygamt1jbm39.fsf@akutech.de>
<3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com>
<76ee7fea-ccbb-412c-b220-d33971d94775n@googlegroups.com>
<04705bdd-8e4a-4ae9-b173-99bf1b48f85dn@googlegroups.com>
<u5a56r$2pukr$1@dont-email.me>
Content-Language: en-US
From: nospam@wanadoo.nl (Schelte)
In-Reply-To: <u5a56r$2pukr$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$6d1f5eb5$4c94a4ba@9ad37996d1fc318a>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!news-2.dfn.de!news-1.dfn.de!news.dfn.de!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 11
Injection-Date: Thu, 01 Jun 2023 15:25:47 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1443
 by: Schelte - Thu, 1 Jun 2023 13:25 UTC

On 01/06/2023 15:07, Rich wrote:
> And include a "package provide" with the same version number inside.

That would be redundant, because the version number is already specified
in the file name and Tcl will pick it up from there. So there is no need
to include a "package provide" command in a module code.

Schelte.

Re: Recommended way to import files?

<u5a86c$2q8mj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Recommended way to import files?
Date: Thu, 1 Jun 2023 13:58:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <u5a86c$2q8mj$1@dont-email.me>
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com> <ygamt1jbm39.fsf@akutech.de> <3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com> <76ee7fea-ccbb-412c-b220-d33971d94775n@googlegroups.com> <04705bdd-8e4a-4ae9-b173-99bf1b48f85dn@googlegroups.com> <u5a56r$2pukr$1@dont-email.me> <nnd$6d1f5eb5$4c94a4ba@9ad37996d1fc318a>
Injection-Date: Thu, 1 Jun 2023 13:58:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2e1b42c0ffb3bcc398f181960b2d840e";
logging-data="2958035"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sTU0rbbuguKZ6HMojQwKK"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.19 (x86_64))
Cancel-Lock: sha1:QcnZROLqDLaqpf1cRaJ/cV499ow=
 by: Rich - Thu, 1 Jun 2023 13:58 UTC

Schelte <nospam@wanadoo.nl> wrote:
> On 01/06/2023 15:07, Rich wrote:
>> And include a "package provide" with the same version number inside.
>
> That would be redundant, because the version number is already
> specified in the file name and Tcl will pick it up from there. So
> there is no need to include a "package provide" command in a module
> code.

Hmm, learn something new every day.

I've been adding 'package provide #' commands that I didn't need to
add. Now I know to stop doing that for modules.

Re: Recommended way to import files?

<ygailc7b570.fsf@akutech.de>

  copy mid

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

  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: Recommended way to import files?
Date: Thu, 01 Jun 2023 16:57:55 +0200
Lines: 16
Message-ID: <ygailc7b570.fsf@akutech.de>
References: <6297bbd3-edcf-4ecf-8b0b-de043a6e29c0n@googlegroups.com>
<ygamt1jbm39.fsf@akutech.de>
<3d8317a8-d1b2-4b2c-8f19-b87e4ed48fcen@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net C5Im+TlRZTazcjU06Wc8zw5sdKFc3QhmXu+Iz9aGbxhEF7CQg=
Cancel-Lock: sha1:cYgqczeZfbCfDre0DK5Lu/b/bBo= sha1:LUJvlfNFUERf+H0n65n3Yv7rn7s=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Thu, 1 Jun 2023 14:57 UTC

* Mark <m.n.summerfield@googlemail.com>
| On Thursday, June 1, 2023 at 9:53:03 AM UTC+1, Ralf Fassel wrote:
| > * Mark <m.n.sum...@googlemail.com>
| > - new file: pkgIndex.tcl
| > package ifneeded liba 1.0 [list source -encoding utf-8 [file join $dir liba.tcl]]
| > package ifneeded libb 1.0 [list source -encoding utf-8 [file join $dir libb.tcl]]
--<snip-snip>--
| Also, in pkgIndex.tcl where does $dir's value come from?

$dir is automatically provided by the mechanism which loads the
pkgIndex.tcl. If you look into other pkgIndexes (eg. from tcllib),
you'll see that they don't set 'dir' either.
You should omit that line from your pkgIndex.tcl.

HTH
R'


devel / comp.lang.tcl / Re: Recommended way to import files?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor