Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yangtau/hedgehog
a toy programming language
https://github.com/yangtau/hedgehog
compiler interpreter programming-language toy-programming-language
Last synced: about 2 months ago
JSON representation
a toy programming language
- Host: GitHub
- URL: https://github.com/yangtau/hedgehog
- Owner: yangtau
- License: mit
- Created: 2019-02-14T03:25:41.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-15T11:22:47.000Z (about 2 years ago)
- Last Synced: 2024-08-03T18:14:50.506Z (5 months ago)
- Topics: compiler, interpreter, programming-language, toy-programming-language
- Language: C
- Homepage:
- Size: 747 KB
- Stars: 32
- Watchers: 4
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- AwesomeInterpreter - hedgehog
README
# Hedgehog
It is hard to design a good programming language.
```
fn fac(n) {
if n <=1 { return 1 } else { return n * fac(n-1) }
}# tail call version:
fn fac_tailcall(n) {
fn f(acc, n) {
if n <= 1 { return acc} else { return fn(acc*n, n-1) }
}
return f(1, n)
}
```
## ModulesA module is an anonymous function.
```
# math
m = {}
m.pi = 3.14159m.add = fn (x, y) { return x+y }
return m
``````
math = require("math") # import math module
print = require("std").printmath.add(3, 9) # 12
print(math.pi) --> 3.14159
``````
# a modules looks like this for interpreter:
fu () {
m = {}
m.pi = 3.14159m.add = fn (x, y) { return x+y }
return m
}()
```## functional
```
fn filter(t, predicate) {
res = {}
for k, v in t {
if predicate(v) {
res[k] = v
}
}
return res
}fn map(t, f) {
res = {}
for k, v in t {
res[k] = f(v)
}
return res
}# `x.f(y)` is a syntax sugar for `f(x, y)`
{1, 2, 3, 4}.
filter(fn (x) {return x>1}).
map(fn (x) {return x+1}) # --> 3, 4, 5
```