Links und Funktionen
Sprachumschaltung

Navigationspfad
Sie sind hier: Startseite / Lehre / SS 2011 / Programmierung und Modellierung / Online Beispiele 27. Jun 11


Inhaltsbereich

Online Beispiele 27. Jun 11

Plain Text icon 270611.txt — Plain Text, 5 KB (5412 bytes)

Dateiinhalt

mhofmann@trento:~/pum$ sml
Standard ML of New Jersey v110.69 [built: Mon Jun  8 14:15:08 2009]
- exception LMU;
exception LMU
- raise LMU;
stdIn:2.1-2.10 Warning: type vars not generalized because of
   value restriction are instantiated to dummy types (X1,X2,...)

uncaught exception LMU
  raised at: stdIn:2.7-2.10
- fun f n = if n < 0 then raise LMU else 2*n;
val f = fn : int -> int
- f 12;
val it = 24 : int
- f 36;
val it = 72 : int
- f ~1;

uncaught exception LMU
  raised at: stdIn:2.16-2.19
- fun f n = 13 * (if n < 0 then raise LMU else 2*n);
val f = fn : int -> int
- f 2;
val it = 52 : int
- f ~1;

uncaught exception LMU
  raised at: stdIn:2.22-2.25
- exception Fehler;
exception Fehler
- fun fakt n = if n < 0 then raise Fehler else
= if n = 0 then 1 else n * fakt (n-1);
val fakt = fn : int -> int
- fakt 3;
val it = 6 : int
- fakt 0;
val it = 1 : int
- fakt ~1;

uncaught exception Fehler
  raised at: stdIn:8.34-8.40
- fun fakt n = if n < 0 then raise Fehler else
= n * fakt(n-1);
val fakt = fn : int -> int
- fakt 6;

uncaught exception Fehler
  raised at: stdIn:8.16-8.22
- 
- fun fakt n = if n < 0 then raise Fehler else 
= if n = 0 then 1 else n * fakt(n-1);
val fakt = fn : int -> int
- fakt 9;
val it = 362880 : int
- fakt ~1;

uncaught exception Fehler
  raised at: stdIn:15.34-15.40
- fun f x = Int.toString (fakt x) 
= handle Fehler => "Falsches Argument!";
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
val f = fn : int -> string
- f 9;
val it = "362880" : string
- f ~1;
val it = "Falsches Argument!" : string
- exception Fehler of int;
exception Fehler of int
- fun fakt n = if n < 0 then raise Fehler n else 
= if n = 0 then 1 else n * fakt(n-1);
val fakt = fn : int -> int
- fakt 9;
val it = 362880 : int
- fakt ~1;

uncaught exception Fehler
  raised at: stdIn:23.34-23.42
- fun f x = Int.toString(fakt x) handle 
= Fehler z => "fakt: falsches Argument: " ^ Int.toString z;
val f = fn : int -> string
- f 9;
val it = "362880" : string
- f ~27;
val it = "fakt: falsches Argument: ~27" : string
- ref 14;
val it = ref 14 : int ref
- val meinezelle = it;
val meinezelle = ref 14 : int ref
- !meinezelle;
val it = 14 : int
- meinezelle := 15;
val it = () : unit
- !meinezelle;
val it = 15 : int
- let val wrdlbrmpfd = meinezelle := 19 in 42;
= let val wrdlbrmpfd = meinezelle := 19 in 42 end;
= let val wrdlbrmpfd = meinezelle := 19 in 42 end;  C-c C-c
Interrupt
- let val wrdlbrmpfd = meinezelle := 19 in 42 end;
val it = 42 : int
- !meinezelle;
val it = 19 : int
- (meinezelle := 34;42) ; 
val it = 42 : int
- !meinezelle;
val it = 34 : int
- fun mkrandom seed range = let val n = ref seed in 
= fn () => let val x = (1291 * !n + 9991) mod 32768 in (n:=x; (x mod range)+1 end;
= end;
=   C-c C-c
Interrupt
- fun mkrandom seed range = let val n = ref seed in 
= fn () => let val x = (1291 * n * fakt ( n-1 ) ; + 9991) mod 32768 in (n:=x; (x mod range)+1 ) end end;
stdIn:43.49 Error: expression or pattern begins with infix identifier "+"
stdIn:43.23-43.46 Error: operator and operand don't agree [literal]
  operator domain: int * int
  operand:         int * 'Z ref
  in expression:
    1291 * n
stdIn:43.41-43.44 Error: operator and operand don't agree [overload]
  operator domain: 'Z * 'Z
  operand:         'Y ref * int
  in expression:
    n - 1
stdIn:43.49-43.55 Error: operator and operand don't agree [literal]
  operator domain: 'Z * 'Z
  operand:         int
  in expression:
    + 9991
- fun mkrandom seed range = let val n = ref seed in 
= fn () => let val x = (1291 * !n + 9991) mod 32768 in (n:=x; (x mod range)+1 ) end end;
val mkrandom = fn : int -> int -> unit -> int
- mkrandom 1345 6;
val it = fn : unit -> int
- val wuerfel = it;
val wuerfel = fn : unit -> int
- wuerfel ();
val it = 5 : int
- wuerfel ();
val it = 6 : int
- wuerfel ();
val it = 5 : int
- wuerfel ();
val it = 2 : int
- wuerfel ();
val it = 5 : int
- wuerfel ();
val it = 6 : int
- wuerfel ();
val it = 3 : int
- wuerfel ();
val it = 6 : int
- wuerfel ();
val it = 1 : int
- wuerfel ();
val it = 2 : int
- val wuerfel2 = mkrandom 1345 6;
val wuerfel2 = fn : unit -> int
- wuerfel2();
val it = 5 : int
- wuerfel2();
val it = 6 : int
- wuerfel2();
val it = 5 : int
- wuerfel2();
val it = 2 : int
- wuerfel2();
val it = 5 : int
- wuerfel2();
val it = 6 : int
- wuerfel2();
val it = 3 : int
- wuerfel2();
val it = 6 : int
- wuerfel();
val it = 5 : int
- wuerfel();
val it = 2 : int
- wuerfel();
val it = 3 : int
- wuerfel();
val it = 6 : int
- wuerfel();
val it = 1 : int
- fun memoize f = let val x = ref 0 in let
= val fx = ref (f 0) in 
= fn y => if y = !x then !fx else
= let val fy = f y in x:=y ; fx := fy ; fy end end end; 
val memoize = fn : (int -> 'a) -> int -> 'a
- fun g n = if n = 0 then 0 else n * g(n-1);
val g = fn : int -> int
- g 10;
val it = 0 : int
- g 100000;
val it = 0 : int
- g 1000000;
val it = 0 : int
- g 5000000;
val it = 0 : int
- val gmem = memoize g; 
val gmem = fn : int -> int
- gmem 10;
val it = 0 : int
- gmem 1000000;
val it = 0 : int
- gmem 1000000;
val it = 0 : int
- gmem 2000000;
val it = 0 : int
- gmem 2000000;
val it = 0 : int
- gmem 1000000;
val it = 0 : int
- gmem 1000000;
val it = 0 : int
- gmem 4000000;
val it = 0 : int
- gmem 4000000;
val it = 0 : int
- gmem 4000000;
val it = 0 : int
- gmem 4000000;
val it = 0 : int
- gmem 4000000;
val it = 0 : int
- gmem 4000000;
val it = 0 : int
- gmem 4000000;
val it = 0 : int
- 

Artikelaktionen


Funktionsleiste