Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This can be done...but it will require a bit of effort. The basic idea is to use the right shift operator to create and update a new type of object that defers the actual computation.</p> <p>For instance, let's say that your variables above: A, B, C, D, and E are all objects of type Actual. We'll introduce a new class Deferred that is produced by the rshift operation on an instance of Actual. Deferred also implements the rshift operator, which updates the object and returns itself.</p> <p>(BTW, For the remainder of this answer, I'm assuming that A, B, C, D, and E are immutable and that the rshift operation produces a new object.)</p> <pre><code>F = A &gt;&gt; B &gt;&gt; C &gt;&gt; D &gt;&gt; E </code></pre> <p>Would be computed like ...</p> <pre><code>F = Deferred(A,B) &gt;&gt; C &gt;&gt; D &gt;&gt; E F = Deferred(A,B,C) &gt;&gt; D &gt;&gt; E F = Deferred(A,B,C,D) &gt;&gt; E F = Deferred(A,B,C,D,E) </code></pre> <p>F maintains a cached instance of Actual, that is computed from the reverse sequence. Furthermore, F implements the same interface as Actual, so that methods invoked on an instance of Deferred are delegated to the cached instance of Actual.</p> <p>I don't know the kind of computation you're doing, so in the following example, I make up something kind of trivial, just to demonstrate that the when the deferred computation is actually performed, they are reversed.</p> <pre><code>class Var(object): def __init__(self): pass @property def name(self): return self._name( ) @property def length(self): return len(self.name) class Actual(Var): def __init__(self, name): Var.__init__(self) self._text = name def _name(self): return self._text def __rshift__(self, other): if isinstance(other, Actual): return Deferred(self, other) return len(self.name) @staticmethod def NewFromShiftComputation(sequence): x = ' &gt;&gt; '.join(reversed(map(lambda actual: actual.name, sequence))) return Actual(x) class Deferred(Var): def __init__(self, *args): Var.__init__(self) self._items = [ ] self._actual = None #-- cached "actual" for item in args: self._items.append(item) def _name(self): self._assure_actual( ) return self._actual.name def __rshift__(self, other): self._actual = None #-- Invalidate the cached "actual" self._items.append(other) return self def _assure_actual(self): if self._actual is None: self._actual = Actual.NewFromShiftComputation(self._items) A = Actual('A') B = Actual('B') C = Actual('C') D = Actual('D') E = Actual('E') F = A &gt;&gt; B &gt;&gt; C &gt;&gt; D &gt;&gt; E print F.name print F.length </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload