Skip to content

Commit

Permalink
replace std submodule by a basic folder and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mortim committed Aug 9, 2022
1 parent da68c2b commit 23054fe
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 7 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# The Noc Programming Language

This repository contains the Noc interpreter and the Noc Standard Library. For more informations, you can check the [Noc website](https://noc-lang.github.io).

<img src="https://raw.githubusercontent.com/noc-lang/noc-lang.github.io/master/assets/icon.png" alt="Noc icon" align=right width="170" />
This repository contains the Noc interpreter and the Noc Standard Library.

## Features
- Stack-based language
Expand All @@ -16,11 +14,10 @@ This repository contains the Noc interpreter and the Noc Standard Library. For m

## Get Noc

To install the Noc interpreter, you can check this [Installation guide](https://noc-lang.github.io/book/installation.html).
To install the Noc interpreter, you can check this [Installation guide](https://github.com/mortim/noc/wiki/Installation).

## Resources
- [The Noc Book](https://noc-lang.github.io/book)
- [Discord bot](https://github.com/noc-lang/bot)
- [The Noc Book](https://github.com/mortim/noc/wiki)

## Contributing
To contribute to The Noc Programming Language, you can add an [issue](https://github.com/noc-lang/noc/issues/) to report some bugs, ask for a new feature, questions, etc... Or you can fork this repository to evolve her with the [pull requests](https://github.com/noc-lang/noc/pulls).
To contribute to The Noc Programming Language, you can add an [issue](https://github.com/mortim/noc/issues/) to report some bugs, ask for a new feature, questions, etc... Or you can fork this repository to evolve her with the [pull requests](https://github.com/mortim/noc/pulls).
3 changes: 3 additions & 0 deletions std/README.md
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.
67 changes: 67 additions & 0 deletions std/bool.noc
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
}

26 changes: 26 additions & 0 deletions std/dict.noc
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
}
35 changes: 35 additions & 0 deletions std/fs.noc
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
}
15 changes: 15 additions & 0 deletions std/io.noc
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
}
73 changes: 73 additions & 0 deletions std/list.noc
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
}
48 changes: 48 additions & 0 deletions std/math.noc
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 ^
}
69 changes: 69 additions & 0 deletions std/stack.noc
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
}
14 changes: 14 additions & 0 deletions std/string.noc
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
}

0 comments on commit 23054fe

Please sign in to comment.