--- /dev/null
+/****************************************************************************
+Ejercicio: 2.1
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 14:34:05 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ proc {P X}
+ if X>0 then {P X-1} end % La llamada es unbounded
+ {System.show X}
+ end
+ % Imprimimos algo de ejemplo
+ {P 5}
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.10
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 15:59:18 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+
+ fun {SMerge Xs Ys}
+ case Xs#Ys
+ of nil#Ys then Ys
+ [] Xs#nil then Xs
+ [] (X|Xr)#(Y|Yr) then
+ if X=<Y then X|{SMerge Xr Ys}
+ else Y|{SMerge Xs Yr} end
+ end
+ end
+
+ {System.show {SMerge [5 6 7 8 9] [0 1 2 3 4]}}
+
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.11
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 16:05:51 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+
+ fun {IsEven X}
+ if X==0 then true else {IsOdd X-1} end
+ end
+ fun {IsOdd X}
+ if X==0 then false else {IsEven X-1} end
+ end
+
+ {System.show {IsEven 100000000}}
+ {System.show {IsOdd 100000000}}
+ {System.show {IsEven 100000001}}
+ {System.show {IsOdd 100000001}}
+
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.2
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 14:34:05 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ N=3
+ proc {MulByN X ?Y}
+ Y=N*X
+ end
+ A = 10
+ B
+ % N = 5 Da un assert al compilar (pero compila) y al ejecutar.
+ {MulByN A B}
+ {System.show B}
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.3
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 15:06:39 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ fun {Muero B}
+ if B then {System.show "Esto NO debería imprimirse"} end
+ % Acá lanza la excepción, porque el if/else debe retornar un valor
+ %{System.show "Esto NO debería imprimirse"}
+ end
+ proc {NoMuero B}
+ if B then {System.show "Esto NO debería imprimirse"} end
+ % Acá no hay problema, porque no se retorna un valor
+ %{System.show "Esto debería imprimirse"}
+ end
+ {NoMuero false}
+ X = {Muero false}
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.4
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 15:08:32 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ proc {If X}
+ case X
+ of true then {System.show true}
+ else {System.show false}
+ end
+ end
+ {If true}
+ {If false}
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.5
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 15:14:38 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ proc {Test X}
+ case X
+ of a|Z then {System.show 'case'(1)}
+ [] f(a) then {System.show 'case'(2)}
+ [] Y|Z andthen Y==Z then {System.show 'case'(3)}
+ [] Y|Z then {System.show 'case'(4)}
+ [] f(Y) then {System.show 'case'(5)}
+ else {System.show 'case'(6)} end
+ end
+ {Test [b c a]}
+ {Test f(b(3))}
+ {Test f(a)}
+ {Test f(a(3))}
+ {Test f(d)}
+ {Test [a b c]}
+ {Test [c a b]}
+ {Test a|a}
+ {Test '|'(a b c)}
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.6
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 15:24:15 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ proc {Test X}
+ {System.show 'proc'}
+ {System.show X}
+ case X
+ of f(a Y c) then {System.show 'case'(1)}
+ else {System.show 'case'(2)}
+ end
+ end
+ {System.show 'inicio'}
+ local X Y in {Test f(X b Y)} end % Se queda esperando a que se bindee X!
+ {System.show 'post1'}
+ local X Y in {Test f(a Y d)} end
+ {System.show 'post2'}
+ local X Y in {Test f(X Y d)} end
+ {System.show 'post3'}
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.7
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 15:33:55 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ Max3 Max5
+ proc {SpecialMax Value ?SMax}
+ fun {SMax X}
+ if X>Value then X else Value end
+ end
+ end
+ {SpecialMax 3 Max3} % Algo así como un constructor de funciones
+ {SpecialMax 5 Max5}
+ {System.show [{Max3 4} {Max5 4}]}
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :
--- /dev/null
+/****************************************************************************
+Ejercicio: 2.9
+Alumno: Leandro Lucarella
+Fecha: mié jul 27 15:45:41 ART 2005
+****************************************************************************/
+
+functor
+import
+ Application
+ System
+define
+ fun {Sum1 N}
+ if N==0 then 0 else N+{Sum1 N-1} end
+ end
+ fun {Sum2 N S}
+ if N==0 then S else {Sum2 N-1 N+S} end
+ end
+
+ %{System.show {Sum1 100000000}} No funciona, se agota la memoria
+
+ {System.show {Sum2 100000000 0}} % Anda, supongo que porque lo puede
+ % convertir en un ciclo
+
+ {Application.exit 0}
+end
+
+% vim: set et sw=4 sts=4 filetype=oz :