Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( B = literal.B F = literal.F I = literal.I T = literal.T CmdError = assign.CmdError CmdErrorCtx = assign.CmdErrorCtx )
View Source
var Blob []byte
View Source
var FactorialCheck = []rt.Execute{ &debug.Expect{ Value: &core.CompareNum{ A: F(6), Is: core.C_Comparison_EqualTo, B: &assign.CallPattern{ PatternName: "factorial", Arguments: []assign.Arg{{ Name: "num", Value: &assign.FromNumber{Value: F(3)}, }}}, }, }, }
run 3! factorial
View Source
var FactorialDecreaseRule = []rt.Execute{ &core.ChooseBranch{ If: &core.CompareNum{ Markup: UserComment("above zero, subtract one"), A: core.Variable("num"), Is: core.C_Comparison_GreaterThan, B: F(0)}, Exe: FactorialMulMinusOne, }, }
override the default behavior:
View Source
var FactorialDefaultRule = []rt.Execute{ &assign.SetValue{ Markup: UserComment("by default, return one"), Target: core.Variable("num"), Value: &assign.FromNumber{Value: I(1)}, }, }
the default rule: use the number 1
View Source
var FactorialJs string
View Source
var FactorialMulMinusOne = []rt.Execute{ &assign.SetValue{ Target: core.Variable("num"), Value: &assign.FromNumber{Value: &core.MultiplyValue{ A: core.Variable("num"), B: &core.SubtractValue{ A: core.Variable("num"), B: I(1), }, }}}, }
subtracts 1 from the num and multiples by one
View Source
var FactorialStory = story.StoryFile{ Statements: []story.StoryStatement{ &story.DefineTest{ TestName: "factorial", Exe: FactorialCheck, }, &story.DefinePattern{ PatternName: T("factorial"), Requires: []story.FieldDefinition{ &story.NumberField{ Markup: UserComment("just one argument, a number called 'num'"), Name: T("num"), }}, Provides: []story.FieldDefinition{&story.NumberField{ Markup: UserComment("the result uses the same variable as the pattern input does"), Name: T("num"), }}, Exe: FactorialDefaultRule, }, &story.RuleForPattern{ PatternName: T("factorial"), Exe: FactorialDecreaseRule, }}, }
a program that can check factorials
View Source
var SayPattern = testpat.Pattern{ Name: "say me", Labels: []string{"num"}, Fields: []g.Field{ {Name: "num", Affinity: "number", Type: ""}, }, Rules: []rt.Rule{{ Name: "default", Exe: SayIt("Not between 1 and 3."), }, { Name: "3b", Exe: []rt.Execute{&core.ChooseBranch{ If: &MatchNumber{3}, Exe: SayIt("San!")}, }, }, { Name: "3a", Exe: []rt.Execute{&core.ChooseBranch{ If: &MatchNumber{3}, Exe: SayIt("Three!")}, }, }, { Name: "2", Exe: []rt.Execute{&core.ChooseBranch{ If: &MatchNumber{2}, Exe: SayIt("Two!")}, }, }, { Name: "1", Exe: []rt.Execute{&core.ChooseBranch{ If: &MatchNumber{1}, Exe: SayIt("One!")}, }, }}, }
the rules defined last run first
Functions ¶
func DetermineSay ¶
func DetermineSay(i int) *assign.CallPattern
func UserComment ¶
Types ¶
type Flow ¶
type Flow struct {
// contains filtered or unexported fields
}
Flow creates a debug flow to simulate spec generation
type MatchNumber ¶
type MatchNumber struct {
Val int
}
Click to show internal directories.
Click to hide internal directories.