Mercurial > code > home > repos > light9
diff port.py @ 0:45b12307c695
Initial revision
author | drewp |
---|---|
date | Wed, 03 Jul 2002 09:37:57 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/port.py Wed Jul 03 09:37:57 2002 +0000 @@ -0,0 +1,41 @@ + +''' +Snippet Pi=3: RFC 2: New port semantics +''' + +# an example of the max node's op +def changed(self, inputs): + # note how this function does not use stateaccess, as it doesn't use state + return max(inputs.values()) + +# so, how the heck does this work? +# we check the function to get the names of kw args in the function. +# we always pass self, but everything else is optional +# the node asked for inputs, which looks like this: +# inputs = {'portname' : PortObj, 'portname2', PortObj} +# somehow, the PortObjs are max'ible. +# the node has only one output so it can just return the value to set the +# output. (maybe) +# alteratively, if we decide that you always return a new dict of outputs: +# return {'outputportname' : max(inputs.values())} +# which isn't horrible, but not great + +# another example: an adder. the node has ports A and B, and an output C: +# C also gets capped at stateaccess[min]. +def changed(self, a, b, c, stateaccess): + c.set(max(stateaccess['min'], a + b)) + return {} + +# or: +def changed(self, a, b, stateaccess): + c = max(stateaccess['min'], a + b) + return {'c' : c} + +# which i think is clearer. doing all port changes at the end has some +# book-keeping advantages (we can detect easily which ports are changed) +# the counter node could work this way: + +def changed(self, someoutput): + return {'someoutput' : someoutput + 1} + +