diff --git a/ROADMAP.md b/ROADMAP.md index fbfce72..053f216 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,7 +1,7 @@ # TODO CONCEPTS - [x] Functions -- [ ] imports +- [x] imports - [x] scopes of visibility - [ ] methods for arrays @@ -12,7 +12,7 @@ - [ ] command execution function - [ ] function for random - [x] delete variable -- [ ] types conversion +- [ ] types conversion `in process` - [ ] checking variable type - [x] checking for the existence of a variable - [x] create scopes without if, else, loop diff --git a/doc/main.md b/doc/main.md index e68c52c..af9c636 100644 --- a/doc/main.md +++ b/doc/main.md @@ -8,6 +8,12 @@ `All posibilities in example.json5` +## How to import modules + +```json5 +[{ import: { path: "examples/assertions.onla", as: "assertions" } }] +``` + ## How to print ```json5 diff --git a/examples/assertions.onla b/examples/assertions.onla new file mode 100644 index 0000000..904ea20 --- /dev/null +++ b/examples/assertions.onla @@ -0,0 +1,11 @@ +//artegoser +//assertions module for onlang +[ + { + fn: { + name: "eq", + args: ["a", "b"], + body: [{ return: { comp: [{ var: "a" }, "==", { var: "b" }] } }], + }, + }, +] diff --git a/examples/calc.json5 b/examples/calc.onla similarity index 100% rename from examples/calc.json5 rename to examples/calc.onla diff --git a/examples/factorial.onla b/examples/factorial.json5 similarity index 61% rename from examples/factorial.onla rename to examples/factorial.json5 index 3213992..7ae7912 100644 --- a/examples/factorial.onla +++ b/examples/factorial.json5 @@ -64,42 +64,54 @@ }, }, - { - fn: { - name: "_eq", - args: ["a", "b"], - body: [{ return: { comp: [{ var: "a" }, "==", { var: "b" }] } }], - }, - }, + { import: { path: "examples/assertions.onla", as: "assertions" } }, - ["10! == 3 628 800: ", { _eq: [{ fact: [10] }, 3628800] }], - ["11! == 39 916 800: ", { _eq: [{ fact: [11] }, 39916800] }], + ["10! == 3 628 800: ", { "assertions.eq": [{ fact: [10] }, 3628800] }], + ["11! == 39 916 800: ", { "assertions.eq": [{ fact: [11] }, 39916800] }], - ["12! == 479 001 600: ", { _eq: [{ fact: [12] }, 479001600] }], - ["13! == 6 227 020 800: ", { _eq: [{ fact: [13] }, 6227020800] }], + ["12! == 479 001 600: ", { "assertions.eq": [{ fact: [12] }, 479001600] }], + ["13! == 6 227 020 800: ", { "assertions.eq": [{ fact: [13] }, 6227020800] }], - ["14! == 87 178 291 200: ", { _eq: [{ fact: [14] }, 87178291200] }], - ["15! == 1 307 674 368 000: ", { _eq: [{ fact: [15] }, 1307674368000] }], + [ + "14! == 87 178 291 200: ", + { "assertions.eq": [{ fact: [14] }, 87178291200] }, + ], + [ + "15! == 1 307 674 368 000: ", + { "assertions.eq": [{ fact: [15] }, 1307674368000] }, + ], - ["16! == 20 922 789 888 000: ", { _eq: [{ fact: [16] }, 20922789888000] }], - ["17! == 355 687 428 096 000: ", { _eq: [{ fact: [17] }, 355687428096000] }], + [ + "16! == 20 922 789 888 000: ", + { "assertions.eq": [{ fact: [16] }, 20922789888000] }, + ], + [ + "17! == 355 687 428 096 000: ", + { "assertions.eq": [{ fact: [17] }, 355687428096000] }, + ], [ "18! == 6 402 373 705 728 000: ", - { _eq: [{ fact: [18] }, 6402373705728000] }, + { "assertions.eq": [{ fact: [18] }, 6402373705728000] }, ], [ "19! == 121 645 100 408 832 000: ", - { _eq: [{ fact: [19] }, 121645100408832000] }, + { "assertions.eq": [{ fact: [19] }, 121645100408832000] }, ], [ "20! == 2 432 902 008 176 640 000: ", - { _eq: [{ fact: [20] }, 2432902008176640000] }, + { "assertions.eq": [{ fact: [20] }, 2432902008176640000] }, ], "", - ["(loop) 10! == 3 628 800: ", { _eq: [{ fact_loop: [10] }, 3628800] }], - ["(loop) 11! == 39 916 800: ", { _eq: [{ fact_loop: [11] }, 39916800] }], + [ + "(loop) 10! == 3 628 800: ", + { "assertions.eq": [{ fact_loop: [10] }, 3628800] }, + ], + [ + "(loop) 11! == 39 916 800: ", + { "assertions.eq": [{ fact_loop: [11] }, 39916800] }, + ], // [ // "21! == 51 090 942 171 709 440 000: ",