예제 #1
0
 def print_string(s):
     view_in = asker.refresh(view)
     asker.update(add_line(input), view_in)
     #FIXME more things going wrong with representation levels...
     s = convert.unquote(asker, s)
     line = asker.ask_firmly(render(s))
     asker.update(add_line(line), view_in)
     return properties.trivial()
예제 #2
0
def set_lifted_field(asker, object, new_value, field):
    raw_result = asker.ask(apply_update(
        set_field(field, convert.unquote(asker, new_value)), 
        convert.unquote(asker, object)
    )).firm_answer
    return asker.reply(answer=representations.quote(raw_result))
예제 #3
0
def lift_field(asker, object, field):
    response = asker.ask(fields.get_field(field, convert.unquote(asker, object)))
    if response.has_answer():
        return asker.reply(answer=representations.quote(response.answer))
    else:
        return asker.reply()
예제 #4
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)