int f(int x) { return x * 2 + 1; } int main() { return f(f(1)); }
f x = x * x g x = f x + f x f 2 + g 2
f x = x * x g x = f x + f x f (3 + g 2)
f x = x * x g x = f x + f x g (f 2)
(λz.z) ((λx.(λy.y) x) w),os redexes (λz.z) ((λx.(λy.y) x) w) e (λx.(λy.y) x) w são mais exteriores que (λy.y) x, sendo (λx.(λy.y) x) w o mais à direita.)
f y = y * y g x = f x f (g 5)
f x = x + x g f x = f x + 1 h = g f h 3
o f g x = f (g x) h x = x + 1 o h h y
y := 2 * x + 2; z := x * 2; x := 2 * x + 1
x := 2 * x + 1; y := x + 1; z := x - 1
x1, x2 := e1, e2cujo efeito é atribuir, em "simultâneo", o valor da expressão e1 à variável x1 e o valor da expressão e2 à variável x2.
Defina a semântica denotacional desta instrução e mostre que
x, y := y, x
troca os valores de x e de y.
i := 0; q := 0; while i < n do ( q := q + 2 * i + 1; i := i + 1 )(Sugestões: (1) considere que n0, o valor inicial de n, é tal que i assume os valores 0, 1, 2, ..., n0-2, n0-1, n0, e expanda o cálculo da semântica denotacional em concordância (i.e., para os valores de i: 0, 1, 2, n0-2, n0-1 e n0, substituindo o que acontece entre 2 e n0-2 por "..." onde for conveniente); (2) mantenha o valor de q na forma 0 + 1 + 3 + ... (ou 1 + 3 + ...).)
if x = 0 then ( y := z ^ 2; x := 2 * y ) else ( y := (z + x) ^ 2; z := z + x; x := x + 2 * y )
Tenha em conta os tipos pré-definidos:
0, 1, 2, ... : int +, -, * : int -> int -> int true, false : bool = : 'a -> 'a -> bool [] : 'a list hd : 'a list -> 'a tl : 'a list -> 'a list :: : 'a -> 'a list -> 'a list
fun f x y = let fun g x = 3 * x + y in g (x - 1) end; f 4 5;
{ int a = 5, b = 2, c = 0; while (b > 0) { int a = 3; a = (a - b) * (a + b); c += a; --b; } { int d; { int a = 15, b; b = c + d + a; } d = b; } return c; }
1 let val x = 2 in 2 let fun y = x + y in 3 let val x = 7 in 4 x + 5 f x 6 end 7 end 8 end;estude a evolução do conteúdo da pilha de execução durante a sua avaliação, e determine o valor das ocorrências de
x
(nas linhas 2, 4 e 5) e o valor final, quando
var x: integer; procedure p(y: integer) begin y := 1; x := 10 end; x := 0; p(x);Traduza o código apresentado para ML, de modo a reflectir os modos de passagem de argumentos indicados, e calcule o valor final de
x
em cada um dos casos.
begin integer i; procedure pass(x, y: integer) begin x := x + 1; y := x + 1; x := y; i := i + 1 end; i := 1; pass(i, i); print i end