Exemple #1
0
func makeFunc(rift *lang.Rift, outerEnv collections.PersistentMap, f *lang.Func) func([]interface{}) interface{} {
	env := collections.ExtendPersistentMap(outerEnv)
	return func(args []interface{}) interface{} {
		ensureArity(len(f.Args()), len(args))
		for i, argRef := range f.Args() {
			env.Set(argRef.String(), args[i])
		}

		var lastValue interface{}
		for _, line := range f.Lines() {
			lastValue = evaluate(rift, env, line)
		}
		return lastValue
	}
}
Exemple #2
0
func Run(rifts []*lang.Node) {
	InitPredefs()
	env := collections.ExtendPersistentMap(Predefs)
	for _, riftNode := range rifts {
		rift := riftNode.Rift()
		if !rift.IsMain() {
			evalRift(rift, env)
		}
	}
	if main := mainRift(rifts); main != nil {
		evalRift(main, env)
	} else {
		// TODO: Serve functionality
	}
	logging.Debug("Final environment:")
	for k, v := range env.Freeze() {
		logging.Debug(" |- %s = %+v", k, v)
	}
}