def set_image(asker, new_value, k, key, value, other): if booleans.ask_firmly(asker, builtins.equal(k, key)): return asker.reply(answer=cons(key=key, value=new_value, other=other)) else: return asker.reply(answer=cons(key=key, value=value, other=updates.update(updates.set_field(image(k), new_value), other) ))
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 ))
def easy_set(asker, object, new_value): #FIXME the cyclic import again, would be nice to do better import updates return asker.reply(answer=updates.update( updates.apply_to_field( modifier(), updates.set_field(implication_about(field), new_value) ), object ))
def bind_variable(asker, view, name, value): return asker.reply(answer=updates.update( updates.apply_to_field( bindings_field(), updates.set_field( dictionaries.image(name), value ) ), view ))
def predict_input(asker, view): lines = fields.get(asker, lines_field(), view) h = asker.ask(state.get_history()).firm_answer response = asker.ask(fields.get_field(dictionaries.image(lines), h)) if response.has_answer(): return asker.reply(answer=response.answer) else: input = asker.ask_firmly(elicit(view)) asker.ask(state.update_state(updates.apply_to_field( state.history(), updates.set_field( dictionaries.image(lines), input ) ))) return asker.reply(answer=input)
def outline_to_lines(asker, root): debug() result = asker.ask(fields.get_field(cached_lines(), root)).answer if result is not None: return asker.reply(answer=result) base_headline = asker.ask(fields.get_field(headline(), root)).firm_answer root = asker.refresh(root) prefix = "* " if convert.check_hard(asker, is_pointer(), root) else " " full_headline = strings.string_concat(T.from_str(prefix), base_headline) root = asker.refresh(root) children = asker.ask(fields.get_field(visible_children(), root)).firm_answer body = empty_lines() for child in lists.iterator(asker, children): section = asker.ask(outline_to_lines(child)).firm_answer body = concat_lines(body, section) result = concat_lines(one_line(full_headline), indent_lines(body)) asker.update(updates.set_field(cached_lines(), result), root) return asker.reply(answer=result)
def set_last_concat(asker, l, new_value): #FIXME deal with the case where b is empty return asker.reply(answer=l.simple_update(b=updates.update( updates.set_field(last(), new_value), l['b'] )))
def set_last_simple(asker, l, new_value): return asker.reply(answer=l.simple_update(tail=updates.update( updates.set_field(last(), new_value), l['tail'] )))