Diferencia entre revisiones de «Segundo Parcial 1er Cuat 2016 (Paradigmas)»
De Cuba-Wiki
(Página creada con «== Ejercicio 1 == a) Number >> pesos ^Dinero new. Number >> centavos ^Dinero new. b) Number >> pesos ^Dinero withValue: self. Number >> centavos ^Dinero wit...») |
Sin resumen de edición |
||
(No se muestran 2 ediciones intermedias del mismo usuario) | |||
Línea 1: | Línea 1: | ||
{{Back|Paradigmas de Lenguajes de Programación}} | |||
== Ejercicio 1 == | == Ejercicio 1 == | ||
a) | a) | ||
Línea 32: | Línea 34: | ||
== Ejercicio 2 == | == Ejercicio 2 == | ||
a) | |||
II) | |||
Forma lógica: | |||
*1) <math>\forall t_1 \forall t_2 subclase(t_1, t_2) \implies subtipo(t_1, t_2)</math> | |||
*2) <math>\forall t_1 subclase(t_1, t_1)</math> | |||
*3) <math>\forall t_1 \forall t_2 (\exists t_3 subclase (t_3, t_2) \wedge extiende(t_1, t_3)) \implies subclase(t_1, t_2)</math> | |||
*4) <math>extiende(perro, animal)</math> | |||
*GOAL) <math>\forall x \neg subtipo(perro, x)</math> | |||
Forma clausal (<math>t = t_1, u = t_2, v = t_3</math>): | |||
1) | |||
*<math>\forall t \forall u \neg subclase(t, u) \vee subtipo(t, u)</math> | |||
*<math>\{\neg subclase(t_1, u_1) \vee subtipo(t_1, u_1)\}</math> | |||
2) | |||
*<math>\{subclase(t_2, t_2)\}</math> | |||
3) | |||
*<math>\forall t \forall u (\neg \exists v subclase (v, u) \wedge extiende(t, v)) \vee subclase(t, u)</math> | |||
*<math>\forall t \forall u (\forall v \neg subclase (v, u) \vee \neg extiende(t, v)) \vee subclase(t, u)</math> | |||
*<math>\forall t \forall u \forall v \neg subclase (v, u) \vee \neg extiende(t, v) \vee subclase(t, u)</math> | |||
*<math>\{\neg subclase (v_3, u_3) \vee \neg extiende(t_3, v_3) \vee subclase(t_3, u_3)\}</math> | |||
4) | |||
*<math>\{extiende(perro, animal)\}</math> | |||
GOAL) | |||
*<math>\{\neg subtipo(perro, x_g)\}</math> | |||
b) | b) | ||
asignaciónValida(+declaraciones, ?asignacion) | asignaciónValida(+declaraciones, ?asignacion) |
Revisión actual - 20:56 9 jul 2016
Ejercicio 1
a)
Number >> pesos ^Dinero new.
Number >> centavos ^Dinero new.
b)
Number >> pesos ^Dinero withValue: self.
Number >> centavos ^Dinero withValue: self/100.
Dinero >> withValue: aNumber ^(Dinero new) value = aNumber.
Dinero >> = aDinero ^value = aDinero getValue.
Dinero >> + aDinero ^Dinero withValue: value + aDinero getValue.
Dinero >> getValue ^value.
c)
Dinero class >> actualizacion : unDiccionario keysAndValuesDo: [:k :v | number class compile (' k, '^Dinero withValue: ', v asString, '* self')].
Ejercicio 2
a) II) Forma lógica:
- 1)
- 2)
- 3)
- 4)
- GOAL)
Forma clausal ():
1)
2)
3)
4)
GOAL)
b)
asignaciónValida(+declaraciones, ?asignacion) asignaciónValida(d, asig(v1, v2)) :- member(d, decl(v1, t1)), member(d, decl(v2, t2)), v1 \= v2, subtipo(t2, t1).
c)
reemplazar(+programaConVariables, +tipos, +asignacion) reemplazar([], _, []). reemplazar([asig(A, B)|PCVA], T, [asig(A, B)|PCVB]) :- reemplazar(PCVA, T, PCVB). reemplazar([decl(A, TA)|PCVA], T, [decl(B, TB)|PCVB]) :- (var(TA), member(B, TB)); (\+ var(TA), TB == TA), reemplazar(PCVA, T, PCVB).
d)
unicovalido(+programaConVariables, +tipos) unicovalido(PCV, T) :- reemplazar(PCV, T, P), valido(P), not(reemplazar(PCV, T, P2), valido(P2), P1 \= P2).