diff --git a/clyx-go/clyx.go b/clyx-go/clyx.go index 8577eea..1f50831 100644 --- a/clyx-go/clyx.go +++ b/clyx-go/clyx.go @@ -468,7 +468,7 @@ func NewClyx(libfname string, libCode string) *Clyx { c.words["loop"] = func() { body, cond := c.pop().([]any), c.pop().([]any); for { c.execQForm(cond); if !isTruthy(c.pop()) { break }; c.execQForm(body) } } c.words["hsargs"] = func() { c.stack = append(c.stack, toAnySlice(os.Args)) } c.words["hsexit"] = func() { os.Exit(int(toInt(c.pop()))) } - c.words["l2s"] = func() { + c.words["q2s"] = func() { l := c.pop().([]any) var sb strings.Builder for _, val := range l { @@ -512,7 +512,7 @@ func NewClyx(libfname string, libCode string) *Clyx { regMath("exp", math.Exp) regMath("log", math.Log) - c.Run(`"::" [ next defw ] defw :: readf [ "r" fopen dup read swap close ] :: src [ readf l2s i ]`) + c.Run(`"::" [ next defw ] defw :: readf [ "r" fopen dup read swap close ] :: src [ readf q2s i ]`) if libfname == "" { c.Run(libCode) diff --git a/clyx-python/clyx/clyx.py b/clyx-python/clyx/clyx.py index 1af1b7f..5d5c9dd 100755 --- a/clyx-python/clyx/clyx.py +++ b/clyx-python/clyx/clyx.py @@ -69,13 +69,13 @@ class Clyx: 'loop': lambda: (lambda body, cond: self._exec_loop(cond, body))(self._stack.pop(), self._stack.pop()), 'hsargs': lambda: self._stack.append(list(sys.argv)), 'hsexit': lambda: sys.exit(int(self._stack.pop())), - 'l2s': lambda: self._stack.append("".join(chr(int(x)) for x in self._stack.pop())), + 'q2s': lambda: self._stack.append("".join(chr(int(x)) for x in self._stack.pop())), 'hseval': lambda: self._stack.append(eval(self._stack.pop())), 'chr': lambda: self._stack.append(chr(int(self._stack.pop()))), 'sin': lambda: self._stack.append(math.sin(float(self._stack.pop()))), 'cos': lambda: self._stack.append(math.cos(float(self._stack.pop()))), 'atan': lambda: self._stack.append(math.atan(float(self._stack.pop()))), 'exp': lambda: self._stack.append(math.exp(float(self._stack.pop()))), 'log': lambda: self._stack.append(math.log(float(self._stack.pop()))) } - self.run('"::" [ next defw ] defw :: readf [ "r" fopen dup read swap close ] :: src [ readf l2s i ]') + self.run('"::" [ next defw ] defw :: readf [ "r" fopen dup read swap close ] :: src [ readf q2s i ]') self.run(f'"{libpath}" src' if libfname is None else (libfname + ' src')) def _cmd_write(self): diff --git a/clyx_manual.md b/clyx_manual.md index 258d722..b77e0c9 100644 --- a/clyx_manual.md +++ b/clyx_manual.md @@ -117,13 +117,13 @@ Any line fragment starting with `#` to the end of the physical source line is re - **Stack Effect**: `( s -- code )` - **Description**: Converts the first character of the string `s` to its integer ASCII character code. -### `s2l` (String to Q-form) +### `s2q` (String to Q-form) - **Stack Effect**: `( val -- [q] )` - **Description**: Converts the value `val` (if it is a string) to a Q-form of its byte values/integers. If `val` is already a Q-form, it does nothing. -### `l2s` (Q-form to String) +### `q2s` (Q-form to String) - **Stack Effect**: `( [q] -- s )` -- **Description**: Converts the Q-form of integers `[q]` (character/byte codes) into its string representation `s`. Reverts the operation of `s2l`. +- **Description**: Converts the Q-form of integers `[q]` (character/byte codes) into its string representation `s`. Reverts the operation of `s2q`. --- @@ -337,7 +337,7 @@ These words are defined in Clyx itself during the interpreter's bootstrap phase: ### `src` (Source) - **Stack Effect**: `( filename -- )` -- **Description**: Reads the file `filename` using `readf`, converts the Q-form of bytes to a string using `l2s`, and runs the resulting Clyx code in real-time using `i`. +- **Description**: Reads the file `filename` using `readf`, converts the Q-form of bytes to a string using `q2s`, and runs the resulting Clyx code in real-time using `i`. --- diff --git a/lib.clx b/lib.clx index 2bfc6af..e95c779 100644 --- a/lib.clx +++ b/lib.clx @@ -22,7 +22,7 @@ :: neg [ 0 swap - ] :: 1/ [ 1 swap / ] :: shr [ neg shl ] -:: readln [ 0 "r" fopen read l2s ] +:: readln [ 0 "r" fopen read q2s ] :: writef [ "w" fopen dup rot write swap close ] :: nlstn [ "0.0.0.0" swap nopen ] :: = [ - 0= ] @@ -35,15 +35,15 @@ :: isstr [ type 1 = ] :: isq [ type 2 = ] :: vlen [ type 2 = if [ qlen ] [ slen ] ] -:: s2l [ type 2 = if [] [ dup slen 0 = if [ drop [] ] [ uncons drop swap cons ] ] ] -:: asc [ s2l 0 qget ] +:: s2q [ type 2 = if [] [ dup slen 0 = if [ drop [] ] [ uncons drop swap cons ] ] ] +:: asc [ s2q 0 qget ] :: lcat [ [ rev ] dip swap uncons while [ [ swap ] dip swap cons swap uncons ] drop ] :: streq [ dup vlen [ swap dup vlen ] dip = if [ 1 while [ uncons if [ [ swap uncons drop ] dip = if [ dup qlen 0 = if [ drop drop 1 0 ] [ swap 1 ] ] [ drop drop 0 0 ] ] [ drop drop 1 0 ] ] ] [ drop drop 0 ] ] -:: lower [ "" swap uncons while [ dup 65 >= [ dup 90 <= ] dip and if [ 32 + ] [] [ swap ] dip chr s+ swap uncons ] drop l2s ] -:: upper [ "" swap uncons while [ dup 97 >= [ dup 122 <= ] dip and if [ 32 - ] [] [ swap ] dip chr s+ swap uncons ] drop l2s ] +:: lower [ "" swap uncons while [ dup 65 >= [ dup 90 <= ] dip and if [ 32 + ] [] [ swap ] dip chr s+ swap uncons ] drop q2s ] +:: upper [ "" swap uncons while [ dup 97 >= [ dup 122 <= ] dip and if [ 32 - ] [] [ swap ] dip chr s+ swap uncons ] drop q2s ] :: bitnot [ dup nand ] :: bitand [ nand bitnot ] :: bitor [ bitnot swap bitnot nand ] :: bitxor [ over over bitnot bitand [ swap bitnot bitand ] dip bitor ] :: rev [ [] swap uncons while [ [ swap ] dip swap cons swap uncons ] drop ] -:: s+ [ s2l [ s2l ] dip lcat ] +:: s+ [ s2q [ s2q ] dip lcat ] diff --git a/test.clx b/test.clx index 7637897..e4233d5 100644 --- a/test.clx +++ b/test.clx @@ -159,16 +159,16 @@ if [ "AbC" lower "abc" streq "aBc" upper "ABC" streq and "abc" "def" s+ "abcdef" streq and -"abc" s2l [ 97 98 99 ] streq and -"abc" s2l l2s "abc" streq and -[ 1 2 3 ] s2l [ 1 2 3 ] streq and -"" s2l [ ] streq and -[ 97 98 99 ] l2s "abc" streq and -[ ] l2s "" streq and +"abc" s2q [ 97 98 99 ] streq and +"abc" s2q q2s "abc" streq and +[ 1 2 3 ] s2q [ 1 2 3 ] streq and +"" s2q [ ] streq and +[ 97 98 99 ] q2s "abc" streq and +[ ] q2s "" streq and if [ - " l2s, streq, lower, and upper PASS" puts cr + " q2s, streq, lower, and upper PASS" puts cr ] [ - " l2s, streq, lower, and upper FAIL" puts cr + " q2s, streq, lower, and upper FAIL" puts cr ] # 8. Q-form Operations @@ -182,11 +182,11 @@ if [ 99 [ 10 20 30 ] 1 qset [ 10 99 30 ] streq if [ " qset PASS" puts cr ] [ " qset FAIL" puts cr ] # Test qset [ 1 2 3 ] rev [ 3 2 1 ] streq [ 1 2 ] [ 3 4 ] lcat [ 1 2 3 4 ] streq and -[ 1 2 ] s2l [ 1 2 ] streq and +[ 1 2 ] s2q [ 1 2 ] streq and if [ - " rev, lcat and s2l PASS" puts cr + " rev, lcat and s2q PASS" puts cr ] [ - " rev, lcat and s2l FAIL" puts cr + " rev, lcat and s2q FAIL" puts cr ] # 9. Bitwise Operations