Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Send lawyers, guns and money..." -- Lyrics from a Warren Zevon song


devel / comp.lang.tcl / Re: Sourcing another Tcl file

SubjectAuthor
* Sourcing another Tcl filesnosniv
+* Sourcing another Tcl fileRich
|`- Sourcing another Tcl fileMole Cool
+* Sourcing another Tcl fileHarald Oehlmann
|`* Sourcing another Tcl filesnosniv
| `- Sourcing another Tcl fileHarald Oehlmann
`- Sourcing another Tcl fileet4

1
Sourcing another Tcl file

<72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:1cc7:b0:4af:6573:c056 with SMTP id g7-20020a0562141cc700b004af6573c056mr44552186qvd.103.1667828329305;
Mon, 07 Nov 2022 05:38:49 -0800 (PST)
X-Received: by 2002:ad4:5963:0:b0:4bc:1a6b:2011 with SMTP id
eq3-20020ad45963000000b004bc1a6b2011mr27589980qvb.79.1667828329084; Mon, 07
Nov 2022 05:38:49 -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: Mon, 7 Nov 2022 05:38:48 -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: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com>
Subject: Sourcing another Tcl file
From: nivpars...@gmail.com (snosniv)
Injection-Date: Mon, 07 Nov 2022 13:38:49 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1567
 by: snosniv - Mon, 7 Nov 2022 13:38 UTC

I have a set of files which break up my program into sections, such as GUI, tooltips, procedures etc.
The GUI interface is my main program from which I want to source the other Tcl programs, all in the same directory.
Obviously I can use: cd C:/dir/dir.... and then just use source <file>

BUT, I'd like to be able to do this from whatever directory the files all happen to be in, so I need a generic way of "cd-ing" to the dir wherever it is.

I thought something like set x [pwd]
then... cd $x would work? Apparently not.

Windows 10 PC if that makes a difference.

TIA, Kev P.

Re: Sourcing another Tcl file

<tkb2rn$3jida$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Sourcing another Tcl file
Date: Mon, 7 Nov 2022 13:57:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <tkb2rn$3jida$1@dont-email.me>
References: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com>
Injection-Date: Mon, 7 Nov 2022 13:57:11 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="872722aabccfe5c836ffe17b60cbb5ca";
logging-data="3787178"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/h7afRbsN+rDueE+JvGKzs"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:+ofCO9hPQ2S5q0zkdGlnEjAZ2k4=
 by: Rich - Mon, 7 Nov 2022 13:57 UTC

snosniv <nivparsons@gmail.com> wrote:
> I have a set of files which break up my program into sections, such
> as GUI, tooltips, procedures etc. The GUI interface is my main
> program from which I want to source the other Tcl programs, all in
> the same directory. Obviously I can use: cd C:/dir/dir.... and then
> just use source <file>
>
> BUT, I'd like to be able to do this from whatever directory the files
> all happen to be in, so I need a generic way of "cd-ing" to the dir
> wherever it is.
>
> I thought something like set x [pwd]
> then... cd $x would work? Apparently not.
>
> Windows 10 PC if that makes a difference.

If all the ancillary files are in the same directory as the main
script, you can use [file dirname], [file join] and [info script] to
find and source them.

[info script] gives you the location and name of the script. You then
need to use [file dirname] to extract just the path component. Then
file join that path to each script file name:

set srcpath [file dirname [info script]]

source [file join $srcpath aux1.tcl]
source [file join $srcpath aux2.tcl]

...

Re: Sourcing another Tcl file

<tkb35o$3i4eu$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Sourcing another Tcl file
Date: Mon, 7 Nov 2022 15:02:32 +0100
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <tkb35o$3i4eu$1@dont-email.me>
References: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 7 Nov 2022 14:02:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="2843aac443762a7eaff6ad9bb58128da";
logging-data="3740126"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UlhyH1pdVCmOQWRmJf7mc"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:0XXWQlmfFkG5PP/n8oJgAP+nVpM=
In-Reply-To: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com>
Content-Language: en-GB
 by: Harald Oehlmann - Mon, 7 Nov 2022 14:02 UTC

Am 07.11.2022 um 14:38 schrieb snosniv:
> I have a set of files which break up my program into sections, such as GUI, tooltips, procedures etc.
> The GUI interface is my main program from which I want to source the other Tcl programs, all in the same directory.
> Obviously I can use: cd C:/dir/dir.... and then just use source <file>
>
> BUT, I'd like to be able to do this from whatever directory the files all happen to be in, so I need a generic way of "cd-ing" to the dir wherever it is.
>
> I thought something like set x [pwd]
> then... cd $x would work? Apparently not.
>
> Windows 10 PC if that makes a difference.
>
> TIA, Kev P.

Dear Key,

the normal way to organize this is to use packages, namespaces and a
pckIndex.tcl file.
Then, you put your folder with the pckIndex.tcl file into your auto_path
search list.
There is a couple of explanation required here and Ashoks book may help
to get the basics.

What I do:
- my program has a main folder, which is relative to the start script.
- Say, your start script is somewhere, and all other folders are in
subfolder "lib".
- So add in the start script:

lappend auto_path [file join [file dirname [info script]] lib]

This command will automatically cause a scan for pckIndex.tcl files in
the given folder and all direct sub-folders.

The pckIndex.tcl file has an entry for each package in the same folder,
like this:
-pckIndex.tcl---
package ifneeded tools 1.0 [list source -encoding utf-8\
[file join $dir tools.tcl]]
-EOF-
A package "tools" with Version 1.0 is in the file tools.tcl

-tools.tcl- has the following
package provide tools 1.0
% program code
-EOF-

And the start script does this to load the package:
package require tools

It is common, that the package tools will reside in the namespace "tools".

If you have any other packages (3rd party), just put them also in your
lib folder and get them by package require.

Sorry, this does not answer your question directly,
Harald

Re: Sourcing another Tcl file

<4abedc3e-aca7-42c6-b2e5-32188489565dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:c21:b0:4bb:9fea:f545 with SMTP id a1-20020a0562140c2100b004bb9feaf545mr44768462qvd.73.1667830704292;
Mon, 07 Nov 2022 06:18:24 -0800 (PST)
X-Received: by 2002:a05:6214:5004:b0:4bb:f292:6fbc with SMTP id
jo4-20020a056214500400b004bbf2926fbcmr38968160qvb.53.1667830703970; Mon, 07
Nov 2022 06:18:23 -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: Mon, 7 Nov 2022 06:18:23 -0800 (PST)
In-Reply-To: <tkb35o$3i4eu$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=82.1.128.13; posting-account=gstOigoAAADV9pmzZL58qQ436SKV3SBu
NNTP-Posting-Host: 82.1.128.13
References: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com> <tkb35o$3i4eu$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4abedc3e-aca7-42c6-b2e5-32188489565dn@googlegroups.com>
Subject: Re: Sourcing another Tcl file
From: nivpars...@gmail.com (snosniv)
Injection-Date: Mon, 07 Nov 2022 14:18:24 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3502
 by: snosniv - Mon, 7 Nov 2022 14:18 UTC

On Monday, 7 November 2022 at 14:02:54 UTC, Harald Oehlmann wrote:
> Am 07.11.2022 um 14:38 schrieb snosniv:
> > I have a set of files which break up my program into sections, such as GUI, tooltips, procedures etc.
> > The GUI interface is my main program from which I want to source the other Tcl programs, all in the same directory.
> > Obviously I can use: cd C:/dir/dir.... and then just use source <file>
> >
> > BUT, I'd like to be able to do this from whatever directory the files all happen to be in, so I need a generic way of "cd-ing" to the dir wherever it is.
> >
> > I thought something like set x [pwd]
> > then... cd $x would work? Apparently not.
> >
> > Windows 10 PC if that makes a difference.
> >
> > TIA, Kev P.
> Dear Key,
>
> the normal way to organize this is to use packages, namespaces and a
> pckIndex.tcl file.
> Then, you put your folder with the pckIndex.tcl file into your auto_path
> search list.
> There is a couple of explanation required here and Ashoks book may help
> to get the basics.
>
> What I do:
> - my program has a main folder, which is relative to the start script.
> - Say, your start script is somewhere, and all other folders are in
> subfolder "lib".
> - So add in the start script:
>
> lappend auto_path [file join [file dirname [info script]] lib]
>
> This command will automatically cause a scan for pckIndex.tcl files in
> the given folder and all direct sub-folders.
>
> The pckIndex.tcl file has an entry for each package in the same folder,
> like this:
> -pckIndex.tcl---
> package ifneeded tools 1.0 [list source -encoding utf-8\
> [file join $dir tools.tcl]]
> -EOF-
> A package "tools" with Version 1.0 is in the file tools.tcl
>
> -tools.tcl- has the following
> package provide tools 1.0
> % program code
> -EOF-
>
> And the start script does this to load the package:
> package require tools
>
> It is common, that the package tools will reside in the namespace "tools".
>
> If you have any other packages (3rd party), just put them also in your
> lib folder and get them by package require.
>
> Sorry, this does not answer your question directly,
> Harald

Thanks Harald,
I'm only a "Dabbler" in Tcl, not a serious programmer (I'm a retired electronic hardware designer), so simple solutions suit me best!

Re: Sourcing another Tcl file

<tkb819$3i4eu$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Sourcing another Tcl file
Date: Mon, 7 Nov 2022 16:25:29 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <tkb819$3i4eu$2@dont-email.me>
References: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com>
<tkb35o$3i4eu$1@dont-email.me>
<4abedc3e-aca7-42c6-b2e5-32188489565dn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 7 Nov 2022 15:25:29 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="2843aac443762a7eaff6ad9bb58128da";
logging-data="3740126"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/juSIt/hP81GtjAXTx9FAH"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:naCnO8fulQybsUBHeXQ+Pu3EpAs=
Content-Language: en-GB
In-Reply-To: <4abedc3e-aca7-42c6-b2e5-32188489565dn@googlegroups.com>
 by: Harald Oehlmann - Mon, 7 Nov 2022 15:25 UTC

> Thanks Harald,
> I'm only a "Dabbler" in Tcl, not a serious programmer (I'm a retired electronic hardware designer), so simple solutions suit me best!

Thanks for the feed-back. You will be happy with the solution by Rich.

The package way has a lot of advantages:
- using 3rd party packages is easy
- package dependencies are solved by "package require". They are only
loaded once, even if required by multiple packages.
- namespaces are useful to avoid variable and name overlaps.

Take care,
Harald

Re: Sourcing another Tcl file

<tkbqdc$bce$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!YN2ulY6LKp1eoOUw2OJ8ig.user.46.165.242.91.POSTED!not-for-mail
From: tcln...@rocketship1.me (et4)
Newsgroups: comp.lang.tcl
Subject: Re: Sourcing another Tcl file
Date: Mon, 7 Nov 2022 12:39:08 -0800
Organization: Aioe.org NNTP Server
Message-ID: <tkbqdc$bce$1@gioia.aioe.org>
References: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="11662"; 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 - Mon, 7 Nov 2022 20:39 UTC

On 11/7/2022 5:38 AM, snosniv wrote:
> I have a set of files which break up my program into sections, such as GUI, tooltips, procedures etc.
> The GUI interface is my main program from which I want to source the other Tcl programs, all in the same directory.
> Obviously I can use: cd C:/dir/dir.... and then just use source <file>
>
> BUT, I'd like to be able to do this from whatever directory the files all happen to be in, so I need a generic way of "cd-ing" to the dir wherever it is.
>
> I thought something like set x [pwd]
> then... cd $x would work? Apparently not.
>
> Windows 10 PC if that makes a difference.
>
> TIA, Kev P.

Since your files are each source-able, you could look at Tcl modules. If you want to place your files in a particular directory, say, c:/modules

Then you could use this statement:

tcl::tm::path add c:/modules

Then you give each of your files a specially formatted name, like say, mymodule-1.0.tm and then you can use

package require mymodule

Here, the 1.0 is the version number and the name must begin with the module name, a dash, and end with the extension .tm The package/module system will locate and source your file for you.

There's also a command

tcl::tm::path list

which will output a list of known module directories. You could pick one of those to put you files in, then you would only need the [package require] command.

And with all things tcl 8.6 the best resource is "The Tcl Programming Language" by Ashok. It's where I learned about modules.

et

Re: Sourcing another Tcl file

<43526ba5-c73f-4900-9355-5b913b6deda5n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:4f57:0:b0:3a5:5191:b34b with SMTP id i23-20020ac84f57000000b003a55191b34bmr27867263qtw.111.1668046299596;
Wed, 09 Nov 2022 18:11:39 -0800 (PST)
X-Received: by 2002:ad4:5963:0:b0:4bc:1a6b:2011 with SMTP id
eq3-20020ad45963000000b004bc1a6b2011mr40652102qvb.79.1668046299451; Wed, 09
Nov 2022 18:11:39 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.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: Wed, 9 Nov 2022 18:11:39 -0800 (PST)
In-Reply-To: <tkb2rn$3jida$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:ee:9739:4900:89ac:b507:fbf9:5c3a;
posting-account=IpC1pwoAAACCAmF-qbg4PWxvUAd-j7Tc
NNTP-Posting-Host: 2003:ee:9739:4900:89ac:b507:fbf9:5c3a
References: <72e189b2-316a-4791-88c5-16215908d0fan@googlegroups.com> <tkb2rn$3jida$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <43526ba5-c73f-4900-9355-5b913b6deda5n@googlegroups.com>
Subject: Re: Sourcing another Tcl file
From: molecool...@googlemail.com (Mole Cool)
Injection-Date: Thu, 10 Nov 2022 02:11:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2953
 by: Mole Cool - Thu, 10 Nov 2022 02:11 UTC

For me, how to start is the most crucial part at all. I have everything in one sandbox, this sandbox can be moved into different folder or machines, but still works immediately. I use one folder where I start the wish executable with the first file to source within a batch file. In this batch file, you figure out where you are (what is my path). You also could setup some env vars before running wish. The first argument you give to the wish exe is known in your first script via argv0, or inside with ‘info script’. From the batch you know your full path, so you give this full path to your init script.

Each program I develop, has ONE app folder in the sandbox.

All my init scripts, calling at the end only one init proc. Here you have now your folder path. Next I use a var which contains all files, which are required for my program to run. You have the path and the source list, now you can source all this files, and after you have sourced, you call the ‘main’ procedure. This source list var is useful during debug and resource. All my source file having NO global statements, only procs and namespaces. This makes it than easy to resource during debug.The only global statement is the call to the init procedure. The init file looks the same for each main program, only the list of files which needs to be sourced on start and the main call MAY differ.

This is similar to having include files in C. And if you run the wish event loop you can update your code during develop on the fly, or even to release, you know all parts of your program. Yo may end up on release in one single file without any debug calls.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor