-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from slntRohit/recoursion-example
Added recursion example
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 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,54 @@ | ||
# MojiScript Recursion | ||
|
||
MojiScript Recursion example. | ||
|
||
## Install | ||
|
||
```bash | ||
# clone repository | ||
git clone https://github.com/joelnet/MojiScript.git | ||
|
||
# enter directory | ||
cd MojiScript/examples/recursion | ||
|
||
# install dependencies | ||
npm ci | ||
``` | ||
|
||
## Run | ||
|
||
```bash | ||
npm start | ||
``` | ||
|
||
You should see the output | ||
|
||
``` | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
... | ||
``` | ||
Will keep printing numbers every 1 second. | ||
|
||
## Code | ||
|
||
```javascript | ||
import log from 'mojiscript/console/log' | ||
import pipe from 'mojiscript/core/pipe' | ||
import run from 'mojiscript/core/run' | ||
import wait from 'mojiscript/threading/sleep' | ||
|
||
const state = 1 | ||
|
||
const main = pipe ([ | ||
log, | ||
wait (1000), | ||
x => main (x + 1) | ||
]) | ||
|
||
run ({ state, main }) | ||
``` |
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 @@ | ||
import log from 'mojiscript/console/log' | ||
import pipe from 'mojiscript/core/pipe' | ||
import run from 'mojiscript/core/run' | ||
import wait from 'mojiscript/threading/sleep' | ||
|
||
const state = 1 | ||
|
||
const main = pipe ([ | ||
log, | ||
wait (1000), | ||
x => main (x + 1) | ||
]) | ||
|
||
run ({ state, main }) |
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,13 @@ | ||
{ | ||
"name": "recursion", | ||
"version": "1.0.0", | ||
"author": "Joel Thoms", | ||
"license": "MIT", | ||
"main": "index.mjs", | ||
"scripts": { | ||
"start": "node --experimental-modules --no-warnings index.mjs" | ||
}, | ||
"dependencies": { | ||
"mojiscript": "file:../.." | ||
} | ||
} |