closure_ints

package
v0.0.0-...-2ff796e Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MPL-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arg

func Arg(env *Env) int

func Nop

func Nop(env *Env)

Types

type Env

type Env struct {
	Binds []int
	Outer *Env
}

func NewEnv

func NewEnv(outer *Env) *Env

type Func

type Func func(arg int) int

func DeclCollatz

func DeclCollatz(env *Env) Func
  interpreted version of:

	func collatz(n int) {
		for n > 1 {
			if n&1 != 0 {
				n = ((n * 3) + 1) / 2
			} else {
				n = n / 2
			}
		}
	}

func DeclFibonacci

func DeclFibonacci(env *Env) Func
  interpreted version of:

	func fibonacci(n int) int {
		if (n <= 2) {
			return 1
		}
		return fibonacci(n-1) + fibonacci(n-2)
	}

func DeclSum

func DeclSum(env *Env) Func
  interpreted version of:

	func sum(n int) int {
		total := 0
		for i := 1; i <= n; i++ {
			total += i
		}
		return total
	}

type SReturnInt

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

type X0

type X0 func(*Env)

func Block

func Block(list ...X0) X0

func DeclVar

func DeclVar(idx int, expr XInt) X0

func For

func For(init X0, pred XBool, post X0, body X0) X0

func If

func If(pred XBool, then, els X0) X0

func Return

func Return(expr XInt) X0

func VarInc

func VarInc(idx int) X0

func VarSet

func VarSet(idx int, expr XInt) X0

type XBool

type XBool func(*Env) bool

func Less

func Less(lhs, rhs XInt) XBool

func Lesseq

func Lesseq(lhs, rhs XInt) XBool

func Noteq

func Noteq(lhs, rhs XInt) XBool

type XFunc

type XFunc func(env *Env) Func

func MakeFunc

func MakeFunc(body X0) XFunc

type XInt

type XInt func(*Env) int

func Add

func Add(lhs, rhs XInt) XInt

func Bitand

func Bitand(lhs, rhs XInt) XInt

func Call

func Call(fun *Func, arg XInt) XInt

func Const

func Const(n int) XInt

func Mul

func Mul(lhs, rhs XInt) XInt

func Rshift

func Rshift(lhs, rhs XInt) XInt

func Sub

func Sub(lhs, rhs XInt) XInt

func Var

func Var(idx int) XInt

Jump to

Keyboard shortcuts

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