1
0
Fork 0
forked from fun/fun

Some update in the v0.2 spec.

This commit is contained in:
Johannes Findeisen 2025-09-12 04:40:44 +02:00
commit 96c68b0d27

View file

@ -124,12 +124,14 @@ array<string> names = ["Alice","Bob"]
#### Multidimensional arrays: #### Multidimensional arrays:
```
array<number> matrix = [[1,2],[3,4]] array<number> matrix = [[1,2],[3,4]]
```
- Arrays or dictionaries can hold different types, even if scalars are strictly typed (including objects later). - Arrays or dictionaries can hold different types, even if scalars are strictly typed (including objects later).
```fun ```fun
array mixed = [1, "two", true, [3,4]] array mixed = [1, "two", true, [3,4], matrix]
``` ```
## 4. Variables and Scope ## 4. Variables and Scope
@ -164,26 +166,26 @@ x = "Now I'm a string"
```fun ```fun
if(x != y) if(x != y)
print x print(x)
else if(a == b || h != i) else if(a == b || h != i)
print a + b print(a + b)
else else
if(k < 1 && l > 1) if(k < 1 && l > 1)
print "Buh!" print("Buh!")
``` ```
### For Loops ### For Loops
```fun ```fun
for i in range(1, 10) for i in range(1, 10)
print i print(i)
``` ```
### While Loops ### While Loops
```fun ```fun
while x < 10 while x < 10
print x print(x)
x = x + 1 x = x + 1
``` ```
@ -195,7 +197,9 @@ Provided by the runtime (cannot be redefined). Examples:
print, range, system, exec. print, range, system, exec.
```fun ```fun
print "Hello, Fun!" print(a)
number lemmy = range(a, b)
string result = exec("date")
``` ```
### User-Defined Functions ### User-Defined Functions
@ -253,12 +257,12 @@ Full path:
```fun ```fun
#include math as m #include math as m
print m.sqrt(16) print(m.sqrt(16))
``` ```
```fun ```fun
#include /home/user/project/universe.fun as u #include /home/user/project/universe.fun as u
print u.size() print(u.size())
``` ```
## 9. Objects ## 9. Objects
@ -374,14 +378,14 @@ Terminates process.
### Hello World ### Hello World
```fun ```fun
print "Hello, World!" print("Hello, World!")
``` ```
### Loop with Range ### Loop with Range
```fun ```fun
for i in range(1, 5) for i in range(1, 5)
print i print(i)
``` ```
### User Function ### User Function
@ -390,14 +394,14 @@ for i in range(1, 5)
fun greet(name) fun greet(name)
return "Hello " + name return "Hello " + name
print greet("Fun") print(greet("Fun"))
``` ```
### System Call ### System Call
```fun ```fun
string now = exec("date") string now = exec("date")
print "Current time: " + now print("Current time: " + now)
``` ```
## 15. License ## 15. License