added more examples
This commit is contained in:
@@ -167,6 +167,14 @@ When the packed executable runs:
|
|||||||
- If a `_main` word is defined in the environment, it is executed automatically.
|
- If a `_main` word is defined in the environment, it is executed automatically.
|
||||||
- If `_main` is not present, the interpreter falls back to running the standard REPL.
|
- If `_main` is not present, the interpreter falls back to running the standard REPL.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
The [examples](examples/) directory contains several simple examples of Clyx programming, namely:
|
||||||
|
|
||||||
|
- a [Hello World](examples/hello.clx) program
|
||||||
|
- a [FizzBuzz](examples/fizzbuzz.clx) program
|
||||||
|
- a [TCP echo server](examples/tcpecho.clx)
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
### Where does the name Clyx originate from?
|
### Where does the name Clyx originate from?
|
||||||
|
|||||||
Regular → Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env clyx
|
||||||
|
:: _main [
|
||||||
|
for [ 1 101 range ] [
|
||||||
|
1 # tracking flag
|
||||||
|
swap # the index is on top
|
||||||
|
dup 3 mod 0= if [ "Fizz" puts swap drop 0 swap ] [ ]
|
||||||
|
dup 5 mod 0= if [ "Buzz" puts swap drop 0 swap ] [ ]
|
||||||
|
swap if [ . ] [ drop cr ]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env clyx
|
#!/usr/bin/env clyx
|
||||||
:: _main [
|
:: _main [
|
||||||
"Hello, world!" puts cr
|
"Hello from Clyx!" puts cr
|
||||||
]
|
]
|
||||||
|
|||||||
Executable
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env clyx
|
||||||
|
:: _main [
|
||||||
|
"Listening on port 1337..." puts cr
|
||||||
|
1337 nlstn # listen on port 1337
|
||||||
|
1 while [ # outer connection accept loop
|
||||||
|
dup read # accept a new connection -> conn_fd
|
||||||
|
1 # loop condition for client session loop
|
||||||
|
while [
|
||||||
|
dup read # read data
|
||||||
|
dup vlen 0 != # check if data is non-empty
|
||||||
|
if [ over swap write drop 1 ] [ drop 0 ]
|
||||||
|
]
|
||||||
|
close # close the connection socket
|
||||||
|
1 # loop condition for outer server loop
|
||||||
|
]
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user