From b1cd35d0ca12cc6970b2375bb50d928576a7c25c Mon Sep 17 00:00:00 2001 From: Luxferre Date: Tue, 7 Jul 2026 10:54:04 +0300 Subject: [PATCH] v0.3.4: set and say --- README.md | 2 +- clyx-python/pyproject.toml | 2 +- clyx_manual.md | 12 +++++++++++- lib.clx | 4 +++- test.clx | 8 ++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 91ddfb3..57455dc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Clyx aims for maximum portability and can be implemented in any modern runtime e The core spec of Clyx is mostly stable but the standard library is still a work-in-progress. -The most recent Clyx version is **0.3.3**. The version is bumped every time the language core words (aka primitives), the standard library or the REPL get updated. The primitive set is expected to be indefinitely frozen once the version number reaches 1.0. +The most recent Clyx version is **0.3.4**. The version is bumped every time the language core words (aka primitives), the standard library or the REPL get updated. The primitive set is expected to be indefinitely frozen once the version number reaches 1.0. ## Language features diff --git a/clyx-python/pyproject.toml b/clyx-python/pyproject.toml index 6aa1683..4a7224b 100644 --- a/clyx-python/pyproject.toml +++ b/clyx-python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "clyx" -version = "0.3.3" +version = "0.3.4" description = "Clyx programming language interpreter" readme = "README.md" requires-python = ">=3.7" diff --git a/clyx_manual.md b/clyx_manual.md index 491939b..94a4f5f 100644 --- a/clyx_manual.md +++ b/clyx_manual.md @@ -2,7 +2,7 @@ Clyx is a concatenative, stack-oriented programming language designed for simplicity, minimalism, and metaprogramming capabilities. It uses postfix notation (aka Reverse Polish Notation, RPN), where operations are performed on a global stack. Clyx features homoiconicity: code is structured as Q-forms (special forms to represent data similar to Python or Tcl lists), which can be manipulated as data and executed dynamically. -This document describes the stack effects and behavior of the **50 primitive core words**, **3 bootstrapped core words**, and **49 standard library words** present in the reference implementation. +This document describes the stack effects and behavior of the **50 primitive core words**, **3 bootstrapped core words**, and **51 standard library words** present in the reference implementation. The Clyx runtime itself allows the programmer to redefine any already defined word, including the core ones and the ones from the standard library. Unlike e.g. Forth, where words are resolved at compile-time, Clyx words are resolved at runtime, so such redefinitions may affect all previously established behavior. That's why, as a rule, any **predefined** Clyx word, both in the language core and the standard library, must not exceed 6 characters. This is done to encourage programmers to define their own human-readable words (7+ characters long) without any risk of overwriting existing word definitions. @@ -446,6 +446,11 @@ These words are defined in the standard library file `lib.clx` and loaded dynami - **Stack Effect**: `( s -- )` or `( [q] -- )` - **Description**: Outputs a string or Q-form of character codes to standard output character-by-character. +#### `say` +- **Syntax**: `say "message"` +- **Stack Effect**: `( -- )` (parses string literal from the execution stream). +- **Description**: Parses a string literal from the execution stream, prints it to standard output, and outputs a newline. Defined as `[ next puts cr ]`. + #### `readln` (Read Line) - **Stack Effect**: `( -- s )` - **Description**: Reads a line of input from standard input and pushes it as a string. @@ -575,3 +580,8 @@ These words are defined in the standard library file `lib.clx` and loaded dynami - **Syntax**: `name is [actions]` - **Stack Effect**: `( name -- )` (parses actions Q-form from the execution stream). - **Description**: A synonym/helper for `::` used to define inline words. Defined as `[ next defw ]`. + +#### `set` +- **Syntax**: `set name [actions]` +- **Stack Effect**: `( -- )` (parses name and actions Q-form from the execution stream). +- **Description**: Defines a word dynamically by parsing its name and its actions Q-form from the execution stream. Defined as `[ next next defw ]`. diff --git a/lib.clx b/lib.clx index 1f78372..ce1f435 100644 --- a/lib.clx +++ b/lib.clx @@ -1,7 +1,8 @@ # Clyx standard library (in addition to [ :: readf src ]) # Created by Luxferre in 2026, released into the public domain -:: is [ next defw ] +:: is [ next defw ] # alias to :: for constant definitions +:: set [ next next defw ] :: source [ next src ] :: then [ ] :: _start [ next _main swap defw ] @@ -20,6 +21,7 @@ :: cr [ 10 emit ] :: space [ 32 emit ] :: puts [ uncons while [ emit uncons ] drop ] +:: say [ next puts cr ] :: sqrt [ 0.5 ^ ] :: tan [ dup sin swap cos / ] :: cotan [ dup cos swap sin / ] diff --git a/test.clx b/test.clx index 2d07f64..39be466 100644 --- a/test.clx +++ b/test.clx @@ -78,6 +78,7 @@ if [ " Testing dot: " puts 123 . # Test dot " Testing emit: " puts 65 emit cr # Test emit " Testing space: " puts 65 emit space 66 emit cr # Test space +" Testing say: " puts say "hello from say" " Testing readln: " puts readln puts cr # Test readln " Testing .s: " puts .s cr # Test .s @@ -232,6 +233,13 @@ my_str_word "abc" streq and :: "my_inline_string_word" [ 400 ] my_inline_string_word 400 = and if [ " is PASS" puts cr ] [ " is FAIL" puts cr ] # Test is +set my_set_word [ 500 ] +my_set_word 500 = +set my_set_num 600 +my_set_num 600 = and +set my_set_str "hello_set" +my_set_str "hello_set" streq and +if [ " set PASS" puts cr ] [ " set FAIL" puts cr ] # Test set " _start PASS" puts cr # Test _start (executed via entry point) # 11. Host Language Evaluation: hseval