alias sml '/home/users2/sml/bin/sml'so (next time you login) to start the system you will only have to type the command sml.
use "hw.sml";You do not need to restart the SML system each time you want to reload a file. In fact, you should only need to enter the SML system just once during your session logged on. You can suspend the system like any other process, or run it from a separate window.
open <Library name>;For instance, if you want to use the function sqrt (square root) you need to open the Math library. Example:
> /home/users2/sml/bin/sml Standard ML of New Jersey, Version 110, December 9, 1997 [CM&CMB] val it = () : unit - open Math; opening Math type real = ?.real val pi : real val e : real val sqrt : real -> real val sin : real -> real val cos : real -> real val tan : real -> real val asin : real -> real val acos : real -> real val atan : real -> real val atan2 : real * real -> real val exp : real -> real val pow : real * real -> real val ln : real -> real val log10 : real -> real val sinh : real -> real val cosh : real -> real val tanh : real -> real - sqrt 0.1; val it = 0.316227766017 : real
- datatype bintree = emp | nod of bintree * int * bintree; datatype bintree = emp | nod of bintree * int * bintree - nod(nod(nod(emp,2,emp),3,emp),1,nod(nod(emp,4,emp),5,emp)); val it = nod (nod (nod #,3,emp),1,nod (nod #,5,emp)) : bintreeIn order to avoid this, you can use the "print switches" OF SML, which are
Compiler.Control.Print.printDepth (for data structures) Compiler.Control.Print.printLength (for lists) Compiler.Control.Print.stringDepth (for strings)You should set these at the prompt "-", e.g.,
- Compiler.Control.Print.printDepth := 1000; val it = () : unit - nod(nod(nod(emp,2,emp),3,emp),1,nod(nod(emp,4,emp),5,emp)); val it = nod (nod (nod (emp,2,emp),3,emp),1,nod (nod (emp,4,emp),5,emp)) : bintree
Unfortunately, the print command of SML works only on strings; for other data, you need to convert them to strings. You can use the SML libraries for the various conversions on predefined types. For user-defined data structures, you need to define your own conversion routines. Here below is an example of "tracing" a program. Note the use of the parenteses around the print command. They are neceesary because otherwise the ";" would be interpreted as the end of the definition.
- fun append  L = L | append (x::K) L = (print x; print "\n"; x:: append K L); val append = fn : string list -> string list -> string list - append ["a","b","c"] ["d","e","f"]; a b c val it = ["a","b","c","d","e","f"] : string list
- fun last [x] = x | last (x::L) = last L; stdIn:154.1-155.25 Warning: match nonexhaustive x :: nil => ... x :: L => ... val last = fn : 'a list -> 'aThe reason of this warning message is that the definition of last does not consider all possible pattern cases for the parameter: the case of empty list is missing. This warning has no consequences on the execution and you can just ignore it. But you should, of course, avoid applying last to the empty list.
Similar warnings are generated each time you don't consider all possible patterns in the definition of a function.
GC #0.0.0.0.3.41: (0 ms)This only means that the system has done a grbage collection. Just ignore it.
val cd = OS.FileSys.chDir; val pwd = OS.FileSys.getDir;You might want to put these two lines in a file and then use this file. You can then change and get your working directory via expressions like:
- pwd(); val it = "/home/users3/cg428/www/examples/SML" : string - cd "../../assignments"; val it = () : unit - pwd(); val it = "/home/users3/cg428/www/assignments" : string -