1
0
Fork 0
forked from fun/fun

Added spec version 0.4 and added a changelog that will cover all changes more detailed in the future. No code changes. (0.40.5)

This commit is contained in:
Johannes Findeisen 2026-04-10 21:53:50 +02:00
commit 5c57391e5d
3 changed files with 250 additions and 1 deletions

33
CHANGELOG.md Normal file
View file

@ -0,0 +1,33 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (during 0.x.y development phase).
## [0.40.5] - 2026-04-10
### Removed
- All `libsql` support.
- All `tcltk` support.
## [0.40.0] - 2026-03-25
### Added
- Nested functions support in the Fun parser.
- Higher-order function patterns enabled by nesting.
## [0.39.15] - 2026-03-10
### Added
- Initial GitHub Actions CI workflow.
- Automated execution of examples in CI.
### Changed
- Refactored examples directory structure.
### Fixed
- Line number reporting in error messages.
## [0.30.0] - 2025-11-15
### Added
- `libcurl` (cURL) support for networking.
- `CRC32` and `CRC32C` classes in stdlib.
---
*Note: Dates for older versions are approximate based on repository history.*

View file

@ -80,6 +80,8 @@ Fun may not change the world — but it will make programming a little more fun.
- if/else if/else
- try/catch/finally
And much more...! Look at the specs in [spec/](./spec/) for more detailed information.
### Lib (./lib/)
See [./lib/](https://git.xw3.org/fun/fun/src/branch/main/lib) for what the standard library provides.
@ -119,7 +121,8 @@ Looking for docs? Start here:
Additional references:
- Specification: [spec/v0.3.md](./spec/v0.3.md) (work in progress)
- Specification: [spec/v0.4.md](./spec/v0.4.md) (work in progress)
- Changelog: [CHANGELOG.md](./CHANGELOG.md)
- Examples demonstrating most features: [examples/](./examples/)
- Internals and VM opcodes live in [src/](./src/) (see [src/vm/](./src/vm) for opcode implementations)

213
spec/v0.4.md Normal file
View file

@ -0,0 +1,213 @@
# Fun Language Specification v0.4
This document describes Fun (Fun Uses Nothing) as of version 0.4. It supersedes v0.3 by formalizing nested functions, refining modules, and updating system integrations.
---
## 1) Overview and Goals
- Readable: strict, indentation-based syntax (2 spaces), no semicolons.
- Safe: explicit types, no implicit numeric coercions, bounds-checked operations, controlled side effects.
- Hackable: pragmatic stdlib, process I/O, sockets, threads, and now nested functions for better encapsulation.
Whats new in v0.4 (high level):
- Nested Functions: functions can now be declared inside other functions.
- Enhanced CI integration for standard library and examples.
- Refinement of optional extensions (removal of obsolete/unmaintained integrations like libsql, tcltk, notcurses).
---
## 2) Lexical Structure
- Case-sensitive identifiers: letters, digits, `_`; must not start with a digit.
- Comments:
- Single-line: `// comment`
- Multi-line: `/* ... */`
- Whitespace and newlines:
- Indentation is exactly 2 spaces; tabs are forbidden.
- Newline terminates statements; no semicolons.
Reserved keywords (cannot be redefined):
- `if`, `else`, `for`, `while`, `break`, `continue`
- `fun`, `return`
- `class`, `extends`
- `global`, `private`
- `true`, `false`
- `try`, `catch`, `finally`
---
## 3) Types
Scalar types:
- `number`: 64-bit signed integer.
- `float`: 64-bit IEEE-754 floating point.
- `string`
- `boolean`: `true` / `false`.
- `byte`: 8-bit value.
Fixed-width integers (signed/unsigned):
- `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`
Aggregate types:
- `array` and typed arrays: `array<T>`
- `map<K, V>` (dictionary / associative array)
- `object` (instances of `class`)
---
## 4) Variables and Scope
- `global` variables are visible program-wide.
- `private` variables are file-local (module private).
- Local variables are scoped to the function or block.
- Rebinding a global or shadowing a name is a compile-time error.
---
## 5) Operators and Builtins
Arithmetic: `+`, `-`, `*`, `/`, `%`
Comparison: `==`, `!=`, `>`, `<`, `>=`, `<=`
Boolean: `&&`, `||`, `!`
Assignment: `=`
Bitwise helpers (functions):
- `band(a, b)`, `bor(a, b)`, `bxor(a, b)`, `bnot(a)`, `shl(a, n)`
---
## 6) Control Flow
If/Else:
```fun
if (x != y)
print(x)
else if (a == b)
print(a + b)
else
print("Else")
```
While:
```fun
while i < 10
i = i + 1
if i == 5
continue
if i > 8
break
```
For:
- Range: `for i in range(0, 5)`
- Array: `for x in arr`
- Map keys: `for k in keys(m)`
Try/Catch/Finally:
```fun
try
risky()
catch err
print(err)
finally
cleanup()
```
---
## 7) Functions and Nested Functions
User-defined functions:
```fun
fun add(a, b)
return a + b
```
Nested Functions (New in v0.4):
Functions can be defined within other functions to encapsulate logic.
```fun
fun outer(x)
fun inner(y)
return x + y
return inner(10)
```
---
## 8) Classes and Objects
Definition:
```fun
class Point(x, y)
x = 0
y = 0
fun _construct(this, x, y)
this.x = x
this.y = y
fun move(this, dx, dy)
this.x = this.x + dx
this.y = this.y + dy
```
Inheritance:
```fun
class Child(x, y) extends Point
fun describe(this)
return "Child at " + to_string(this.x)
```
---
## 9) Modules and Includes
- System: `#include <utils/math.fun>`
- Local: `#include "./local.fun"`
- Namespaced: `#include <math.fun> as m`
---
## 10) Collections
- Arrays: `[1, 2, 3]`, `push(arr, val)`, `join(arr, sep)`
- Maps: `{ "key": "value" }`, `has(m, key)`, `keys(m)`
---
## 11) Concurrency (Threads)
- `thread_spawn(fn, args)`
- `thread_join(id)`
- `sleep(ms)`
---
## 12) System and Networking
- Processes: `exec(cmd)`, `system(cmd)`, `nexec(cmd)`, `wait(pid)`
- Environment: `env(NAME)`, `argv()`
- Networking: `tcp_connect(host, port)`, `sock_send(fd, data)`, `sock_recv(fd, nbytes)`
---
## 13) Error Handling and Type Safety
- No implicit type coercion.
- Overflow on fixed-width types is an error.
- Shadowing internal functions is forbidden.
---
## 14) Changelog (from v0.3 to v0.4)
- Added: Nested functions support (functions within functions).
- Added: Enhanced CI workflow for testing examples and stdlib.
- Removed: `libsql`, `tcltk`, `notcurses`, and `libressl` optional extensions to streamline the core.
- Fixed: Various bugs in parser and line number reporting.
---
## 15) Versioning
- v0.4 continues the 0.x.y semantic development phase.
- Backward compatibility with v0.3 is maintained except for removed optional extensions.