def set_referent(asker, rep, new_value, s):
    import updates, dictionaries
    return asker.ask_tail(updates.apply_update(
        updates.set_field(
            fields.compose(bindings(), dictionaries.image(s)),
            new_value
        ),
        rep
    ))
Пример #2
0
 def update(self, change, v, repr_change=None):
     if repr_change is None:
         repr_change = updates.lift(change)
         default_repr_change = True
     else:
         default_repr_change = False
     if v.id in self.internal:
         internal = self.internal[v.id]
         #if we are updating stale information...
         #apply the update, but not any representation change
         #(if info is stale, probably just a representation change...)
         if v.id != self.current[internal].id:
             if change.head == updates.trivial.head:
                 return True
             else:
                 repr_change = updates.lift(change)
         self.updates[internal] = updates.compose(self.updates[internal], change)
         self.current[internal] = convert.unquote(
                 self, 
                 self.ask_firmly(updates.apply_update(
                     repr_change, 
                     representations.quote(self.current[internal])
                 ))
             )
         self.changed[internal] = True
         return True
     else:
         #FIXME think more about how this propagation ought to work
         #it seems like something is going oddly w.r.t levels of abstraction
         #also should I propagate back across field accesses? I don't know...
         #also this whole thing seems kind of like a mess, I don't expect it to work consistently
         def propagate_back(s):
             if s.head == term.because.head:
                 return propagate_back(s['operation'])
             elif s.head == term.explain.head:
                 return propagate_back(s['operation']) or propagate_back(s['prior'])
             elif s.head == term.accessing.head:
                 if change.head == updates.trivial.head:
                     parent = s['term']
                     binding = s['binding']
                     return self.update(
                         updates.trivial(),
                         parent,
                         repr_change=updates.apply_to_field(
                             representations.referent_of(T.from_str(binding)),
                             repr_change
                         ).explain("tracing backwards from [v]", v=v)
                     )
                 else:
                     return False
             elif s.head == askers.answering.head:
                 Q = s['Q']
                 if Q.head == fields.get_field.head:
                     parent = Q['object']
                     field = Q['field']
                     return self.update(
                         updates.apply_to_field(field, change), 
                         parent, 
                         repr_change=updates.apply_to_field(updates.lift_field(field), repr_change)
                     )
                 elif Q.head == convert.convert.head:
                     previous = Q['value']
                     return self.update(
                         change,
                         previous,
                         repr_change=None
                     )
             return False
         return propagate_back(v.source)