Index to the Examples
This page lists the code examples used in the book. They are listed by
chapter and in the order that they appear in the book.
Hello World
- hw.sml
- This is the basic "hello world" program.
- echo.sml
- This is the echo program.
- wordCnt.sml
- This is the word counter which implements the state machine with mutually
recursive state functions.
- wordCnt2.sml
- This is the word counter which implements the state machine with a state variable.
- getopt1.sml
- This is the first getopt program written in a mostly-functional style.
- getopt2.sml
- This is the second getopt program written using a hash table.
- getopt3.sml
- This is the third getopt program written using the GetOpt module
from the SML/NJ Utility library.
Hello World
- ibr_cvt.sml
- This is the integer buffer reader program.
- wcx.sml
- This is the word count program.
- scanwx.sml
- This demonstrates scanning a directory tree looking for writable executable files.
- statx.sml
- This demonstrates reporting a file's status.
- ttyx.sml
- This demonstrates changing the erase character on your terminal.
The SML/NJ Extensions
- sizeof.sml
- This demonstrates estimating the size of objects in memory.
- interrupt.sml
- This demonstrates setting up a simple interrupt handler.
- ticker.sml
- This demonstrates the interval timer.
- profile.sml
- This demonstrates profiling.
- susp.sml
- This demonstrates using lazy suspensions to "memoise" a function.
- weak.sml
- This demonstrates using weak pointers when caching.
- exnhist.sml
- This demonstrates fetching the exception history list.
- simpletcp.sml
- This is the simple TCP client.
- tcpserver.sml
- This is the simple TCP server.
- pollserver.sml
- This is the polling server.
The Utility Libraries
- intmap.sml
- This demonstrates integer maps.
- plist.sml
- This demonstrates property lists.
- dyn.sml
- This demonstrates using exceptions to simulate dynamic typing.
- sort.sml
- This demonstrates sorting.
- format.sml
- This demonstrates formatting strings for printing.
- regexp.sml
- This demonstrates regular expressions.
Concurrency
- counter.sml
- This is the counter object.
- counter2.sml
- This demonstrates getting the counter's value.
- counter3.sml
- This demonstrates getting the counter's value through an event.
- counter4.sml
- This demonstrates getting the counter's value with a time-out.
- counter5.sml
- This demonstrates getting the counter's value using an I-var.
- timeouts.sml
- This demonstrates time-out behaviour.
- sema.sml
- This demonstrates a semaphore.
- sema2.sml
- This demonstrates semaphores via synchronous variables.
Under the Hood
- speed.sml
- This tests basic SML/NJ performance.
- chan_scaling.sml
- This tests how CML performs when sending messages through
a channel.
- thr_scaling.sml
- This tests spawning a thread and how it scales
to large numbers of threads.
- timeout_evt.sml
- This compares the behaviour of the CML.atTimeEvt and CML.timeOutEvt
functions.
- timing.sml
- This is common code for the timing functions.