Ejemplo n.º 1
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"))))
}
Ejemplo n.º 2
0
func Str(s string) term.T {
	return term.Str(s)
	/*
		runes := make([]term.T, 0)
		for _, c := range s {
			runes = append(runes, strings.Rune.T(Int(int(c))))
		}
		return strings.ByRunes.T(List(runes))
	*/
}
Ejemplo n.º 3
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))
}
Ejemplo n.º 4
0
func getID(d dynamics.Dwimmer, s *term.SettingT, quoted term.T) term.T {
	var result int
	switch quoted.Head() {
	case represent.QuotedSetting:
		setting, err := represent.ToSetting(d, quoted)
		if err != nil {
			return term.Make("was asked to find the ID of a setting, " +
				"but while converting to a setting received []").T(err)
		}
		result = int(setting.ID)
	case term.Int(0).Head():
		result = int(term.IDer.PackInt(int(quoted.(term.Int))).(intern.ID))
	case term.Str("").Head():
		result = int(term.IDer.PackString(string(quoted.(term.Str))).(intern.ID))
	}
	return core.Answer.T(represent.Int(result))
}
Ejemplo n.º 5
0
func SuggestedTemplates(d dynamics.Dwimmer, s *term.Setting, n int, templatess ...[]*term.Template) (templates []*term.Template) {
	for _, x := range templatess {
		templates = append(templates, x...)
	}
	if s.Size == 0 {
		return
	}
	defer func() {
		if len(templates) > n {
			templates = templates[:n]
		}
	}()
	ShouldAddTemplate := func(template *term.Template) bool {
		for _, other := range templates {
			if other.String() == template.String() {
				return false
			}
		}
		excluded := []term.T{
			term.Int(0), term.Str(""), term.Quoted{}, term.Wrapper{},
		}
		for _, exclude := range excluded {
			if template == exclude.Head().Template() {
				return false
			}
		}
		excludedIDs := []term.TemplateID{
			dynamics.ParentChannel, dynamics.OpenChannel,
		}
		for _, exclude := range excludedIDs {
			if template.ID() == exclude {
				return false
			}
		}
		return true
	}
	AddTemplate := func(template *term.Template) {
		if ShouldAddTemplate(template) {
			templates = append(templates, template)
		}
	}
	AddTemplates := func(action term.ActionC) {
		actionTemplates := action.AllTemplates()
		for _, template := range actionTemplates {
			AddTemplate(template)
		}
	}

	actions, _ := Suggestions(d, s, n)
	for _, action := range actions {
		AddTemplates(action)
	}
	lastLine := s.Last
	switch line := lastLine.(type) {
	case term.ActionCID:
		AddTemplates(line.ActionC())
	case term.TemplateID:
		AddTemplate(line.Template())
	}
	if len(templates) < n {
		templates = SuggestedTemplates(d, s.Previous, n, templates)
	}
	return
}
Ejemplo n.º 6
0
func bracketed(d dynamics.Dwimmer, s *term.SettingT, a term.T) term.T {
	return core.Answer.T(term.Str(fmt.Sprint("[%s]", string(a.(term.Str)))))
}
Ejemplo n.º 7
0
func concat(d dynamics.Dwimmer, s *term.SettingT, a, b term.T) term.T {
	return core.Answer.T(term.Str(string(a.(term.Str)) + string(b.(term.Str))))
}