Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flag syntax #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ Positional values can be gotten out of lists using the `at` operator, and keys u
20
```

A shortcut for a key whose value is `true` looks like this, called a flag:
```
> (list :yes)
(yes: true)
```

#### Variables
Variables are declared using `define` and `define-global`. Variables declared with `define` are available for use anywhere in subsequent expressions in the same scope, and `define-global` makes them globally available.
```
Expand Down Expand Up @@ -227,22 +221,12 @@ A function's parameter list can contain both positional and key parameters, wher
15
```

If the key's value is `true`, the same name as the key is used to bind the parameter's value. This makes it easy to define named parameters with flags:
```
> (let f (fn (a b: true) (+ a b))
(f 1 b: 2))
3
> (let f (fn (a :b) (+ a b)) ; use a flag
(f 10 b: 20))
30
```

Parameters in Lumen are always optional, and those without a supplied argument have the value `nil`:
```
> (let f (fn (a) a)
(f))
>
> (let f (fn (:b) (if (= b nil) 10 20))
> (let f (fn (b: b) (if (= b nil) 10 20))
(f a: 99))
10
```
Expand Down Expand Up @@ -270,7 +254,7 @@ Variables can be bound to values in a list at certain positions or key:
2
> ((fn ((a b: my-b)) (list a my-b)) (list 1 b: 2))
(1 2)
> (let ((a :b) (list 1 b: 2))
> (let ((a b: b) (list 1 b: 2))
b)
2
```
Expand All @@ -279,7 +263,7 @@ The `rest` key works with destructuring as it does with function parameters, whi
> (let ((a rest: as) (list 1 2 3))
(list a as))
(1 (2 3))
> (let ((a :rest) (list 1 2 3))
> (let ((a rest: rest) (list 1 2 3))
(list a rest))
(1 (2 3))
```
Expand Down
26 changes: 15 additions & 11 deletions bin/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,22 +503,22 @@ ____x69.js = "!";
____x69.lua = "not";
____x68["not"] = ____x69;
var ____x70 = [];
____x70["*"] = true;
____x70["/"] = true;
____x70["%"] = true;
____x70["*"] = "*";
____x70["/"] = "/";
____x70["%"] = "%";
var ____x71 = [];
var ____x72 = [];
____x72.js = "+";
____x72.lua = "..";
____x71.cat = ____x72;
var ____x73 = [];
____x73["+"] = true;
____x73["-"] = true;
____x73["+"] = "+";
____x73["-"] = "-";
var ____x74 = [];
____x74["<"] = true;
____x74[">"] = true;
____x74["<="] = true;
____x74[">="] = true;
____x74["<"] = "<";
____x74[">"] = ">";
____x74["<="] = "<=";
____x74[">="] = ">=";
var ____x75 = [];
var ____x76 = [];
____x76.js = "===";
Expand Down Expand Up @@ -567,8 +567,12 @@ var getop = function (op) {
if (__x82 === true) {
return op;
} else {
if (is63(__x82)) {
return __x82[target];
if (string63(__x82)) {
return __x82;
} else {
if (is63(__x82)) {
return __x82[target];
}
}
}
}, infix);
Expand Down
26 changes: 15 additions & 11 deletions bin/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -454,22 +454,22 @@ ____x69.js = "!"
____x69.lua = "not"
____x68["not"] = ____x69
local ____x70 = {}
____x70["*"] = true
____x70["/"] = true
____x70["%"] = true
____x70["*"] = "*"
____x70["/"] = "/"
____x70["%"] = "%"
local ____x71 = {}
local ____x72 = {}
____x72.js = "+"
____x72.lua = ".."
____x71.cat = ____x72
local ____x73 = {}
____x73["+"] = true
____x73["-"] = true
____x73["+"] = "+"
____x73["-"] = "-"
local ____x74 = {}
____x74["<"] = true
____x74[">"] = true
____x74["<="] = true
____x74[">="] = true
____x74["<"] = "<"
____x74[">"] = ">"
____x74["<="] = "<="
____x74[">="] = ">="
local ____x75 = {}
local ____x76 = {}
____x76.js = "==="
Expand Down Expand Up @@ -513,8 +513,12 @@ local function getop(op)
if __x82 == true then
return op
else
if is63(__x82) then
return __x82[target]
if string63(__x82) then
return __x82
else
if is63(__x82) then
return __x82[target]
end
end
end
end, infix)
Expand Down
39 changes: 16 additions & 23 deletions bin/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ read_string = function (str, more) {
var key63 = function (atom) {
return string63(atom) && _35(atom) > 1 && char(atom, edge(atom)) === ":";
};
var flag63 = function (atom) {
return string63(atom) && _35(atom) > 1 && char(atom, 0) === ":";
};
var expected = function (s, c) {
var ____id1 = s;
var __more = ____id1.more;
Expand Down Expand Up @@ -146,49 +143,45 @@ read_table[""] = function (s) {
};
read_table["("] = function (s) {
read_char(s);
var __r16 = undefined;
var __r15 = undefined;
var __l1 = [];
while (nil63(__r16)) {
while (nil63(__r15)) {
skip_non_code(s);
var __c4 = peek_char(s);
if (__c4 === ")") {
read_char(s);
__r16 = __l1;
__r15 = __l1;
} else {
if (nil63(__c4)) {
__r16 = expected(s, ")");
__r15 = expected(s, ")");
} else {
var __x2 = read(s);
if (key63(__x2)) {
var __k = clip(__x2, 0, edge(__x2));
var __v = read(s);
__l1[__k] = __v;
} else {
if (flag63(__x2)) {
__l1[clip(__x2, 1)] = true;
} else {
add(__l1, __x2);
}
add(__l1, __x2);
}
}
}
}
return __r16;
return __r15;
};
read_table[")"] = function (s) {
return error("Unexpected ) at " + s.pos);
};
read_table["\""] = function (s) {
read_char(s);
var __r19 = undefined;
var __r18 = undefined;
var __str1 = "\"";
while (nil63(__r19)) {
while (nil63(__r18)) {
var __c5 = peek_char(s);
if (__c5 === "\"") {
__r19 = __str1 + read_char(s);
__r18 = __str1 + read_char(s);
} else {
if (nil63(__c5)) {
__r19 = expected(s, "\"");
__r18 = expected(s, "\"");
} else {
if (__c5 === "\\") {
__str1 = __str1 + read_char(s);
Expand All @@ -197,25 +190,25 @@ read_table["\""] = function (s) {
}
}
}
return __r19;
return __r18;
};
read_table["|"] = function (s) {
read_char(s);
var __r21 = undefined;
var __r20 = undefined;
var __str2 = "|";
while (nil63(__r21)) {
while (nil63(__r20)) {
var __c6 = peek_char(s);
if (__c6 === "|") {
__r21 = __str2 + read_char(s);
__r20 = __str2 + read_char(s);
} else {
if (nil63(__c6)) {
__r21 = expected(s, "|");
__r20 = expected(s, "|");
} else {
__str2 = __str2 + read_char(s);
}
}
}
return __r21;
return __r20;
};
read_table["'"] = function (s) {
read_char(s);
Expand Down
39 changes: 16 additions & 23 deletions bin/reader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ end
local function key63(atom)
return string63(atom) and _35(atom) > 1 and char(atom, edge(atom)) == ":"
end
local function flag63(atom)
return string63(atom) and _35(atom) > 1 and char(atom, 0) == ":"
end
local function expected(s, c)
local ____id1 = s
local __more = ____id1.more
Expand Down Expand Up @@ -146,49 +143,45 @@ read_table[""] = function (s)
end
read_table["("] = function (s)
read_char(s)
local __r16 = nil
local __r15 = nil
local __l1 = {}
while nil63(__r16) do
while nil63(__r15) do
skip_non_code(s)
local __c4 = peek_char(s)
if __c4 == ")" then
read_char(s)
__r16 = __l1
__r15 = __l1
else
if nil63(__c4) then
__r16 = expected(s, ")")
__r15 = expected(s, ")")
else
local __x2 = read(s)
if key63(__x2) then
local __k = clip(__x2, 0, edge(__x2))
local __v = read(s)
__l1[__k] = __v
else
if flag63(__x2) then
__l1[clip(__x2, 1)] = true
else
add(__l1, __x2)
end
add(__l1, __x2)
end
end
end
end
return __r16
return __r15
end
read_table[")"] = function (s)
return error("Unexpected ) at " .. s.pos)
end
read_table["\""] = function (s)
read_char(s)
local __r19 = nil
local __r18 = nil
local __str1 = "\""
while nil63(__r19) do
while nil63(__r18) do
local __c5 = peek_char(s)
if __c5 == "\"" then
__r19 = __str1 .. read_char(s)
__r18 = __str1 .. read_char(s)
else
if nil63(__c5) then
__r19 = expected(s, "\"")
__r18 = expected(s, "\"")
else
if __c5 == "\\" then
__str1 = __str1 .. read_char(s)
Expand All @@ -197,25 +190,25 @@ read_table["\""] = function (s)
end
end
end
return __r19
return __r18
end
read_table["|"] = function (s)
read_char(s)
local __r21 = nil
local __r20 = nil
local __str2 = "|"
while nil63(__r21) do
while nil63(__r20) do
local __c6 = peek_char(s)
if __c6 == "|" then
__r21 = __str2 .. read_char(s)
__r20 = __str2 .. read_char(s)
else
if nil63(__c6) then
__r21 = expected(s, "|")
__r20 = expected(s, "|")
else
__str2 = __str2 .. read_char(s)
end
end
end
return __r21
return __r20
end
read_table["'"] = function (s)
read_char(s)
Expand Down
Loading