(* Copyright 2003 Sean Proctor This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA The license is at . *) exception BadInput; fun mkshoes(date) = let val colors = #["red", "orange", "yellow", "green", "blue", "khaki", "black"]; val random = Rand.mkRandom(Word.fromInt(date)); fun rand() = Rand.range(0, 6)(random()); val shoe1 = Vector.sub(colors, rand()); val shoe2 = Vector.sub(colors, rand()); in if shoe1 <> shoe2 then (shoe1, shoe2) else (Vector.sub(colors, rand()), Vector.sub(colors, rand())) end; fun current_date() = valOf(Int.fromString(Date.fmt("%Y%m%d")(Date.fromTimeLocal(Time.now())))); fun check_input(x) = let val date = Int.fromString(x); in if isSome(date) andalso size(x) = 8 then valOf(date) else raise BadInput end; fun mkdate(nil) = current_date() | mkdate(x::nil) = check_input(x) | mkdate(_) = raise BadInput; fun print_shoes(_, args) = let val date = mkdate(args); val shoes = mkshoes(date); in ( print("On " ^ Int.toString(date) ^ "\nshoe 1: " ^ #1(shoes) ^ "\nshoe 2: " ^ #2(shoes) ^ "\n"); OS.Process.success ) end;