1
0
Fork 0
forked from fun/fun

Some fixes in the spec.

This commit is contained in:
Johannes Findeisen 2025-09-11 23:31:44 +02:00
commit 70fc762c4d

View file

@ -31,12 +31,18 @@ Reserved words cannot be redefined:
### Comments ### Comments
- Single-line: - Single-line:
```fun
// This is a comment // This is a comment
```
- Multi-line: - Multi-line:
```fun
/* /*
This is This is a
a multi-line comment multi-line comment
*/ */
```
### Whitespace ### Whitespace
@ -50,7 +56,7 @@ Reserved words cannot be redefined:
- 64-bit signed integer. - 64-bit signed integer.
``` ```fun
number n = 42 number n = 42
``` ```
@ -58,7 +64,7 @@ number n = 42
- 64-bit IEEE floating point. - 64-bit IEEE floating point.
``` ```fun
float pi = 3.14159 float pi = 3.14159
``` ```
@ -68,10 +74,10 @@ float pi = 3.14159
- ' has higher priority, so " can appear unescaped inside '...'. - ' has higher priority, so " can appear unescaped inside '...'.
- To include ' inside '...', escape with \'. - To include ' inside '...', escape with \'.
``` ```fun
string s1 = "Hello" string s1 = "Hello"
string s2 = 'World' string s2 = 'World'
string s3 = "He said: 'Fun!'" string s3 = 'He said: "Fun!"'
``` ```
### Boolean ### Boolean
@ -79,7 +85,7 @@ string s3 = "He said: 'Fun!'"
- Canonical values: true, false. - Canonical values: true, false.
- 1 and 0 are accepted in conditionals. - 1 and 0 are accepted in conditionals.
``` ```fun
boolean flag = true boolean flag = true
``` ```
@ -87,7 +93,7 @@ boolean flag = true
- Raw byte value. - Raw byte value.
``` ```fun
byte b1 = 0x23 byte b1 = 0x23
byte b2 = "A" byte b2 = "A"
``` ```
@ -96,7 +102,7 @@ byte b2 = "A"
- Declared using [ ... ]. - Declared using [ ... ].
``` ```fun
array nums = [1, 2, 3] array nums = [1, 2, 3]
``` ```
@ -106,7 +112,7 @@ array nums = [1, 2, 3]
- Private variables: file-local, cannot be used outside the file. - Private variables: file-local, cannot be used outside the file.
- Redefining globals or shadowing names is forbidden. - Redefining globals or shadowing names is forbidden.
``` ```fun
global string message = "Hello" global string message = "Hello"
private number count = 42 private number count = 42
``` ```
@ -122,7 +128,7 @@ private number count = 42
### If/Else ### If/Else
``` ```fun
if(x != y) if(x != y)
print x print x
else if(a == b || h != i) else if(a == b || h != i)
@ -136,14 +142,14 @@ fi
### For Loops ### For Loops
``` ```fun
for i in range(1, 10) for i in range(1, 10)
print i print i
``` ```
### While Loops ### While Loops
``` ```fun
while x < 10 while x < 10
print x print x
x = x + 1 x = x + 1
@ -156,7 +162,7 @@ while x < 10
Provided by the runtime (cannot be redefined). Examples: Provided by the runtime (cannot be redefined). Examples:
print, range, system, exec. print, range, system, exec.
``` ```fun
print "Hello, Fun!" print "Hello, Fun!"
``` ```
@ -164,7 +170,7 @@ print "Hello, Fun!"
Must be declared with the f prefix. Must be declared with the f prefix.
``` ```fun
f add(a, b) f add(a, b)
return a + b return a + b
``` ```
@ -180,7 +186,7 @@ f add(a, b)
Looked up in /var/lib/fun/, supporting .so (native) and .fun (Fun code). Looked up in /var/lib/fun/, supporting .so (native) and .fun (Fun code).
``` ```fun
&#35;include crypt/md5 &#35;include crypt/md5
&#35;include date &#35;include date
&#35;include math &#35;include math
@ -190,7 +196,7 @@ Looked up in /var/lib/fun/, supporting .so (native) and .fun (Fun code).
From the current working directory: From the current working directory:
``` ```fun
&#35;include utils/file.fun &#35;include utils/file.fun
``` ```
@ -198,7 +204,7 @@ From the current working directory:
Full path: Full path:
``` ```fun
&#35;include /home/user/project/lib.fun &#35;include /home/user/project/lib.fun
``` ```
@ -208,7 +214,7 @@ Full path:
Executes a command, returns exit code. Executes a command, returns exit code.
``` ```fun
system("ls -l") system("ls -l")
``` ```
@ -216,7 +222,7 @@ system("ls -l")
Executes a command, returns stdout. Executes a command, returns stdout.
``` ```fun
string result = exec("date") string result = exec("date")
``` ```
@ -224,7 +230,7 @@ string result = exec("date")
Executes a command asynchronously, returns process ID. Executes a command asynchronously, returns process ID.
``` ```fun
number pid = spawn("sleep 10") number pid = spawn("sleep 10")
``` ```
@ -239,20 +245,20 @@ number pid = spawn("sleep 10")
### Hello World ### Hello World
``` ```fun
print "Hello, World!" print "Hello, World!"
``` ```
### Loop with Range ### Loop with Range
``` ```fun
for i in range(1, 5) for i in range(1, 5)
print i print i
``` ```
### User Function ### User Function
``` ```fun
f greet(name) f greet(name)
return "Hello " + name return "Hello " + name
@ -261,7 +267,7 @@ print greet("Fun")
### System Call ### System Call
``` ```fun
string now = exec("date") string now = exec("date")
print "Current time: " + now print "Current time: " + now
``` ```