[Tcl Java] [Tcl Java] Re: [Tcl Java] RE: [Tcl Java] namespace

1999-11-03 Thread sang-suan gam

> > Here's what I'm trying to do with namespaces; maybe someone has an
> > alternative that would work better:  The application I wrote allows users to
> > open multiple "documents" (I use the term generically here) that may contain
> > Tcl vars and procs specific to the document.  Since there's only one interp
> > these vars can conflict leading to inconsistent results.  I thought that
> > perhaps the namespace feature would be useful in this situation.  However,
> > I'd like to avoid the user from having to understand namespaces by hiding
> > them as much as possible.  Some questions then...

In an earlier application, I did the following to get data specific to a file
into its own namespace:

namespace eval app {

set doc $filename

namespace eval ::app::${filename} {

set fd  [open $filename]
set all [split [read $fd] \n]

}
}

When looking up file specific data, I had to do:

set index [eval lsearch -exact \
[format {$::app::%s::all} $Current_file] $pattern]

cheers,
sam


The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:send mail to [EMAIL PROTECTED]  
 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 



[Tcl Java] Article about Tcl/Java and new 1.2.5 release

1999-11-03 Thread Moses DeJong

Hi all.

Check out this URL for an article about Tcl and Java.

http://www.sunworld.com/sunworldonline/swol-11-1999/swol-11-jacl.html

You might also want to check out the new Tcl and Java
web pages at Scriptics. They have been updated for the
new "production" 1.2.5 releases of Jacl and Tcl Blend.

http://www.scriptics.com/java

The new 1.2.5 release is also in the Scriptics online CVS.

Mo DeJong



The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:send mail to [EMAIL PROTECTED]  
 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 



[Tcl Java] Re: [Tcl Java] RE: [Tcl Java] namespace

1999-11-03 Thread Brent Welch


>>>"Thomas McKay" said:
 > Gotcha.  The book I have Tcl/Tk by Welch has examples of namespace w/o the
 > 'eval'.  Is the book wrong?  It says it describes Tcl 8.0.  I just want to
 > know what Tcl book to recommend to customers.

I thought I recognized your example.  Indeed, the original namespace
implementation did not require the "eval" keyword, so the very first
printing of the book was incorrect.  In subsequent printings I fixed
all but one case of the missing eval keyword.  I've finally fixed that
example in the 3rd edition, due out in two weeks.  See
http://www.beedub.com/book/3rd

--  Brent Welch <[EMAIL PROTECTED]>
http://www.scriptics.com
Scriptics: The Tcl Platform Company



The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:send mail to [EMAIL PROTECTED]  
 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 



[Tcl Java] Re: [Tcl Java] RE: [Tcl Java] namespace

1999-11-03 Thread Moses DeJong

On Wed, 3 Nov 1999, Thomas McKay wrote:

The book is wrong in this one example. This is a namespace feature that
was changed (in Tcl 8.1 I think). Originally, it seemed like a good idea
to be able to leave out the eval but I guess they reconsidered.

> Gotcha.  The book I have Tcl/Tk by Welch has examples of namespace w/o the
> 'eval'.  Is the book wrong?  It says it describes Tcl 8.0.  I just want to
> know what Tcl book to recommend to customers.

Namespaces remove "global conflict" for variables and procs but it
does not give you "instance" data like itcl does. In itcl, you
can create instances of a class that have their own vars.
Problem is, Jacl does not have an Itcl port.

> Here's what I'm trying to do with namespaces; maybe someone has an
> alternative that would work better:  The application I wrote allows users to
> open multiple "documents" (I use the term generically here) that may contain
> Tcl vars and procs specific to the document.  Since there's only one interp
> these vars can conflict leading to inconsistent results.  I thought that
> perhaps the namespace feature would be useful in this situation.  However,
> I'd like to avoid the user from having to understand namespaces by hiding
> them as much as possible.  Some questions then...

Nope, you can not export a variable from a namespace. You could try some
kind of wacky trace on a global variable and then set the namespace var
is the callback.

> 1) Can variables be exported from a namespace in addition to procs?  This is
> to avoid having to explicitly say "foo::var1".

I thought of that too. You could try something like.

proc getinput { } {
  gets stdin var
  namespace eval foo $var
}


> 2) Is there a way to switch to a namespace so that all evals after then take
> place w/in that namespace?  I suppose I could simply wrap all user input in
> "namespace eval foo {  }".
> 


later
mo


The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:send mail to [EMAIL PROTECTED]  
 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 



[Tcl Java] RE: [Tcl Java] namespace

1999-11-03 Thread Thomas McKay

Gotcha.  The book I have Tcl/Tk by Welch has examples of namespace w/o the
'eval'.  Is the book wrong?  It says it describes Tcl 8.0.  I just want to
know what Tcl book to recommend to customers.

Here's what I'm trying to do with namespaces; maybe someone has an
alternative that would work better:  The application I wrote allows users to
open multiple "documents" (I use the term generically here) that may contain
Tcl vars and procs specific to the document.  Since there's only one interp
these vars can conflict leading to inconsistent results.  I thought that
perhaps the namespace feature would be useful in this situation.  However,
I'd like to avoid the user from having to understand namespaces by hiding
them as much as possible.  Some questions then...

1) Can variables be exported from a namespace in addition to procs?  This is
to avoid having to explicitly say "foo::var1".
2) Is there a way to switch to a namespace so that all evals after then take
place w/in that namespace?  I suppose I could simply wrap all user input in
"namespace eval foo {  }".

> -Original Message-
> From: Moses DeJong [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 02, 1999 8:47 PM
> To: [EMAIL PROTECTED]
> Subject: [Tcl Java] Re: [Tcl Java] namespace
>
>
> On Tue, 2 Nov 1999, Thomas McKay wrote:
>
> Nope, you need to use "namespace eval {...}"
>
> Try this.
>
> % namespace eval foo {
>   variable x
>   set x 12
> }
>
> % set foo::x
> 12
>
>
> You can create a namespace like this "namespace eval foo {}".
>
> If you run into problems, please check to see if you code
> works in Tcl 8.X. If you find code that does not work the
> same as Tcl 8.X, I want to hear about it.
>
> later
> mo
>
> > Should the following work?
> >
> > namespace foo {
> > variable x
> > set x 12
> >
> > proc y { a } {
> >puts $y
> > }
> > }
> >
> > I get an unrecognized arg foo, should be eval, etc.  Looking at
> the code it
> > sure seems like this won't work.
> >
> > How do I create a namespace then?
> >
> > ---
> > Thomas McKay
> >
> > Project Leader
> > Microcosm Technologies, Inc.
> > mailto:[EMAIL PROTECTED]
> >
> > 
> > The TclJava mailing list is sponsored by Scriptics Corporation.
> > To subscribe:send mail to [EMAIL PROTECTED]
> >  with the word SUBSCRIBE as the subject.
> > To unsubscribe:  send mail to [EMAIL PROTECTED]
> >  with the word UNSUBSCRIBE as the subject.
> > To send to the list, send email to '[EMAIL PROTECTED]'.
> >
>
> 
> The TclJava mailing list is sponsored by Scriptics Corporation.
> To subscribe:send mail to [EMAIL PROTECTED]
>  with the word SUBSCRIBE as the subject.
> To unsubscribe:  send mail to [EMAIL PROTECTED]
>  with the word UNSUBSCRIBE as the subject.
> To send to the list, send email to '[EMAIL PROTECTED]'.


The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:send mail to [EMAIL PROTECTED]  
 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'.