def exposed_modifier(asker, rep): head = asker.ask(fields.get_field(representations.head(), rep)).answer if head is None: return asker.reply(answer=T.no()) else: result = strings.to_str(asker, head) not in hidden_modifier_heads return asker.reply(answer=T.from_bool(result))
def node_from_term(asker, quoted_term): head = asker.ask(fields.get_field(representations.head(), quoted_term)).firm_answer bindings = asker.ask(fields.get_field(representations.bindings(), quoted_term)).firm_answer return asker.reply(answer=properties.simple_add_modifier( node(head, T.empty_list()), children_on_expanded(bindings) ))
def render_term(asker, term): return asker.reply(answer=strings.concat( strings.concat( T.from_str("T("), field.get(asker, representations.head(), term)), T.from_str(")") ))
def dispatch(x): view_in = asker.refresh(view) asker.update(add_line(input), view_in) head = fields.get(asker, representations.head(), x) bindings = fields.get(asker, representations.bindings(), x) view_in = asker.refresh(view_in) asker.update(add_line(head), view_in) for p in dictionaries.item_iterator(asker, bindings): var, val = pairs.to_pair(asker, p) view_in = asker.refresh(view_in) asker.update(bind_variable(var, val), view_in) return properties.trivial()
def unquote(asker, value): #FIXME more circular dependencies import dictionaries, strings if isinstance(value, representations.Representation): return value.represents #FIXME all of this should be done with requirements embedded in questions #rather than asking and then converting bindings = asker.ask(fields.get_field(representations.bindings(), value)).firm_answer proto_literal_bindings = dictionaries.to_dict(asker, bindings) literal_bindings = frozendict({strings.to_str(asker, k):unquote(asker, v) for k, v in proto_literal_bindings.iteritems()}) head = asker.ask(fields.get_field(representations.head(), value)).firm_answer literal_head = strings.to_str(asker, head) return T(literal_head, literal_bindings)
def expose_modifier(asker, object): rep = representations.quote(object) head = strings.to_str(asker, fields.get(asker, representations.head(), rep)) if head not in hidden_modifier_heads: new_modifier = convert.reduce(asker, object.modifier) return asker.reply(answer=object.simple_update(_modifier=new_modifier))
def irreducible(asker, rep): head = asker.ask(fields.get_field(representations.head(), rep)).firm_answer result = strings.to_str(asker, head) not in reducible_heads return asker.reply(answer=T.from_bool(result)) #FIXME this is much cleaner, but too slow; at any rate could remove duplicate code return asker.ask_tail(properties.check(opposite(reducible()), rep))
def reducible(asker, rep): head = asker.ask(fields.get_field(representations.head(), rep)).firm_answer result = strings.to_str(asker, head) in reducible_heads return asker.reply(answer=T.from_bool(result))
def get_starting_view(asker, query): head = fields.get(asker, representations.head(), query) bindings = fields.get(asker, representations.bindings(), query) initial_lines = T.from_list([head, T.from_str("---")]) return asker.reply(answer=view(initial_lines, bindings))