View · Search · Index
No registered users in community xowiki
in last 10 minutes

Weblog Page

Showing 401 - 410 of 1561 Postings (summary)

[Xotcl] Help with singleton design pattern

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Michael A. Cleverly <michael_at_cleverly.com>
Date: Fri, 18 Apr 2003 23:40:46 -0600 (MDT)

As I'm starting to learn XOTcl, I decided to try and implement a singleton
design pattern as an educational exercise.

Here is what I've come up with see below). I'd appreciate help
understanding why my filterguard registration does not work as I'd expect
it to. (I'd also appreciate feedback on style, or if my comments
indicate a misunderstanding of what the code actually does, etc.)

Thanks again for all the help.

Michael

#!/bin/sh
# -*- tcl -*- \
exec tclsh $0 ${1+"$_at_"}

package require Tcl 8.4
package require XOTcl 1.0
namespace import -force xotcl::*

Class Singleton
Singleton instproc singletonCreateFilter args {
    # Despite adding a filterguard (see below) for some reason
    # the "C foo" below would fail because a singleton instance of
    # class C exists ("::singletonCreateFilter" ?!??) if we don't also
    # check to make sure [self calledproc] == create here.
    #
    # I don't understand why ...
    if {[self calledproc] != "create"} {
        return [next]
    }

    [self class] instvar singletons
    set obj [lindex $args 0]
    set class [self]

    # if the object name isn't a fully qualified name make it so
    if {![string match ::* $obj]} {
        set obj [namespace parent]::$obj
    }

    # don't throw an error if we're recreating the same object
    if {[info exists singletons($class)] &&
        [string equal $singletons($class) $obj] == 0} {
        error "Can't instantiate \"$obj\" of singleton class\
            \"$class\"; \"$singletons($class)\" already instantiated"
    }

    set singletons($class) $obj
    next
}

Singleton instproc singletonDestroyFilter args {
    [self class] instvar singletons

    set class [my info class] ;# equiv of [self] info class

    # if other objects existed before Singleton registerClass
    # was called, and those objects are deleted, we don't care
    if {$singletons($class) == [self]} {
        unset singletons($class)
    }

    next
}

Singleton proc registerClass class {
    my instvar singletons
    my instvar registered

    # make sure we're dealing with a class
    if {[my isclass $class] == 0} {
        error "\"$class\" isn't a class;\
            hence, can't make it a singleton class."

    }

    # Don't "double register" a class
    if {[info exists registered] &&
        [lsearch -exact $registered $class] != -1} then return


    # We need to mixin to the object to filter the obj creation
    # We need to mixin to the class to filter obj destruction
    $class mixinappend [self]
    $class instmixinappend [self]

    $class filterappend singletonCreateFilter
    $class filterguard singletonCreateFilter \
            {[self calledproc] == "create"}

    $class instfilterappend singletonDestroyFilter
    $class instfilterguard singletonDestroyFilter \
        {[self calledproc] == "destroy"}

    lappend registered $class
}

Singleton proc create args {
    # doesn't make sense to instantiate objects of the singleton class
    error "Can't instantiate an object of \"[self]\";\
        use \"[self] registerClass className\" instead."
}

Class C

# just a quick sanity check to make sure our filter doesn't
# keep us from defining instance procs or using them
C instproc datetime {} {
    clock format [clock seconds]
}

Singleton registerClass C

# don't expect/don't want [C foo] to fail
C foo
puts [foo datetime]

# We expect/want [C bar] to fail
C bar

[Xotcl] Sqlite command inside NX object

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Victor Mayevski <vitick_at_gmail.com>
Date: Thu, 28 Jul 2011 17:24:34 -0700

#I am confused about the following behaviour of Sqlite command inside
NX object.

Object create o;
o require namespace;
sqlite3 o::db /tmp/my.db
o db eval {create table mytable (data)};
o public method insert {data} {:db eval {insert into mytable values ($data)} };

#In the above, sqlite sees the variable $data as being empty (or non-existent);
#If I rewrite the method in a following way (using double quotes
instead of braces), it works:

o public method insert {data} {:db eval "insert into mytable values ($data)" };

#The problem is that I might want to insert binary/BLOB data etc,
therefore use the : _at_ $ prefix for variables, I have to use braces,
not double quotes.
#After much trial and error I got the following to work:

o public method insert {data} {[self]::db eval {insert into mytable
values ($data)} };

#why doesn't sqlite see the variable with :db AND braces syntax but it
works fine with [self]::db or :db + double quotes syntax ?
#as far as I am concerned, the problem is solved, I am just curious
what is going on here.

Re: [Xotcl] RE: Snit TIP

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Uwe Zdun <uwe.zdun_at_wu-wien.ac.at>
Date: Sat, 24 Apr 2004 15:22:12 +0200

Hi all,

being a Tcl hacker and strongly engaged in the OO community sometimes makes
me were two different hats ... surely, as a developer of XOTcl, I would
love to
see XOTcl in the core one day. I agree with
Jeff's reasons given below, but what worries me more these days with
regard to the future of Tcl, is that we are arguing whether to have OO
in the core or not in
a time when the OO community argues how to best support
aspect-oriented programming and the likes. Three years ago I could tell
the Java guys: "I use Tcl because in this language we can do things you
cannot do" ... Today, with tools like AspectJ, Javassist, BCEL, and
Eclipse around this is much harder to argue.
Taking a look at modern middleware like IONA
Artix + ART, at server-side component container architecture like JBoss,
or at program development environments like AspectJ / Eclipse you can
see that virtually every "en vogue" OO development has build or
currently builds AOP abstractions into their systems. I have the fear
that once we have some OO in the core, we are getting the
same discussion for AOP abstractions as we have it now for (correct me
if I'm wrong)
at least 10 years for OO...
my major point in favour for XOTcl is that it already provides AOP
abstractions
with its message interceptors in a rugged and efficient way ... and in
Tcl's programming style.

just my 2 cents ...

Uwe
 


Jeff Hobbs wrote:

>>In fact, I'd be pleased to see Snit in the core - I really like the
>>delegation model and I intend to start using Snit more in the future.
>>
>>
>
>I'm not sold on snit, although we do use it. I want to have
>the opportunity to look into xotcl more in actual use. It
>has had a lot more large applications built with it, and has
>been "harder hit" (at least that's my impression).
>
>Why? Because it is similar to snit, similarly it is a
>"Tcl-friendly OO model", but already done in C, even to the
>point of performance tweaking. People like snit because the
>model is good, and they can drop it in anywhere because it is
>pure Tcl.
>
>However, a true core OO should be done in C. xotcl is that
>already. Sure, you can code parts of snit in C - but xotcl
>is already there *and tested*. It has active developers and
>interested users. It's even gone so far as to have an alpha
>"itcl compatability" mode that actually faster than the C
>coded itcl!
>
>So why have I been slow in including it? Well, until v1.2
>the build system was not TEA friendly. I strongly believe
>in extensions that behave as extensions, and it behaved as if
>xotcl was the world. Also, key to AS work in usage only, the
>TDK Compiler does not know how to precompile (hide/obfuscate)
>xotcl methods, so it wouldn't be too hard to go poking in our
>code (which we don't want ;) ).
>
>Please note that this message crosses 3 mailing lists, so be
>conscious of who is on the to/cc for your replies.
>
>Jeff
>
>PS - Of course we still love Will's snit, which is why it
>actually made it into our code, but when we talk "core OO",
>there are different criteria to go by.
>
>_______________________________________________
>Xotcl mailing list - Xotcl_at_alice.wu-wien.ac.at
>http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
>
>

[Xotcl] XOTclIDE 0.32 with Syntax Checker

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Artur Trzewik <mail_at_xdobry.de>
Date: Sat, 10 Aug 2002 15:52:55 +0200

Hi

The Integrated/Interactive Development Environment for XOTcl
The new version of XOTclIDE 0.32 is ready on
http://www.xdobry.de/xotclide

The Changes from last announced Version
- xotclide includes tcl/XOTcl parser written in XOTcl that is used for
- syntax hightlighting that is much better than regexp based syntax
hightlighting
- syntax checker (Tcl and XOTclIDE). The syntax checker is probably better
than tclpro checker. It can also check variables visibility and simulate
commands execution.
More infos to syntax checker
http://www.xdobry.de/xotclide/syntaxchek.html
The syntax checker can be used either by editing code (by accept operation)
or as syntax checker tool that can check whole XOTcl/Tcl projects.

Very good is speed of XOTcl. Checking Syntax of whole XotclIDE project
(1543 methods) takes only 114 seconds (1,2 GHz Pentium). In this time many
thousands of syntax-token objects are build and destroyed.

have fun with it

[Xotcl] Xotck and Vignette

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Lucio Travagnin <ltravagnin_at_e-tree.com>
Date: Fri, 1 Mar 2002 16:01:47 +0100

Hi, I'm new to Tcl, XoTcl and Vignette, but I have to use these in a Project.
XoTcl extensions can be used with vignette? Could I write some classes and then use them in Vignette Templates?
Thank you

Lucio

___________________________________________________________________
Lucio Travagnin
Java & Perl Senior Developer - Interwoven Technical Manager
ltravagnin_at_e-tree.com (ICQ 84914112)

E-TREE - Internet Soul / Via Fonderia 43 - 31100 Treviso (Italy)
phone +39.0422.3107 fax +39.0422.310888
http://www.e-tree.comhttp://www.webanana.com
___________________________________________________________________

[Xotcl] Reference manual for NX

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Jonathan Kelly <jonkelly_at_fastmail.fm>
Date: Wed, 08 Aug 2012 14:39:43 +1000

Is there one? One planned?

Jon

Re: [Xotcl] instprocs in C

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Thu, 16 Feb 2006 22:24:39 +0100

Aamer Akhter schrieb:

>Critcl allows us to easily create tcl callable C procs. Is there
>something similar avaliable for xotcl?
>
>Is there any C api documentation?
>
>
There is as well a simpler way, defining e.g. a cinstproc similar to the
cproc:

===============================================================
lappend auto_path .
package require critcl

Class instproc cinstproc {name arglist returntype body} {
  critcl::cproc $name $arglist $returntype $body
  catch {$name} ;# there must be a better way forcing the compile!
  rename $name ::xotcl::classes[self]::$name
}
===============================================================

now one can define a Class and a cinstproc and use it.

===============================================================
Class C
C cinstproc triple {int i} int {
  return i * 3; /* this is C code */
}

C c1
puts "three times 123 is [c1 triple 123]"
===============================================================

this might be already sufficient for you. Two things should be done
more beautiful:

 a) the compilation in criticl seems to be forced through unknown.
    my approach with the catch is rather crude. but i am sure, there must
    be an option.

 b) It would be nice to generate the command in the right namespace.
     i found as well no nice approach to do this.

Aamer, if you have some experience here, feedback would be welcome,

-gustaf

>
>
>--
>Aamer Akhter / aakhter_at_gmail.com
>
>_______________________________________________
>Xotcl mailing list
>Xotcl_at_alice.wu-wien.ac.at
>http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
>
>

[Xotcl] XOTcl / Tcl Namespace issues

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Adam Turoff <adam.turoff_at_gmail.com>
Date: Fri, 22 Oct 2004 16:20:41 -0400

Hi,

Can anyone explain why this program:

    package require XOTcl
    namespace import xotcl::*

    proc ns {} {return "global"}
    proc examine {} {puts "[ns] EXAMINE"}

    Class Outer
    Outer instproc test {} {return [examine]}

    namespace eval inner {
        proc ns {} {return "inner"}
        proc examine {} {puts "[ns] examine"}

        Class Inner
        Inner instproc test {} {return [examine]}
    }

    Outer o
    o test

    inner::Inner i
    i test

    namespace eval inner {
        ::o test
        ::i test
    }

produces this output:

    global EXAMINE
    global EXAMINE
    inner examine
    inner examine

I've defined the class 'Inner' within the namespace 'inner'. I'd
expect that proc in methods defined within that namespace should first
look within that namespace before looking in the global namespace.
Instead, they look in the namespace currently in use when a method call
is made. (Note how ::o test picks up the definition of inner::examine
when invoked from the inner namespace.)

This is the opposite behavior of how Tcl proc calls work -- when I land
on inner::examine, the [ns] is actually shorthand for inner::ns, not ::ns.

I'm guessing there's a good reason for this behavior, but I can't seem
to find it in the docs.

Thanks,

-- Adam

[Xotcl] Java to XOTcl translator

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Mon, 15 Dec 2008 09:08:06 +0100

Dear XOTcl community,

some of you might be intersted in the Java to XOTcl source code translator
by Mykhaylo Sorochan. It is a very new development looking quite
promising.

http://macroexpand.org/doku.php/txl:projects:java2tcl:start

best regards
Gustaf Neumann

[Xotcl] XOTcl packages

Created by hypermail2xowiki importer, last modified by Stefan Sobernig 02 Jan 2017, at 11:15 PM

From: Victor Mayevski <vitick_at_gmail.com>
Date: Fri, 3 Apr 2009 11:24:03 -0700

I really like that XOTcl is being included with ActiveState
distribution, and even updates via teacup are working. But there is
one issue - why is it that the rest of XOTcl packages (comm,
serializer etc) are not being included?

Thanks a lot

Next Page