Skip to content

Latest commit

 

History

History
147 lines (103 loc) · 4.72 KB

File metadata and controls

147 lines (103 loc) · 4.72 KB

SDGScript 🌱

SDGScript is a small programming language with a sustainability theme. It is playful to write, and it runs on a real tree-walking interpreter that ships as a single Go binary.

The footprint example in SDGScript

The sustainability words carry real semantics. Unused values are rejected as waste, pure functions marked renewable have their results reused, a block can run under an op budget, and any run can end with a metered sustainability report.

Design

Each part of the theme corresponds to a feature you would actually reach for:

Theme What it does
Waste is an error Unused bindings are rejected, so "nothing goes to landfill"
renewable functions Pure functions (no I/O, no external mutation), memoized because their outputs are recyclable
budget N ops { } Fuel-metered execution; a block that overspends its op budget fails
Sustainability report Real counters for ops and allocations and recycled results, plus an estimated CO₂e figure
The 17 SDGs Namespace for the report sections and the future standard library

Grow a binding and never read it, and the program refuses to run.

See a waste error

A waste error from an unused binding

Built on

The interpreter is written in Go, so it ships as a single static binary with no toolchain to install. Internally it is a lexer feeding a Pratt parser feeding a tree-walking evaluator.

A later sdg build --renewable mode can transpile to C or Nim, which is where the "energy efficient" claim becomes literally true rather than a bit.

Language tour

# grow declares a binding (plant a seed). Reuse it, or it counts as waste.
grow footprint = renewable fn(km) {
    harvest km * 0.12          # harvest returns
}

grow trips = [10, 20, 10, 20, 10]
grow total = 0.0

sustain t in trips {           # sustain is the foreach loop
    total = total + footprint(t)   # repeated inputs reuse recycled results
}

report total                   # report prints, and feeds the footprint meter

Keywords

grow (declare), fn / renewable fn, harvest (return), sustain … in … (foreach), report (print), budget N ops { }, if / else, true / false.

Builtins

len(x), range(n), push(arr, v) which returns a new array rather than mutating in place, and str(x).

Run it

go build -o sdg .
./sdg run examples/footprint.sdg --report
./sdg repl

Pass --report to print the sustainability summary after a run.

See a run and its report

A footprint program and its sustainability report

There is a man page too. Read it with man ./sdg.man.

Status

The MVP interpreter covers the lexer, parser, evaluator, waste detection, renewable purity with memoization, op budgets, the sustainability report, a REPL, and a handful of builtins.

Roadmap

  1. Gradual type checker, framed as "long-term planning"
  2. Bytecode VM for a more precise fuel meter
  3. sdg build --renewable native transpile target
  4. SDG-namespaced standard library (a goal13 profiler, goal12 memory limits, and so on)

Disclaimer

SDGScript is an independent hobby project. It is not affiliated with, endorsed by, or connected to the United Nations or its Sustainable Development Goals programme. References to the SDGs are a theme and imply no partnership with anyone.

The sustainability report is not a scientific instrument. Its counters reflect real measurements of the interpreter's work, but the CO₂e figure and the renewability score come from invented coefficients with no real-world basis. Do not cite these numbers anywhere that matters. Using SDGScript will not offset your emissions or make any software genuinely greener.

License and warranty

The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.

Released under the MIT License. See the LICENSE file for the full text.

Citation

If you reference SDGScript in written work, a BibTeX entry is below. Machine metadata also lives in CITATION.cff.

BibTeX
@software{sdgscript,
  title   = {SDGScript: the sustainable programming language},
  author  = {{The SDGScript project}},
  year    = {2026},
  version = {0.1.0},
  url     = {https://github.com/sdgscript/sdg}
}