-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.noug
240 lines (198 loc) · 6.3 KB
/
example.noug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# Nougaro : a python-interpreted high-level programming language
# Copyright (C) 2021-2024 Jean Dubois (https://github.com/jd-develop) <[email protected]>
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# This file was made in Nougaro 1.0.0 version.
import math
import statistics
import time
# This is a comment
/*
this is a multi-line comment
awesome
*/
# Basics :
# Print
print("Hello, world!") # it prints the text then puts a back line
import hello # this lib just prints "Hello, world!"
print() # this prints a blank line with a back line at the end
# Mathematical operators
print(1+1)
print(3-4)
print(2*3)
print(6/2)
print(3^2) # this is the power
print(math.abs(-5)) # the absolute value
print(1e10) # 1*10^10
print()
# Variables
var some_text = "Hello, world!" # no need to put the variable type
var a = var b = 3 # you can use variable definitions in other expressions
print(some_text); print(a * b) # the ';' is like a back line
var a ++
var b --
print(str(a)+str(b)) # 42
print(reverse(str(a)+str(b))) # 24
# the following two lines are an example in the doc (Built-in variables)
print("You use nougaro version " + __noug_version__ + ", interpreted with Python " + __python_version__)
print("You use " + __os_name__ + " " + __os_release__ + " " + __os_version__)
print(None) # like Python's 'None'
print(var b === 3) # like `var b = (b==3)`
print(var b <== 3) # like `var b = (b<=3)`
print(var b <<= 3) # like `var b = (b<3)`
print(var b >== 3) # like `var b = (b>=3)`
print(var b >>= 3) # like `var b = (b>3)`
print()
# Strings
# examples of using the backslash
print("this is a string quoted by \".")
print("You can put\nbacklines and\n\ttabs.")
print("You can add \\ backslashes and \" \' quotes")
print("\u0D9E and \xD9 are unicode chars U+D9E and U+D9")
print("\N{sinhala letter kantaja naasikyaya} is sus") # sus
print(«Wait, French guillemets are valid string delimiters?»)
print("You can add up and multiply strings: " + 3*some_text)
print()
# assert
assert True
# assert False # it makes the program crash. Uncomment the line to see what happens :)
# assert False, "you can also put an error message" # Uncomment this line to see what happens ;)
# Input and tests
var name = input("What's your name? ")
if name == "Jean Dubois" then
print("You are the creator of this language! Amazing!")
elif name != "mrlulu51" then
print("You aren't MrLulu...")
else
print("You are MrLulu!")
end
print()
print(1<2)
print(1>2)
print(12>=12)
print(13<=12)
print()
print(True and False)
print(True or False)
print(True xor False) # exclusive or
print(not True)
print()
# example functions
example('ppap') # all the examples are in the 'examples' folder
print()
# Functions
def fib(n)
# calculates all the numbers of the fibonacci list less than n
var a = 0; var b = 1
var return_list = []
if is_int(n) or is_float(n) then
while a < n then
print(a)
var return_list += a
var a, b = b, a+b
end
return return_list
else
print("first argument must be an int!")
return None
end
end
print(fib(input_int("Enter number: ")))
print()
var a = def()->print("Hello, world!") # you may not give a name to your function
a()
print()
# builtin functions and lists
var a = print_ret("this string is printed and assigned to a")
print("type(a) is " + type(a)) # str
print("is_str(a) is " + str(is_str(a))) # True
print("is_list(a) is " + str(is_list(a))) # False
print("is_func(is_func) is " + str(is_func(is_func))) # True
print("is_list(a) is " + str(is_list(a))) # False
print()
print(str(123)) # "123"
print(int("123")) # 123
print(float("123.456")) # 123.456
print(list("abc")) # ["a", "b", "c"]
print()
var list_ = [1, 2, 3, "4", '5', '6']
print(append(list_, 7)) # append elements to a list.
print(var list_ += 7) # another way to do it
print()
print(pop(list_, -1)) # pop elements to a list
print(list_ - -1) # another way to do it
print()
print(extend(list_, [8, 9, 10])) # add all the elements of a list to another list
print(list_ * [8, 9, 10]) # another way to do it
print()
print(get(list_, -3)) # get the -3rd element of a list
print(list_ / -3) # another way to do it
print(list_(-3)) # the BEST way to do it
print(get(*[list_, -3])) # the WORST way to do it. *[list_, -3] returns list_, -3 in this case.
print()
print("max of the list is " + str(max(list_, True)))
print("min of the list is " + str(min(list_, True)))
print("scope of the list is " + str(statistics.scope([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))) # 10-1 = 9 :)
print()
void() # Does ABSOLUTELY nothing... (in fact, returns None...)
# misc builtin functions
print(ord('😀')) # prints the ord for this character
print(chr(128512)) # prints the character for this ord
# math functions
print(math.sqrt(math.pi) == math.sqrt_pi) # True
print(math.root(27, 3)) # returns x with x^3 = 27, so 3
print(math.degrees(12)) # radians -> degrees
print(math.radians(math.degrees(12))) # 12 :)
print(math.log(3)) # log_e(3)
print(math.log(3, 4)) # log_4(3)
print(math.log2(3)) # log_2(3)
# math.sin, math.cos, math.tan, math.asin, math.acos, math.atan...
print(math.e) # euler's number
print()
# loops
for i = 1 to 10 then
print(i)
end
# it prints 1, 2, 3, 4, 5, 6, 7, 8, 9
print()
for i = 1 to 10 step 2 then
print(i)
end
# it prints 1, 3, 5, 7, 9
print()
for i in list_ then
print(i)
end
# it prints all the elements of list_
print()
var _ = 0
do
print(_)
if _ == 9 then; var _ += 2; continue; end
var _ += 1
then loop while _ != 20
print()
# variable deletion
var a = 1
print(a)
del a
# print(a) # uncomment this line to see what happens ;)
print()
# write into a file
var file = 'example_file'
write "Use '!>>' to overwrite :)" !>> file
write "\nHello world!" >> file # use \n to make a new line.
write "Wow, that is at line 6" >> file 6
print("Write into a file does not prints anything - except in shell mode.")
print("Or you can do `print(write 'str' >> 'file')` ^^")
print()
# read files
print(read file) # it reads the file as a string. When it's printed, it prints also the back lines.
print()
# time sleep
print("wait a second...")
time.sleep(1) # literally a second
print("thank you :)") # you're welcome ^^
print()
# wow... i finished commenting this file.