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 03:20:46 +02:00
commit fe6be681f0

View file

@ -20,12 +20,14 @@ Fun is a scripting and systems programming language inspired by the best ideas f
Fun is **case-sensitive**. `Hacker` and `hacker` are different identifiers.
### Identifiers
- May contain `az`, `AZ`, `09`, and `_`.
- Must not start with a number.
- May contain `az`, `AZ`, `09`, and `_`.
- Must not start with a number.
### Keywords
Reserved words cannot be redefined:
`if`, `else`, `for`, `while`, `fi`, `fun`, `global`, `private`, `return`, `true`, `false`.
### Comments
@ -115,7 +117,7 @@ array nums = [1, 2, 3]
#### Supported typed arrays:
```
```fun
array<number> nums = [1,2,3]
array<string> names = ["Alice","Bob"]
```
@ -126,7 +128,7 @@ array<number> matrix = [[1,2],[3,4]]
- Arrays or dictionaries can hold different types, even if scalars are strictly typed (including objects later).
```
```fun
array mixed = [1, "two", true, [3,4]]
```
@ -144,7 +146,7 @@ number nothing = 23
- Dynamic variables
```
```fun
dynamic string x = 42
x = "Now I'm a string"
```
@ -207,7 +209,7 @@ fun add(a, b)
#### Functions support multiple return values:
```
```fun
fun divide(a, b)
if b == 0
return 0, "division by zero"
@ -261,14 +263,43 @@ print u.size()
## 9. Objects
The next step... ;)
## 10. Reflections
```fun
typeof(x) // Returns "number", "string", etc.
methods(obj) // Lists callable methods
typeof(x) // Returns "number", "string", etc.
methods(obj) // Lists callable methods
```
## 11. System Integration
## 11. Internal functions
### Call Function (Dynamic Function Helper)
- f can be any callable (another function, system call wrapper, etc.).
- arg can be any type (number, string, array, object).
- This function doesnt care about the types, it just calls f(arg).
- This function does not perform type checking on its arguments.
```fun
call(f, arg)
return f(arg)
```
#### Example
```fun
fun add_one(x)
return x + 1
fun shout(s)
return s + "!!!"
print call(add_one, 41) // 42
print call(shout, "Hi") // "Hi!!!"
```
## 12. System Integration
### Blocking
@ -330,7 +361,7 @@ Returns captured stdout (for processes started with nexec).
Terminates process.
## 12. Error Handling
## 13. Error Handling
- No implicit type coercion.
- Redefinition of globals is a compile-time error.
@ -338,7 +369,7 @@ Terminates process.
- Compile-time: undefined variables, illegal redefinitions, type mismatch.
- Runtime: failed system calls, division by zero, etc.
## 13. Examples
## 14. Examples
### Hello World
@ -369,7 +400,7 @@ string now = exec("date")
print "Current time: " + now
```
## 14. License
## 15. License
This document and the Fun language reference are licensed under the Apache License 2.0