-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace std submodule by a basic folder and update README.md
- Loading branch information
Showing
10 changed files
with
354 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# The Noc Standard Library | ||
|
||
This repository contains all the STD files of the Noc language. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Bool functions | ||
*/ | ||
|
||
load std:stack | ||
load seq | ||
|
||
def if = { | ||
--- | ||
if statement | ||
|
||
(example) | ||
["else"] ["then"] True if => ["then"] | ||
--- | ||
[ | ||
[[True] [swap pop unquote]] | ||
[[False] [pop unquote]] | ||
] case | ||
} | ||
|
||
def not = { | ||
--- | ||
Logical operator | ||
Get False if the value is True and True if the value is False | ||
|
||
(example) | ||
True not => [False] | ||
False not => [True] | ||
--- | ||
[ | ||
[[True] [False]] | ||
[[False] [True]] | ||
] case | ||
} | ||
|
||
def eq = { | ||
--- | ||
Check if 2 values are equal | ||
|
||
(example) | ||
5 6 eq => [False] | ||
[Right "ok"] [Right "ok"] eq => [True] | ||
--- | ||
quote quote [[True]] cat quote [[[_] [False]]] cat case | ||
} | ||
|
||
def (==) = { | ||
--- | ||
Check if 2 values are equal | ||
|
||
(example) | ||
5 6 eq => [False] | ||
[Right "ok"] [Right "ok"] eq => [True] | ||
--- | ||
eq | ||
} | ||
|
||
def (!=) = { | ||
--- | ||
Compare if the first value is different than the second value | ||
|
||
(example) | ||
5 6 != => [True] | ||
--- | ||
eq not | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Dict functions | ||
*/ | ||
|
||
load std:stack | ||
load seq | ||
|
||
def keys = { | ||
--- | ||
Get the dictionnary keys | ||
|
||
(example) | ||
[["A" 1] ["B" 2] ["C" 3]] keys => [["A" "B" "C"]] | ||
--- | ||
[unquote pop] step | ||
} | ||
|
||
def values = { | ||
--- | ||
Get the dictionnary values | ||
|
||
(example) | ||
[["A" 1] ["B" 2] ["C" 3]] values => [[1 2 3]] | ||
--- | ||
[unquote swap pop] step | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
FS functions | ||
*/ | ||
|
||
load fs | ||
|
||
def write = { | ||
--- | ||
'Write' action of the open function | ||
|
||
(example) | ||
"filename" "content" write => [] | ||
--- | ||
"w" open | ||
} | ||
|
||
def read = { | ||
--- | ||
'Read' action of the open function | ||
|
||
(example) | ||
"filename" read => ["content"] | ||
--- | ||
"" "r" open | ||
} | ||
|
||
def append = { | ||
--- | ||
'Append' action of the open function | ||
|
||
(example) | ||
"filename" "new content" append => [] | ||
--- | ||
"a" open | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
I/O functions | ||
*/ | ||
|
||
def putstrln = { | ||
--- | ||
putstr function with newline | ||
|
||
(example) | ||
"Hello, World!" putstrln | ||
Output: | ||
Hello, World | ||
--- | ||
"\n" cat putstr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
List functions | ||
*/ | ||
|
||
load std:stack | ||
load seq | ||
load std:bool | ||
|
||
def len' = { | ||
[ | ||
[[[]] [pop 0]] | ||
[[_] [1 swap popr pop dup len' +]] | ||
] case | ||
} | ||
|
||
def len = { | ||
--- | ||
Get a list's length | ||
|
||
(example) | ||
[1 2 3] len => [3] | ||
--- | ||
dup len' | ||
} | ||
|
||
def findByIndex = { | ||
--- | ||
Find a element in a list with his index. | ||
|
||
(example) | ||
2 [[0 "A"] [1 "B"] [2 "C"]] findByIndex | ||
=> ["C"] | ||
|
||
(or with the 'enumerate' function) | ||
2 ["A" "B" "C"] enumerate findByIndex | ||
--- | ||
swap dup 3 -1 rotNM | ||
[ | ||
unquote 4 1 rotNM == | ||
[ | ||
[[True] [dup]] | ||
[[False] [swap pop dup]] | ||
] case | ||
] step | ||
popr pop popr pop | ||
unquote | ||
} | ||
|
||
def enumerate = { | ||
--- | ||
Listing a list with a successive indexes | ||
|
||
(example) | ||
["A" "B" "C"] enumerate | ||
=> [[0 "A"] [1 "B"] [2 "C"]] | ||
--- | ||
-1 swap | ||
[swap 1 + dup 3 1 rotNM quote swap quote cat swap] step | ||
popr pop swap quote swap cat | ||
} | ||
|
||
def filter = { | ||
--- | ||
Filter a list following a predicat. | ||
|
||
(example) | ||
[1 2 3] [2 >] filter | ||
=> [3] | ||
--- | ||
[dup] swap <> | ||
[[pop] [] 3 -1 rotNM if] <> | ||
step | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Math functions | ||
*/ | ||
|
||
load std:stack | ||
load seq | ||
|
||
def pi = { | ||
--- | ||
The pi number | ||
--- | ||
3.141592653589793 | ||
} | ||
|
||
def mod = { | ||
--- | ||
Modulo operation | ||
|
||
(example) | ||
10 6 mod => [4] | ||
--- | ||
quote swap quote swap | ||
cat | ||
dup | ||
popr pop unquote swap | ||
unquote dup 3 rotNR | ||
/ int * - | ||
} | ||
|
||
def (%) = { | ||
--- | ||
Modulo operation | ||
|
||
(example) | ||
10 6 mod => [4] | ||
--- | ||
mod | ||
} | ||
|
||
def sqrt = { | ||
--- | ||
Square root of a number | ||
|
||
(example) | ||
25 sqrt => [5.0] | ||
--- | ||
0.5 ^ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Stack functions | ||
*/ | ||
|
||
load seq | ||
|
||
def quote = { | ||
--- | ||
Put value in a quote | ||
|
||
(example) | ||
5 quote => [5] | ||
--- | ||
[] swap pushr | ||
} | ||
|
||
def rotNR = { | ||
--- | ||
Rotate N elements 1 time (right) | ||
|
||
(example) | ||
stack: [1 2 3] | ||
2 rotNR => [3 1 2] | ||
--- | ||
1 rotNM | ||
} | ||
|
||
def rotNL = { | ||
--- | ||
Rotate N elements 1 time (left) | ||
|
||
(example) | ||
stack: [1 2 3 4] | ||
3 rotNR => [1 3 4 2] | ||
--- | ||
-1 rotNM | ||
} | ||
|
||
def swap = { | ||
--- | ||
Swap 2 top-stack elements | ||
|
||
(example) | ||
stack: [1 2 3] | ||
swap => [1 3 2] | ||
--- | ||
2 rotNR | ||
} | ||
|
||
def rot = { | ||
--- | ||
Rotate 3 top-stack elements | ||
|
||
(example) | ||
stack: [1 2 3 4] | ||
rot => [1 3 4 2] | ||
--- | ||
3 rotNL | ||
} | ||
|
||
def (<>) = { | ||
--- | ||
Concatenate 2 values (string and quotes) | ||
(example) | ||
[1] [2] <> => [1 2] | ||
"Hello, " "World!" <> => "Hello, World!" | ||
--- | ||
cat | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
String functions | ||
*/ | ||
|
||
load str | ||
|
||
def ($) = { | ||
--- | ||
Convert a string to a quote of chars | ||
(example) | ||
"abc" $ => ['a' 'b' 'c'] | ||
--- | ||
chars | ||
} |