Skip to content

Domain-specific language for units and arithmetic calculations

Notifications You must be signed in to change notification settings

adelhult/hypatia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hypatia

Hypatia is a experimental language and notebook environment well suited for both simple calculations and larger homework problems.

Try it in your browser

Many features are yet to be implemented, see the roadmap.

A taste of the language

// Physical quantites
totalTime = 20 s + 3 h

// Declare your own units
// (although most should already be included in the prelude)
unit mile mi = 1 609 m

// Variables
x = 2 m

// Block expressions
area = {
   height = 2 km
   width = 10 m
   height * width
}

// Conditionals
foo = if true {
   20
} else {
   30
}

// Hex, scientific and binary literals
data = 0x20 bytes
header = 0b1010 bit
bigNumber = 3.2E20

// Functions (todo)
f(x) = x + 10
isVeryLong(length) = length > 2 km

// Strings (todo)
name = "Hypatia"
"Hi \(name)"

// Latex output (todo)

Note: more demos, can be found in the core/samples directory.

Development

core contains the parser and interpreter written in Rust. Run cargo test to check a test suite of sample programs.

cd core
cargo test      # test all of the sample files

web is the notebook interface written in Typescript using React. Run this to try it locally.

cd web
npm install     # install the dependencies
npm run wasm    # build the wasm web bindings
npm run dev     # start a vite development server

Note: every commit to the main branch will update the online version using a github actions workflow.

About

Domain-specific language for units and arithmetic calculations

Resources

Stars

Watchers

Forks

Languages