Uttr is a programming language for processing JSON.
$ stack build
$ stack exec uttr-exe
> "Hello world"
"Hello world"
> 1 + 2
3
$ stack exec uttr-exe examples/quicksort.uttr
- Purely functional
- Pattern matching based
- Non-deterministic
- Dynamically typed
- Number:
1
1.5
- String:
"foo"
- Boolean:
true
false
- Null:
null
- Object:
{a: "foo", b: 123}
- List:
["foo", 123]
- Function
- Closure:
[x=x+1]
+
-
*
/
%
<
>
<=
>=
==
!=
&&
||
objectOrList["property"]
{a:123}["a"] == 123
[1, 2, 3][1] == 2
object.property
{a:123}.a == 123
- cons
:
1 : 2 : [3, 4] == [1, 2, 3, 4]
- spread
...
{a: 1, ...{a: 2, b: 3, c: 4}, b: 5} == {a: 2, b: 5, c: 4}
See data types.
And others:
- Template literal
> a = "world"
> `hello $a$`
"hello world"
> `1+2 is $1 + 2$!`
"1+2 is 3!"
> a = "Constant value"
> a
"Constant value"
> [a, b] = [1, 2]
> a
1
> b
2
> {a: a, b} = {a: 1, b: 2}
> a
1
> b
2
add(x, y) = x + y
If arity is 1, you can omit that bracket:
add1 x = x + 1
head(x:_) = x
head
(x:_) = x,
[] = null
evenOrOdd(x)
| x % 2 == 0 = "even!"
| x % 2 != 0 = "odd!"
or
evenOrOdd(x)
| x % 2 == 0 = "even!"
| true = "odd!"
f(x) = g(x)
{ g(x) = x + 1 }
> add(x, y) = x + y
> add(1, 2)
3
> [x = x + 1]
<closure>
> [x = x + 1](1)
2
> [1 = "one", 2 = "tow"](1)
"one"
> [x | x % 2 == 0 = "even!" | true = "odd!"](1)
"odd!"
> a = [() = "Hello"]
> a()
"Hello"
> b(x) = [() = x]
> c = b("hello")
> c()
"hello"
> [true="Same!", false="Different!"](1 == 1)
"Same!"
Similar to JavaScript
{
a: 1,
"b": 2,
["c"]: 3,
...4
}
Takes an any data and returns a readable string that represent the data.
Takes an any data and returns a string as JSON.
Takes a object and returns a list of pair of key and value contained the object.
> items({a: 1, b: 2})
[["a", 1], ["b", 2]]
Takes any data and returns type of the data.
> typeOf(0)
"number"
> typeOf("")
"string"
> typeOf(true)
"boolean"
> typeOf(null)
"null"
> typeOf([])
"list"
> typeOf({})
"object"