Skip to content

Commit 1ddcf8a

Browse files
committed
V1.13.5: Added Loops and Functions to docs and updated README
1 parent 389dd82 commit 1ddcf8a

File tree

9 files changed

+173
-6
lines changed

9 files changed

+173
-6
lines changed

NumberScript/interpreter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def __init__(self):
168168

169169
def interpret(self, code: str, variables_dict: dict = None, function_dict: dict = None, debug_mode: bool = False,library: bool = False) -> str:
170170
"""Interprets the code"""
171+
code = code.replace("\n", " ").replace("\t", "").replace("\r\n", " ").replace("\r", " ")
171172
code = code.split(" ")
172173
variables_dict = {} if variables_dict is None else variables_dict
173174
function_dict = {} if function_dict is None else function_dict

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<img src="docs\images\Logo-256.png" alt="Logo of NumberScript"/>
1+
<img src="https://raw.githubusercontent.com/Sas2k/NumberScript/main/docs/images/Logo-256.png" alt="Logo of NumberScript"/>
22

33
# NumberScript
44

55
[![Downloads-Month](https://pepy.tech/badge/numberscript/month)](https://pepy.tech/project/numberscript)
66
[![Downloads-Total](https://pepy.tech/badge/numberscript)](https://pepy.tech/project/numberscript)
7-
![Discord](https://img.shields.io/discord/1005410273609400402?label=Discord&style=social)
7+
[![Discord](https://img.shields.io/discord/1005410273609400402?label=Discord&style=for-the-badge&color=purple)]((https://discord.gg/wRXR72zJ6W))
88

99
[NumberScript Discord-Invite](https://discord.gg/wRXR72zJ6W)
1010

docs/Tutorial/Functions.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Functions
2+
3+
## What are functions?
4+
5+
Functions are like a mini-program, that you can call in your main program.
6+
7+
so like in some text editors, let's take word for example. there is a button in the top corner that makes the text bold. this is a function. like this there a lot of functions in Word.
8+
9+
## Defining Functions in NumberScript
10+
11+
now to define functions we need the `7` command.
12+
13+
so the basic syntax is this
14+
15+
```
16+
7function-name$function-arguments$function-body
17+
```
18+
19+
now the function-name is the name of the function. the function-arguments are the arguments that the function takes. and the function-body is the code that the function runs.
20+
21+
so here is a function that adds two numbers and prints them.
22+
23+
```
24+
7add$number1,number2$2^number1+number2
25+
```
26+
27+
now how do I call this function well just do this
28+
29+
```
30+
add$5,5
31+
```
32+
33+
and it will print 10.
34+
35+
so how can I have more then one command in the function body?
36+
well simply you can add the function code split in between the commands.
37+
the function split is the `$`.
38+
39+
so here is our function that prints the sum of two numbers. but this function is different.
40+
I changed it to display the double of the sum.
41+
42+
```
43+
7add$number1,number2$3sum:^number1+number2$2^sum*2
44+
```
45+
46+
so if we call this with `add$5,5` it will print 20.
47+
48+
and that's about it for functions.
49+
50+
## Exercises
51+
52+
Now that you got the basics of the functions. try these exercises.
53+
54+
### 1) fisherman's problem
55+
56+
now A fisherman has a brand new programmable fishing rod. now the rod is programmed with NumberScript.
57+
so now the fisherman asks you to program the rod. since he is a fisherman he doesn't know how to program.
58+
59+
so he asks you to make a program to take input. the options are `1` for `small fish` and `2` for `big fish`.
60+
61+
now when the fisherman sees a small fish he input the option (1 for small fish, 2 for big fish) and the rod will ask him to input the weight of the fish. then the rod will display how hard to pull the line.
62+
63+
now the calculation on how to pull the small fish is `weight/2 + 1`.
64+
65+
for big fish it's `weight * 2 / 4 + 1`.
66+
67+
so here is an example input and output.
68+
69+
```
70+
Enter-Option>1
71+
Enter-Weight>4
72+
Pull-the-fish-with,
73+
3
74+
grams
75+
```
76+
77+
```
78+
Enter-Option>2
79+
Enter-Weight>10
80+
Pull-the-fish-with,
81+
6
82+
grams
83+
```

docs/Tutorial/If-Else.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Here is an example of a program using If-Else,
3838

3939
Now that you got the basics of the If-Else Sentences. try these exercises.
4040

41-
### Even or Odd
41+
### 1) Even or Odd
4242

4343
In this exercise you must create a program where it will take an input and checks whether it is Even or Odd.
4444

docs/Tutorial/loops.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Loops
2+
3+
## What are loops?
4+
5+
now what loops do is repeat an instruction a number of time.
6+
7+
now imagine you have an instruction you have to do a 100 times.
8+
you can write it 100 times. but that's not efficient. and it's not fun.
9+
so instead you can use loops.
10+
11+
now in NumberScript there is only 1 type of loop. which is the for loop.
12+
13+
## Loops in NumberScript
14+
15+
now the syntax for loops is this
16+
17+
```
18+
6loop-variable\repeat-count\loop-code
19+
```
20+
21+
now the loop-variable is the variable that will be used to count the number of times the loop has been repeated.
22+
the repeat count is the times it will repeat. the loop code is the instruction that will be repeated.
23+
24+
now let's see an example
25+
26+
```
27+
6i\10\2i
28+
```
29+
30+
here this will print the numbers from 0 to 9.
31+
32+
> Loops start from 0 so the first number will be 0. and the end number will be one less then the placed amount.
33+
34+
now let's see another example
35+
36+
```
37+
6i\10\?i=5:2i|2i-is-5
38+
```
39+
40+
here this will print the numbers from 0 to 9. but if the number is 5 it will print `i-is-5` instead.
41+
42+
## Exercises
43+
44+
### 1) Odd or Even
45+
46+
now, we made a program to see if the number is even or odd in the [If-Else](NumberScript/Tutorial/if-else/#even-or-odd) section. but now your task is to make it so the program loops through the numbers from 0 to 99 and prints if the number is even or odd.
47+
48+
here is the output.
49+
50+
```
51+
0
52+
is even
53+
1
54+
is odd
55+
2
56+
is even
57+
3
58+
is odd
59+
...
60+
```
61+
62+
### 2) FizzBuzz
63+
64+
Now your task is to create a FizzBuzz program where it loops over the numbers from 1 to 100 and prints `Fizz` if the number is divisible by 3, `Buzz` if the number is divisible by 5, `FizzBuzz` if the number is divisible by 3 and 5, and the number if it's not divisible by 3 or 5.
65+
66+
here is the output.
67+
68+
```
69+
1
70+
2
71+
Fizz
72+
4
73+
Buzz
74+
Fizz
75+
7
76+
8
77+
...
78+
```

docs/about.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# About
22

3-
Created by [Sas2k](https://github.com/Sas2k)
3+
Created by [Sas2k](https://github.com/Sas2k) on a rainy day.
4+
5+
> Also some of you might have noticed that this language works with only string parsing.
6+
> No Lexers, Parsers or anything of that sort. :smile:

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Which you can easily download from `pypi` (aka. `pip`)
1010
Now the interpreter is downloaded.
1111
we need to set it up Now run the command below.
1212

13-
`nspm setup`
13+
`nspm setup` _also you only need to run this command once_
1414

1515
> nspm: NumberScript Package Manager
1616

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ nav:
77
- Basics: Tutorial/basics.md
88
- Variables: Tutorial/Variables.md
99
- If-Else: Tutorial/If-Else.md
10+
- Loops: Tutorial/loops.md
11+
- Functions: Tutorial/Functions.md
1012
- About: about.md
1113
theme:
1214
name: material

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="NumberScript",
8-
version="1.13.2",
8+
version="1.13.5",
99
description="possibly the world's most simplest and restricted language.",
1010
author="Sasen Perera",
1111
long_description=longest_description,

0 commit comments

Comments
 (0)