Otter
Blueprints
Otter
Upstream Blueprint Tested
Console Calculator Blueprint
Arithmetic calculator with range clamping, interpolation, and formatted output.
Architecture & Runtime Preview
Otter >=1.0.1Uses math-utils.clamp to ensure numbers stay within defined limits, preventing overflow or unexpected values.
- 1Raw Number Input (input)
- 2Clamp within Range (pack-call: math-utils.clamp)
- 3Display Result (output)
Source Code (4 files)
{
"schemaVersion": 1,
"id": "otter-official/console-calculator",
"version": "1.0.0",
"title": "Console Calculator",
"summary": "Arithmetic calculator with range clamping, interpolation, and formatted output.",
"targets": ["console"],
"requiresOtter": ">=1.0.1",
"packs": [
{ "id": "otter-official/math-utils", "version": "1.0.1" }
],
"configuration": [
{
"id": "clampMin",
"label": "Minimum Allowed Value",
"type": "number",
"default": 0,
"description": "Lower bound constraint for calculations"
},
{
"id": "clampMax",
"label": "Maximum Allowed Value",
"type": "number",
"default": 100,
"description": "Upper bound constraint for calculations"
}
],
"nodes": [
{
"id": "inputVal",
"title": "Raw Number Input",
"kind": "input",
"inputs": [],
"outputs": [{ "name": "val", "type": "number" }],
"description": "Source numeric value to process"
},
{
"id": "clampOperation",
"title": "Clamp within Range",
"kind": "pack-call",
"capability": "math-utils.clamp",
"inputs": [
{ "name": "val", "type": "number", "required": true },
{ "name": "min", "type": "number", "required": true },
{ "name": "max", "type": "number", "required": true }
],
"outputs": [{ "name": "clamped", "type": "number" }],
"description": "Bound the number between minimum and maximum"
},
{
"id": "displayResult",
"title": "Display Result",
"kind": "output",
"inputs": [
{ "name": "result", "type": "number", "required": true }
],
"outputs": [],
"description": "Print the clamped outcome"
}
],
"edges": [
{ "from": "inputVal.val", "to": "clampOperation.val", "label": "raw value" },
{ "from": "clampOperation.clamped", "to": "displayResult.result", "label": "bounded value" }
],
"generatedFiles": [
{
"path": "src/calculator.ot",
"template": "templates/calculator.ot.tmpl"
}
],
"explanations": {
"beginner": "Takes an input number, clamps it between the minimum and maximum boundaries, and prints the result.",
"intermediate": "Uses math-utils.clamp to ensure numbers stay within defined limits, preventing overflow or unexpected values.",
"advanced": "Demonstrates pure functional composition of arithmetic bounds checking using otter-official/math-utils."
},
"tests": [
"tests/test.ot"
]
}
# Generated by Otter Blueprint: otter-official/console-calculator 1.0.0
# Standard editable Otter 1.0.1 source code
use "${import:otter-official/math-utils}"
minBound is ${clampMin}
maxBound is ${clampMax}
# Input value
rawInput is 125
# Calculation: clamp to valid range
bounded is clamp rawInput minBound maxBound
say "Raw input:" rawInput
say "Bounded within" minBound ".." maxBound ":" bounded
# Integration tests for console-calculator Blueprint
use "../../../../packs/otter-official/math-utils/src/main.ot"
# Test 1: Value below lower bound
lowVal is 0 minus 20
clampedLow is clamp lowVal 0 100
if clampedLow is 0
say "test 1 passed: low value clamped to 0"
.
# Test 2: Value in range
midVal is 55
clampedMid is clamp midVal 0 100
if clampedMid is 55
say "test 2 passed: mid value unchanged"
.
# Test 3: Value above upper bound
highVal is 200
clampedHigh is clamp highVal 0 100
if clampedHigh is 100
say "test 3 passed: high value clamped to 100"
.
say "All console-calculator tests passed."
# Demo for console-calculator Blueprint
use "../../../../packs/otter-official/math-utils/src/main.ot"
say "=== Console Calculator Blueprint Demo ==="
minBound is 0
maxBound is 100
negVal is 0 minus 15
testValues are
negVal
42
150
.
for each v in testValues
clamped is clamp v minBound maxBound
say "Input:" v "=> Clamped:" clamped
.
Installation & Usage
otter blueprint explain otter-official/console-calculator
otter blueprint apply otter-official/console-calculator --project ./my-app
Takes an input number, clamps it between the minimum and maximum boundaries, and prints the result.