Skip to content

Scalar function calls ​

quadruple calls double-value twice and returns the composed scalar result. This is the smallest example of function composition without sequence traversal.

Stated source ​

Source mapGrammarVocabularyTypeName / reference
Define quadruple as a function.It accepts an integer named input.Call double-value with the input as input, storing the result as doubled.Call double-value with the doubled as input, storing the result as quadrupled.Return the quadrupled.Define double-value as a function.It accepts an integer named input.Return the doubled value of the input.

Generated Go ​

go
package generated

import (
	"errors"
	"math"
)

func Quadruple(p0 int64) (int64, error) {
	r0, err0 := DoubleValue(p0)
	if err0 != nil {
		return 0, err0
	}
	_ = r0
	r1, err1 := DoubleValue(r0)
	if err1 != nil {
		return 0, err1
	}
	_ = r1
	return r1, nil
}

func DoubleValue(p0 int64) (int64, error) {
	v1 := p0
	_ = v1
	if (v1 > 0 && v1 > math.MaxInt64-v1) || (v1 < 0 && v1 < math.MinInt64-v1) {
		return 0, errors.New("integer overflow")
	}
	v2 := v1 + v1
	return v2, nil
}

Download the Stated source · Download the generated Go

Stated compiles controlled English deterministically. It does not call an LLM at compile time.