Symbol/keyword syntax (:name) #148

Closed
opened 2025-12-30 19:13:00 +00:00 by navicore · 1 comment
navicore commented 2025-12-30 19:13:00 +00:00 (Migrated from github.com)

Context

SON (Seq Object Notation) envisions syntax like:

[:ok "success" wrap]    # Creates Ok("success") variant
[:none wrap]            # Creates None variant

This requires a symbol or keyword type - a lightweight interned identifier.

Proposed Syntax

:foo        # Symbol literal, pushes Symbol("foo") onto stack
:some-name  # Kebab-case supported

Implementation

Parser changes

  • Recognize :identifier as a new token type
  • Parse into Statement::Symbol(String) or similar

Runtime changes

  • New Value::Symbol(SeqString) variant
  • Or intern symbols for O(1) comparison (like Ruby/Clojure)

Codegen changes

  • Emit symbol literals as constants

Design Questions

  1. Interning: Should symbols be interned (pointer equality) or just strings with : prefix?
  2. Namespace: Are :foo and "foo" related? Can you convert between them?
  3. Case: Allow :CamelCase or enforce :kebab-case?
  4. Use beyond SON: Symbols could enable keyword arguments, metadata, etc.

Prior Art

Language Syntax Interned?
Ruby :foo Yes
Clojure :foo Yes
Elixir :foo Yes (atoms)
Lisp 'foo Yes

Relation to SON

Symbols enable dynamic variant construction:

:some 42 wrap   # Instead of Make-Some 42

Without symbols, SON can't represent tagged data portably.


Part of the SON implementation roadmap.
Blocked by: nothing
Blocks: #148 (dynamic variant construction)

## Context SON (Seq Object Notation) envisions syntax like: ```seq [:ok "success" wrap] # Creates Ok("success") variant [:none wrap] # Creates None variant ``` This requires a **symbol** or **keyword** type - a lightweight interned identifier. ## Proposed Syntax ```seq :foo # Symbol literal, pushes Symbol("foo") onto stack :some-name # Kebab-case supported ``` ## Implementation ### Parser changes - Recognize `:identifier` as a new token type - Parse into `Statement::Symbol(String)` or similar ### Runtime changes - New `Value::Symbol(SeqString)` variant - Or intern symbols for O(1) comparison (like Ruby/Clojure) ### Codegen changes - Emit symbol literals as constants ## Design Questions 1. **Interning**: Should symbols be interned (pointer equality) or just strings with `:` prefix? 2. **Namespace**: Are `:foo` and `"foo"` related? Can you convert between them? 3. **Case**: Allow `:CamelCase` or enforce `:kebab-case`? 4. **Use beyond SON**: Symbols could enable keyword arguments, metadata, etc. ## Prior Art | Language | Syntax | Interned? | |----------|--------|-----------| | Ruby | `:foo` | Yes | | Clojure | `:foo` | Yes | | Elixir | `:foo` | Yes (atoms) | | Lisp | `'foo` | Yes | ## Relation to SON Symbols enable dynamic variant construction: ```seq :some 42 wrap # Instead of Make-Some 42 ``` Without symbols, SON can't represent tagged data portably. --- Part of the SON implementation roadmap. Blocked by: nothing Blocks: #148 (dynamic variant construction)
navicore commented 2026-01-03 04:38:21 +00:00 (Migrated from github.com)
https://github.com/navicore/patch-seq/pull/165
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
navicore/patch-seq#148
No description provided.