f



Using "source" vs "package require" for Tcl application files

I would like to divide my Tcl application into separate files. Should I 
generally use "source" to combine the files, or should I use the package 
mechanism (package provide, package require, etc.)?

What is the generally accepted practice?

Thanks,

Gregg
0
gb3534 (77)
12/30/2008 12:04:31 AM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

7 Replies
1057 Views

Similar Articles

[PageSpeed] 49

On 30 dec, 01:04, GB <g...@invalid.invalid> wrote:
> I would like to divide my Tcl application into separate files. Should I
> generally use "source" to combine the files, or should I use the package
> mechanism (package provide, package require, etc.)?
>
> What is the generally accepted practice?
>
> Thanks,
>
> Gregg

IMHO use [source]. My reasoning:

- The package mechanism is meant for getting access to
  general-purpose libraries, installed directly under the Tcl
  installation.

- You talk of source files for your own application. So I would
  expect these files to reside in a directory containing that
  application. Then [source] is easier to use - and you guarantee
  that you get the source files from your application (otherwise
  a random package with the same name from the installation
  could interfer, if you are not careful with the library path)

- Using [source] also makes it clear that these files are meant
  for your application only, not for more general purposes.

Regards,

Arjen
0
arjen.markus (2628)
12/30/2008 7:49:32 AM
Arjen Markus wrote:
> On 30 dec, 01:04, GB <g...@invalid.invalid> wrote:
>> I would like to divide my Tcl application into separate files. Should I
>> generally use "source" to combine the files, or should I use the package
>> mechanism (package provide, package require, etc.)?
>>
>> What is the generally accepted practice?
>>
>> Thanks,
>>
>> Gregg
> 
> IMHO use [source]. My reasoning:
> 
> - The package mechanism is meant for getting access to
>   general-purpose libraries, installed directly under the Tcl
>   installation.
> 
> - You talk of source files for your own application. So I would
>   expect these files to reside in a directory containing that
>   application. Then [source] is easier to use - and you guarantee
>   that you get the source files from your application (otherwise
>   a random package with the same name from the installation
>   could interfer, if you are not careful with the library path)
> 
> - Using [source] also makes it clear that these files are meant
>   for your application only, not for more general purposes.
> 
> Regards,
> 
> Arjen

Thanks. That was my initial inclination, but I was confused after 
reading Practical Programming in Tcl, Chapter 12. In the section 
"Locating Packages", it says:

 > One trick I often use is to put the directory containing the
 > main script into the auto_path. The following command sets this
 > up:

 > lappend auto_path [file dirname [info script]]

 > If your code is split into bin and lib directories, then
 > scripts in the bin directory can add the adjacent lib directory
 > to their auto_path with this command:

 > lappend auto_path \

 >     [file join [file dirname [info script]] ../lib]

Gregg
0
gb3534 (77)
12/30/2008 9:24:27 AM
On 30 dec, 10:24, GB <g...@invalid.invalid> wrote:
> Arjen Markus wrote:
> > On 30 dec, 01:04, GB <g...@invalid.invalid> wrote:
> >> I would like to divide my Tcl application into separate files. Should =
I
> >> generally use "source" to combine the files, or should I use the packa=
ge
> >> mechanism (package provide, package require, etc.)?
>
> >> What is the generally accepted practice?
>
> >> Thanks,
>
> >> Gregg
>
> > IMHO use [source]. My reasoning:
>
> > - The package mechanism is meant for getting access to
> > =A0 general-purpose libraries, installed directly under the Tcl
> > =A0 installation.
>
> > - You talk of source files for your own application. So I would
> > =A0 expect these files to reside in a directory containing that
> > =A0 application. Then [source] is easier to use - and you guarantee
> > =A0 that you get the source files from your application (otherwise
> > =A0 a random package with the same name from the installation
> > =A0 could interfer, if you are not careful with the library path)
>
> > - Using [source] also makes it clear that these files are meant
> > =A0 for your application only, not for more general purposes.
>
> > Regards,
>
> > Arjen
>
> Thanks. That was my initial inclination, but I was confused after
> reading Practical Programming in Tcl, Chapter 12. In the section
> "Locating Packages", it says:
>
> =A0> One trick I often use is to put the directory containing the
> =A0> main script into the auto_path. The following command sets this
> =A0> up:
>
> =A0> lappend auto_path [file dirname [info script]]
>
> =A0> If your code is split into bin and lib directories, then
> =A0> scripts in the bin directory can add the adjacent lib directory
> =A0> to their auto_path with this command:
>
> =A0> lappend auto_path \
>
> =A0> =A0 =A0 [file join [file dirname [info script]] ../lib]
>
> Gregg- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Right, but that refers to the old (ancient?) way of loading Tcl files,
via
the auto loading mechanism - not packages perse.

Myself, I do not use that mechanism (at least not consciously ;)).

Regards,

Arjen
0
arjen.markus (2628)
12/30/2008 10:04:16 AM
I'll use a similar trick if the application is structured in packages, 
however I'll _prepend_ the directory the app lives in rather than 
append.  That deals with the issue of package name clashes.. ensuring 
it's resolved in favor of _my_ packages.

e.g. rather than lapped auto_path [file dirname [info script]]

set auto_path [concat [file dirname [info script]] $auto_path]

RF.

GB wrote:
> Arjen Markus wrote:
>> On 30 dec, 01:04, GB <g...@invalid.invalid> wrote:
>>> I would like to divide my Tcl application into separate files. Should I
>>> generally use "source" to combine the files, or should I use the package
>>> mechanism (package provide, package require, etc.)?
>>>
>>> What is the generally accepted practice?
>>>
>>> Thanks,
>>>
>>> Gregg
>>
>> IMHO use [source]. My reasoning:
>>
>> - The package mechanism is meant for getting access to
>>   general-purpose libraries, installed directly under the Tcl
>>   installation.
>>
>> - You talk of source files for your own application. So I would
>>   expect these files to reside in a directory containing that
>>   application. Then [source] is easier to use - and you guarantee
>>   that you get the source files from your application (otherwise
>>   a random package with the same name from the installation
>>   could interfer, if you are not careful with the library path)
>>
>> - Using [source] also makes it clear that these files are meant
>>   for your application only, not for more general purposes.
>>
>> Regards,
>>
>> Arjen
> 
> Thanks. That was my initial inclination, but I was confused after 
> reading Practical Programming in Tcl, Chapter 12. In the section 
> "Locating Packages", it says:
> 
>  > One trick I often use is to put the directory containing the
>  > main script into the auto_path. The following command sets this
>  > up:
> 
>  > lappend auto_path [file dirname [info script]]
> 
>  > If your code is split into bin and lib directories, then
>  > scripts in the bin directory can add the adjacent lib directory
>  > to their auto_path with this command:
> 
>  > lappend auto_path \
> 
>  >     [file join [file dirname [info script]] ../lib]
> 
> Gregg


-- 
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321
0
fox1 (369)
12/30/2008 12:00:42 PM
Ron Fox wrote:
> I'll use a similar trick if the application is structured in packages, 
> however I'll _prepend_ the directory the app lives in rather than 
> append.  That deals with the issue of package name clashes.. ensuring 
> it's resolved in favor of _my_ packages.
> 
> e.g. rather than lapped auto_path [file dirname [info script]]
> 
> set auto_path [concat [file dirname [info script]] $auto_path]

or: set auto_path [linsert [file dirname [info script]] 0]

-- 
+------------------------------------------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
12/30/2008 4:43:24 PM
At 2008-12-30 11:43AM, "Gerald W. Lester" wrote:
>  Ron Fox wrote:
> > e.g. rather than lapped auto_path [file dirname [info script]]
> > 
> > set auto_path [concat [file dirname [info script]] $auto_path]
>  
>  or: set auto_path [linsert [file dirname [info script]] 0]

you mean:
       set auto_path [linsert $auto_path 0 [file dirname [info script]]]


-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous
0
glennj (645)
12/31/2008 1:58:16 PM
Glenn Jackman wrote:
> At 2008-12-30 11:43AM, "Gerald W. Lester" wrote:
>>  Ron Fox wrote:
>>> e.g. rather than lapped auto_path [file dirname [info script]]
>>>
>>> set auto_path [concat [file dirname [info script]] $auto_path]
>>  
>>  or: set auto_path [linsert [file dirname [info script]] 0]
> 
> you mean:
>        set auto_path [linsert $auto_path 0 [file dirname [info script]]]

Yes, I did.


-- 
+------------------------------------------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
1/1/2009 5:18:12 PM
Reply:

Similar Artilces:

Urgent Requirement in """""""""""""NEW YORK""""""""""""""""
Hello Partners, Please find the requirement below. Please send the updated resume along with rate and contact no. REQ#1: Title : Java Developer ( Rating Project) Duration : 6 months Rate : open Location : NY strong java, WebLogic 9.2, Web Services, Oracle REQ#2: Title : Java Developer Duration : 4 months Rate : open Location : NY Strong java, SQL REQ#3: Title : VB.Net Consultant Location : NY Duration : 4 months Rate : open Primarily looking at someone who has Excel, VB.net a...

Urgent Requirement for """""""""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting ...

""""""""""""""""""""""ADD ME""""""""""""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfo Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... We look forward to build a ve...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

Urgent JAVA Requirement in """"""NEW YORK"""""""""
Hello Partners, How are you ? Please find the requirement below. Location : NY Duration : 8 mnths Rate :Open Job description: Java/J2EE Web Service Developer =B7 (4+ years of application development experience in Java/J2EE and Web service technologies. =B7 Experience with spring & Hibernate. =B7 Experience with J2EE Application Server (preferably Web logic). =B7 Preferable Aqua logic DSP Experience =B7 Preferable Sonic ESB Composite Service experience Experience w...

about "++" and "--"
why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q...

"out" and "in out"
Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c...

"or" and "and"
Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g...

"If then; if then;" and "If then; if;"
I have a raw data set which is a hierarchical file: H 321 s. main st P Mary E 21 F P william m 23 M P Susan K 3 F H 324 S. Main St I use the folowing code to read the data to creat one observation per detail(P) record including hearder record(H): data test; infile 'C:\Documents and Settings\retain.txt'; retain Address; input type $1. @; if type='H' then input @3 Address $12.; if type='P' then input @3 Name $10. @13 Age 3. @16 Gender $1.; run; but the output is not what I want: 1 321 s. main H 2 321 s. main P Mary E 21 F 3 321 s...

"/a" is not "/a" ?
Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&...

why "::", not "."
Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float....

"my" and "our"
Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my $fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the $fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s...

How to do PHP "require()" or TCL "source" in bash script
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure out how to do this in bash script as the requirement is necessary for a migration script to obtain the code from a .cfg file and then be able for the "parent" script to run the code it "imported" from the .cfg file, much like PHP's require() or TCL's "source". This is what I have so far and it fails: if [ -f ivc.cfg ]; then cat ivc.cfg fi Anyone...

Urgent need """""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting Database/ETL requirements (Optional) ...

Web resources about - Using "source" vs "package require" for Tcl application files - comp.lang.tcl

Resources last updated: 2/3/2016 9:21:56 AM