enlightware / enlightware/ferlium

Add module-level constants

Open
#138 0 comments 0 reactions 0 assignees View on GitHub
hir parsing
Dominant language
Rust
Stars
14
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Ferlium now supports trait associated constants for literal values, but there is no way to define ordinary module-level constants. This would be useful for library/domain constants that are not naturally tied to a trait.

## Proposed syntax

```ferlium
const DEFAULT_CAPACITY: int = 16;
pub const PI: float = 3.141592653589793;
```

Type annotation may be required in the first version, or optional if inference is straightforward.

## Initial scope
- Module items only.
- Public/private visibility, like functions and types.
- Immutable values.
- Initializer restricted to literal values, matching associated consts.
- No general compile-time expression evaluation.
- No local constants.
- No generic constants.
- No dependency graph or initialization order beyond literal storage.

## Future extension

A later feature could support const expressions such as:
```
pub const TAU: float = 2.0 * PI;
```

That should be designed separately, because it requires compile-time evaluation rules, cycle detection, purity/effect restrictions, trait/operator handling, and diagnostics.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.