diff options
Diffstat (limited to 'chapter22/docs/examples')
| -rw-r--r-- | chapter22/docs/examples/A_helloWorld.smp | 3 | ||||
| -rw-r--r-- | chapter22/docs/examples/BubbleSort.smp | 25 |
2 files changed, 28 insertions, 0 deletions
diff --git a/chapter22/docs/examples/A_helloWorld.smp b/chapter22/docs/examples/A_helloWorld.smp new file mode 100644 index 00000000..07ff935f --- /dev/null +++ b/chapter22/docs/examples/A_helloWorld.smp @@ -0,0 +1,3 @@ +// -*- mode: java; -*- +sys.io.p("Hello, World!"); +return 0; diff --git a/chapter22/docs/examples/BubbleSort.smp b/chapter22/docs/examples/BubbleSort.smp new file mode 100644 index 00000000..af110159 --- /dev/null +++ b/chapter22/docs/examples/BubbleSort.smp @@ -0,0 +1,25 @@ +// -*- mode: java; -*- + + +val _exit = { u8[~] msg -> + sys.io.p(msg); + sys.libc._exit(1); +}; + +struct Scan { + int !x; + u8[~] buf; +}; + + +// Read from stdin a line of the form "[ 4, 3, 2, 1]" and print it sorted. +val main = { -> + Scan !s = new Scan{ buf = sys.io.stdin(); }; + var junk = new u8[1]; + while( s.x < s.buf# ) { + sys.io.p("scan "); + junk[0] = s.buf[s.x++]; + sys.io.p(junk); + }; + return 0; +}; |
