debug

package
v0.24.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

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: []rt.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 SayIt

func SayIt(s string) []rt.Execute

func UserComment

func UserComment(s string) map[string]any

Types

type Flow

type Flow struct {
	// contains filtered or unexported fields
}

Flow creates a debug flow to simulate spec generation

func MakeFlow

func MakeFlow(op interface{}) Flow

MakeFlow indicates the start of a set of key-value pairs. Unlike the other block types, the block itself is not mutable -- only its values.

func (Flow) GetFlow

func (n Flow) GetFlow() interface{}

func (Flow) GetLede

func (n Flow) GetLede() string

func (Flow) GetType

func (n Flow) GetType() string

func (Flow) SetFlow

func (n Flow) SetFlow(i interface{}) bool

type MatchNumber

type MatchNumber struct {
	Val int
}

func (*MatchNumber) GetBool

func (op *MatchNumber) GetBool(run rt.Runtime) (ret rt.Value, err error)

type SayMe

type SayMe struct {
	Num float64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL