Hi all,

I just started using Kamaelia a little.  First off, let me just say that I
like the idea of wiring components together very much.  That model works
very well for certain types of applications, and the closer your code gets
to that model the easier it is to use.  So far, Kamaelia is the closest to
my ideal for this domain.

That being said, I think there is a lot of room for improvement.  I'm sure
that's a big shocker to everyone, given Kamaelia's relatively young age
;-).  In particular, I find coding and wiring components to be cumbersome.
There's too much mucking around with strings and dictionaries when it would
be much more natural to use attributes -- it's just not 'pythonic'.

What I propose is a new interface -- one that uses the deeper, more
'magical', aspects of python to make things more pythonic.  This would not
necessarily replace the existing interface -- there may be cases where that
old interface would handle better.  Instead, it could build on the existing
interface as appropriate.

I could spend a lot of time describing things, but I think a simple example
would be more efficient.  So here is a fairly simple example that
illustrates how I envision things "should" work:

import component

class Counter(component.Component):
    """
    Component that outputs increasing numbers
    """
    output = component.Output(type=int)

    def __init__(self):
        component.Component.__init__(self)
        self.counter = 0

    def process(self):
        self.output = self.counter
        self.counter += 1

    @component.signal
    def reset(self):
        self.counter = 0

class Printer(component.Component):
    """
    Component that prints its input to standard output.
    """
    input = component.Input()

    def process(self):
        print self.input

class FireOn(component.Component):
    """
    Component that fires an event whenever its input meets the provided
condition
    """
    input = component.Input()

    output = component.OutputSignal()

    def __init__(self, condition):
        self.condition = condition

    def process(self):
        if self.condition(self.input):
            self.output.fire()

class CounterExample(component.Component):
    """
    Component that prints ever-increasing numbers to standard out
    Illustrates:
    * Wiring up a composite component
    * Wiring up a pass-through output
    """
    output = component.Output()

    def __init__(self):
        self.counter = Counter()
        self.printer = Printer()
        self.printer.input = self.counter.output

def run_counter_example():
    example = CounterExample()
    example.run()

def run_counter_reset_example():
    """
    Illustrates:
    * Wiring and running a set of components without a container
    """
    #Create components
    counter = Counter()
    printer = Printer()
    reset = FireOn(lambda x: x == 10)

    #Wire things together
    counter.reset = reset.output
    reset.input = counter.output
    printer.input = counter.output
    component.run(counter, printer) #reset is implied

def run_pipeline_example():
    #Create pipeline
    counter = Counter()
    printer = Printer()
    pipeline = counter | printer #maps output -> input

    #Reset counter at 10
    reset = FireOn(lambda x: x==10)
    counter.reset = reset.output

    #Run pipeline
    pipeline.run()
Well, there it is.  I think it's pretty well self-explanatory, but let me
know if you have any questions.  It's not perfect, but hopefully its a
start.  Let me know what you think, and if you have any suggestions.

Thanks,

Nathan Davis

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"kamaelia" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/kamaelia?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to