Exemplo n.º 1
0
func init() {
	s := dynamics.ExpectQuestion(term.InitS(), GetState, "Q")
	dynamics.AddNative(s, dynamics.Args0(getState))

	s = dynamics.ExpectQuestion(term.InitS(), SetState, "Q", "s")
	dynamics.AddNative(s, dynamics.Args1(setState), "s")
}
Exemplo n.º 2
0
func init() {
	applyState = term.InitS()
	applyState = dynamics.ExpectQuestion(applyState, Apply, "Q1", "f", "x")
	applyState = dynamics.AddSimple(applyState, term.ViewS(term.Sr("f")))
	applyState2 = term.InitS()
	applyState2 = dynamics.ExpectQuestion(applyState2, Apply2, "f", "x", "y")
	applyState2 = dynamics.AddSimple(applyState2, term.ViewS(term.Sr("f")))
}
Exemplo n.º 3
0
func init() {
	QNames := []term.TemplateID{Plus, Times, Minus, Equal, Less, More,
		LessOrEqual, MoreOrEqual,
		Divide,
	}
	QFuncs := [](func(dynamics.Dwimmer, *term.SettingT, ...term.T) term.T){
		dynamics.Args2(addNative),
		dynamics.Args2(multiplyNative),
		dynamics.Args2(subtractNative),
		dynamics.Args2(testEquality),
		dynamics.Args2(testLess),
		dynamics.Args2(testMore),
		dynamics.Args2(testLessOrEqual),
		dynamics.Args2(testMoreOrEqual),
		dynamics.Args2(divideNative),
	}

	for i := range QNames {
		s := term.InitS()
		s = dynamics.ExpectQuestion(s, QNames[i], "Q", "a", "b")
		s = dynamics.AddSimple(s, term.ViewS(term.Sr("a")))
		s.AppendTemplate(term.Int(0).Head())
		s = dynamics.AddSimple(s, term.ViewS(term.Sr("b")))
		s.AppendTemplate(term.Int(0).Head())
		dynamics.AddNative(s, QFuncs[i], "a", "b")
	}
}
Exemplo n.º 4
0
func init() {
	s := term.InitS()
	s = dynamics.ExpectQuestion(s, Explicit, "Q", "t")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("t")))
	s.AppendTemplate(term.Quoted{}.Head())
	dynamics.AddNative(s, dynamics.Args1(makeExplicit), "t")
}
Exemplo n.º 5
0
func init() {
	var s, t *term.SettingS
	s = term.InitS()
	s.AppendTemplate(Fold, "f", "l", "x")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("l")))

	t = s.Copy().AppendTemplate(lists.Empty)
	t = dynamics.AddSimple(t, term.ReturnS(term.Sr("x")))

	t = s.Copy().AppendTemplate(lists.Cons, "head", "tail")
	t = dynamics.AddSimple(t, term.AskS(Apply2.S(term.Sr("f"), term.Sr("x"), term.Sr("head"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A1", "y")
	t = dynamics.AddSimple(t, term.AskS(Fold.S(term.Sr("f"), term.Sr("tail"), term.Sr("y"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A2", "A")
	t = dynamics.AddSimple(t, term.ReturnS(term.Sr("A")))

	t = s.Copy().AppendTemplate(lists.Snoc, "init", "last")
	t = dynamics.AddSimple(t, term.AskS(Fold.S(term.Sr("f"), term.Sr("init"), term.Sr("x"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A1", "y")
	t = dynamics.AddSimple(t, term.AskS(Apply2.S(term.Sr("f"), term.Sr("y"), term.Sr("last"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A2", "A")
	t = dynamics.AddSimple(t, term.ReturnS(term.Sr("A")))

	t = s.Copy().AppendTemplate(lists.Concat, "a", "b")
	t = dynamics.AddSimple(t, term.AskS(Fold.S(term.Sr("f"), term.Sr("a"), term.Sr("x"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A1", "y")
	t = dynamics.AddSimple(t, term.AskS(Fold.S(term.Sr("f"), term.Sr("b"), term.Sr("y"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A2", "A")
	t = dynamics.AddSimple(t, term.ReturnS(term.Sr("A")))

	t = s.Copy().AppendTemplate(lists.Singleton, "y")
	t = dynamics.AddSimple(t, term.AskS(Apply2.S(term.Sr("f"), term.Sr("x"), term.Sr("y"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A1", "A")
	t = dynamics.AddSimple(t, term.ReturnS(term.Sr("A")))
}
Exemplo n.º 6
0
func init() {
	s := term.InitS()
	s = dynamics.ExpectQuestion(s, GetSetting, "Q", "s")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("s")))
	s.AppendTemplate(QuotedSettingT, "lines", "arguments", "children")
	s = dynamics.AddSimple(s, term.ReturnS(core.Answer.S(QuotedSetting.S(term.Sr("lines")))))
}
Exemplo n.º 7
0
func init() {
	s := term.InitS()
	s = dynamics.ExpectQuestion(s, GetTemplate, "Q", "t")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("t")))

	t := s.Copy().AppendTemplate(term.Quoted{}.Head())
	t = dynamics.AddSimple(t, term.AskS(Explicit.S(term.Sr("t"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A", "explicit")
	t = dynamics.AddSimple(t, term.AskS(GetTemplate.S(term.Sr("explicit"))))
	t = dynamics.ExpectAnswer(t, core.Answer, "A2", "result")
	t = dynamics.AddSimple(t, term.ReturnS(core.Answer.S(term.Sr("result"))))

	t = s.Copy().AppendTemplate(QuotedQuoteT, "q")
	dynamics.AddSimple(t, term.ReturnS(core.Answer.S(
		term.Sc(Template(term.Quoted{}.Head())),
	)))

	t = s.Copy().AppendTemplate(QuotedIntT, "q")
	dynamics.AddSimple(t, term.ReturnS(core.Answer.S(
		term.Sc(Template(term.Int(0).Head())),
	)))

	t = s.Copy().AppendTemplate(QuotedStrT, "q")
	dynamics.AddSimple(t, term.ReturnS(core.Answer.S(
		term.Sc(Template(term.Str(0).Head())),
	)))

	t = s.Copy().AppendTemplate(QuotedWrapperT, "q")
	dynamics.AddSimple(t, term.ReturnS(core.Answer.S(
		term.Sc(Template(term.Wrap(nil).Head())),
	)))

	t = s.Copy().AppendTemplate(QuotedCompoundT, "template", "args")
	t = dynamics.AddSimple(t, term.ReturnS(core.Answer.S(term.Sr("template"))))
}
Exemplo n.º 8
0
func init() {
	s := term.InitS()
	s = dynamics.ExpectQuestion(s, GetTemplateAndArguments, "Q", "t")
	s = dynamics.AddSimple(s, term.AskS(GetTemplate.S(term.Sr("t"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A", "template")
	s = dynamics.AddSimple(s, term.AskS(GetArguments.S(term.Sr("t"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A1", "arguments")
	s = dynamics.AddSimple(s, term.ReturnS(TemplateAndArguments.S(term.Sr("template"), term.Sr("arguments"))))
}
Exemplo n.º 9
0
func init() {
	s := term.InitS()
	s = dynamics.ExpectQuestion(s, Len, "Q", "s")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("s")))
	s.AppendTemplate(term.Str("").Head())
	dynamics.AddNative(s, dynamics.Args1(length), "s")

	s = term.InitS()
	s = dynamics.ExpectQuestion(s, Bracketed, "Q", "s")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("s")))
	s.AppendTemplate(term.Str("").Head())
	dynamics.AddNative(s, dynamics.Args1(bracketed), "s")

	s = term.InitS()
	s = dynamics.ExpectQuestion(s, Concat, "Q", "a", "b")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("a")))
	s.AppendTemplate(term.Str("").Head())
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("b")))
	s.AppendTemplate(term.Str("").Head())
	dynamics.AddNative(s, dynamics.Args2(concat), "a", "b")

	dynamics.AddNativeResponse(GetChar, 2, dynamics.Args2(getChar))
}
Exemplo n.º 10
0
func init() {
	var s *term.SettingS
	s = dynamics.ExpectQuestion(term.InitS(), PutChar, "Q", "char", "x", "y")
	dynamics.AddNative(s, dynamics.Args3(nativePutChar), "char", "x", "y")

	s = dynamics.ExpectQuestion(term.InitS(), SetCursor, "Q", "x", "y")
	dynamics.AddNative(s, dynamics.Args2(nativeSetCursor), "x", "y")

	/*
		s = dynamics.ExpectQuestion(term.InitS(), GetCursor, "Q")
		dynamics.AddNative(s, dynamics.Args0(nativeGetCursor))
	*/

	s = dynamics.ExpectQuestion(term.InitS(), Clear, "Q")
	dynamics.AddNative(s, dynamics.Args0(nativeClear))

	s = dynamics.ExpectQuestion(term.InitS(), Size, "Q")
	dynamics.AddNative(s, dynamics.Args0(nativeSize))

	/*
		s = dynamics.ExpectQuestion(term.InitS(), GetChar, "Q")
		dynamics.AddNative(s, dynamics.Args0(nativeGetChar))
	*/
}
Exemplo n.º 11
0
func init() {
	s := term.InitS()
	s = dynamics.ExpectQuestion(s, LastAndInitQ, "Q", "l")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("l")))

	t := s.Copy().AppendTemplate(Snoc, "init", "last")
	t = dynamics.AddSimple(t, term.ReturnS(LastAndInit.S(term.Sr("init"), term.Sr("last"))))

	t = s.Copy().AppendTemplate(Singleton, "x")
	t = dynamics.AddSimple(t, term.ReturnS(LastAndInit.S(term.Sr("x"), Empty.S())))

	t = s.Copy().AppendTemplate(Empty)
	t = dynamics.AddSimple(t, term.ReturnS(IsEmpty.S()))

	t = s.Copy().AppendTemplate(Cons, "first", "rest")
	t = dynamics.AddSimple(t, term.AskS(LastAndInitQ.S(term.Sr("rest"))))

	tt := dynamics.ExpectAnswer(t.Copy(), LastAndInit, "A", "last", "init")
	tt = dynamics.AddSimple(tt, term.ReturnS(LastAndInit.S(
		term.Sr("last"),
		Cons.S(term.Sr("first"), term.Sr("init")),
	)))
	tt = dynamics.ExpectAnswer(t.Copy(), IsEmpty, "A2")
	tt = dynamics.AddSimple(tt, term.ReturnS(LastAndInit.S(term.Sr("first"), Empty.S())))

	t = s.Copy().AppendTemplate(Concat, "a", "b")
	t = dynamics.AddSimple(t, term.AskS(LastAndInitQ.S(term.Sr("b"))))

	tt = dynamics.ExpectAnswer(t, IsEmpty, "A00")
	tt = dynamics.AddSimple(tt, term.AskS(LastAndInitQ.S(term.Sr("a"))))
	dynamics.AddSimple(dynamics.ExpectAnswer(tt, IsEmpty, "A3"), term.ReturnS(IsEmpty.S()))
	dynamics.AddSimple(
		dynamics.ExpectAnswer(tt, LastAndInit, "A4", "last", "init"),
		term.ReturnS(LastAndInit.S(term.Sr("last"), term.Sr("init"))),
	)

	tt = dynamics.ExpectAnswer(t, LastAndInit, "A7", "last", "init")
	dynamics.AddSimple(tt, term.ReturnS(LastAndInit.S(
		term.Sr("last"),
		Concat.S(term.Sr("a"), term.Sr("init")),
	)))

}
Exemplo n.º 12
0
func init() {
	s := term.InitS()
	s = dynamics.ExpectQuestion(s, RepresentSetting, "Q", "s")
	dynamics.AddNative(s, dynamics.Args1(quote), "s")
}
Exemplo n.º 13
0
func init() {
	s := dynamics.ExpectQuestion(term.InitS(), SettingForChannel, "Q", "c")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("c")))
	s = s.AppendTemplate(term.Channel{}.Head())
	dynamics.AddNative(s, dynamics.Args1(settingForChannel), "c")
}
Exemplo n.º 14
0
func AddNativeResponse(t term.TemplateID, n int, f func(Dwimmer, *term.SettingT, ...term.T) term.T) {
	names := append([]string{"_Q"}, allNames[:n]...)
	s := ExpectQuestion(term.InitS(), t, names...)
	AddNative(s, f, allNames[:n]...)
}
Exemplo n.º 15
0
func TestEncoding(t *testing.T) {
	collection := Collection("testing")
	collection.Empty("testing")
	template := term.Make("test [] term")
	c := template.C(term.ReferenceC{0})
	cc := term.ConstC{template.T(term.Make("stub").T())}
	action := term.ReturnC(c)
	settingS := term.InitS().AppendTemplate(template, "q").AppendAction(action)
	setting := settingS.Setting
	collection.Set(1, term.SaveSetting(setting))
	collection.Set(2, term.SaveC(cc))
	found := 0
	for _, x := range collection.All() {
		if x["key"] == 1 {
			t.Log(x["value"])
			newVal, ok := term.LoadSetting(x["value"])
			if !ok {
				t.Error("failed to load setting")
			}
			newID := newVal.ID
			oldID := setting.ID
			if newID != oldID {
				t.Errorf("%v != %v", newVal, setting)
			}
			found++
		}
		if x["key"] == 2 {
			newVal, ok := term.LoadC(x["value"])
			if !ok {
				t.Error("failed to load C")
			}
			newID := term.IDC(newVal)
			oldID := term.IDC(cc)
			if newID != oldID {
				t.Errorf("%v != %v", newVal, cc)
			}
			found++
		}
	}
	if found < 2 {
		t.Errorf("found %d < 2 items", found)
	}
	{
		savedSetting, ok := collection.Get(1)
		if !ok {
			t.Error("failed to retrieve from database")
		}
		newSetting, ok := term.LoadSetting(savedSetting)
		if !ok {
			t.Errorf("failed to load setting %v", savedSetting)
		}
		newID := newSetting.ID
		oldID := setting.ID
		if newID != oldID {
			t.Errorf("%v != %v", newSetting, setting)
		}
	}
	{
		savedC, ok := collection.Get(2)
		if !ok {
			t.Error("failed to retriev from database")
		}
		newC, ok := term.LoadC(savedC)
		if !ok {
			t.Errorf("failed to load %v", savedC)
		}
		newID := term.IDC(newC)
		oldID := term.IDC(cc)
		if newID != oldID {
			t.Errorf("%v != %v", newC, cc)
		}
	}
}
Exemplo n.º 16
0
func init() {
	//dynamics.AddNativeResponse(FallThrough, 1, dynamics.Args1(fallThrough))
	dynamics.AddNativeResponse(DisplayTemplate, 1, dynamics.Args1(displayTemplate))
	dynamics.AddNativeResponse(GetActionInput, 2, dynamics.Args2(getInput))
	dynamics.AddNativeResponse(ParseInputAsAction, 2, dynamics.Args2(parseInput))

	var s *term.SettingS
	s = dynamics.ExpectQuestion(term.InitS(), FallThrough, "Q", "setting")
	s = dynamics.AddSimple(s, term.AskS(GetTemplate.S(term.Sr("setting"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A", "template")
	s = dynamics.AddSimple(s, term.AskS(ElicitActionQ.S(term.Sr("template"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A2", "action")
	s = dynamics.AddSimple(s, term.AskS(MakeTransition.S(term.Sr("action"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A3", "transition")
	s = dynamics.AddSimple(s, term.AskS(ShouldRecord.S(term.Sr("action"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "AA", "should")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("should")))
	s.AppendTemplate(core.Yes)
	s = dynamics.AddSimple(s, term.AskS(SetTransition.S(term.Sr("transition"), term.Sr("template"))))
	s = dynamics.ExpectAnswer(s, core.OK, "A4")
	s = dynamics.AddSimple(s, term.ReturnS(TakeTransition.S(term.Sr("transition"))))

	s = dynamics.ExpectQuestion(term.InitS(), ShouldRecord, "Q", "action")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("action")))
	s.AppendTemplate(represent.QuotedActionC, "act", "args", "indices")
	s = dynamics.AddSimple(s, term.ViewS(term.Sr("act")))
	for act, template := range represent.ActionLookup {
		t := s.Copy().AppendTemplate(template)
		switch act {
		case term.Replace, term.Correct, term.Replay:
			dynamics.AddSimple(t, term.ReturnS(core.Answer.S(core.No.S())))
		default:
			dynamics.AddSimple(t, term.ReturnS(core.Answer.S(core.Yes.S())))
		}
	}

	s = dynamics.ExpectQuestion(term.InitS(), MakeTransition, "Q", "action")
	s = dynamics.AddSimple(s, term.ReturnS(core.Answer.S(represent.QuotedSimpleTransition.S(term.Sr("action")))))

	s = dynamics.ExpectQuestion(term.InitS(), GetTemplate, "Q", "setting")
	t := dynamics.AddSimple(s, term.ViewS(term.Sr("setting")))
	s = t.Copy().AppendTemplate(represent.QuotedTemplate, "parts")
	s = dynamics.AddSimple(s, term.ReturnS(core.Answer.S(term.Sr("setting"))))
	s = t.Copy().AppendTemplate(represent.QuotedSettingT, "template", "args")
	s = dynamics.AddSimple(s, term.ReturnS(core.Answer.S(term.Sr("template"))))

	s = dynamics.ExpectQuestion(term.InitS(), ElicitActionQ, "Q", "setting")
	s = dynamics.AddSimple(s, term.AskS(GetTemplate.S(term.Sr("setting"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A", "template")
	s = dynamics.AddSimple(s, term.AskS(ElicitActionQTemplate.S(term.Sr("template"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A2", "action")
	s = dynamics.AddSimple(s, term.ReturnS(core.Answer.S(term.Sr("action"))))

	s = dynamics.ExpectQuestion(term.InitS(), ElicitActionQTemplate, "Q", "template")
	s = dynamics.AddSimple(s, term.AskS(similarity.GetHints.S(term.Sr("template"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A", "hints")
	s = dynamics.AddSimple(s, term.AskS(similarity.GetTools.S(term.Sr("template"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A2", "tools")
	s = dynamics.AddSimple(s, term.AskS(ElicitActionQTemplateHints.S(
		term.Sr("template"), term.Sr("hints"), term.Sr("tools"),
	)))
	s = dynamics.ExpectAnswer(s, core.Answer, "A3", "action")
	s = dynamics.AddSimple(s, term.ReturnS(core.Answer.S(term.Sr("action"))))

	s = dynamics.ExpectQuestion(term.InitS(), ElicitActionQTemplateHints, "Q", "template", "hints", "tools")
	s = dynamics.AddSimple(s, term.AskS(meta.Clear.S()))
	s = dynamics.ExpectAnswer(s, core.OK, "A")
	s = dynamics.AddSimple(s, term.AskS(DisplayTemplate.S(term.Sr("template"))))
	s = dynamics.ExpectAnswer(s, Names, "A2", "names")
	s = dynamics.AddSimple(s, term.AskS(similarity.DisplayTools.S(term.Sr("tools"))))
	s = dynamics.ExpectAnswer(s, similarity.ToolMapping, "A3", "toolmap")
	s = dynamics.AddSimple(s, term.AskS(similarity.DisplayHints.S(term.Sr("hints"), term.Sr("names"))))
	s = dynamics.ExpectAnswer(s, similarity.HintStrings, "A4", "hintstrings")
	s = dynamics.AddSimple(s, term.AskS(GetActionInput.S(term.Sr("hintstrings"), term.Sr("toolmap"))))
	s = dynamics.ExpectAnswer(s, core.Answer, "A5", "input")
	s = dynamics.AddSimple(s, term.AskS(ParseInputAsAction.S(term.Sr("input"), term.Sr("names"))))

	t = dynamics.ExpectAnswer(s.Copy(), core.Answer, "A6", "action")
	t = dynamics.AddSimple(t, term.ReturnS(core.Answer.S(term.Sr("action"))))

	t = dynamics.ExpectAnswer(s.Copy(), GoMeta, "A6")
	t = dynamics.AddSimple(t, term.MetaS())

	dynamics.AddNativeResponse(ActionQ, 1, dynamics.Args1(findAction))
	dynamics.AddNativeResponse(SetTransition, 2, dynamics.Args2(setTransition))
	dynamics.AddNativeResponse(GetTransition, 1, dynamics.Args1(getTransition))
	dynamics.AddNativeResponse(GetContinuations, 1, dynamics.Args1(getContinuations))
	dynamics.AddNativeResponse(AllSettings, 0, dynamics.Args0(allSettings))
}