Skip to content

Commit

Permalink
lambda calculus and free variables
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@706 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Nov 13, 2009
1 parent cadb00e commit c48555b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions topics/exercises/lambda1/Makefile
@@ -0,0 +1,6 @@
test:
swipl -f syntax.pro -t "write(term(`cat input.txt`)),nl"

prompt:
swipl -s syntax.pro

1 change: 1 addition & 0 deletions topics/exercises/lambda1/input.txt
@@ -0,0 +1 @@
lambda(f,lambda(g,lambda(x,apply(f,apply(g,x)))))
12 changes: 12 additions & 0 deletions topics/exercises/lambda1/syntax.pro
@@ -0,0 +1,12 @@
% see slides #147

term(x).
term(y).
term(z).
term(f).
term(g).
term(h).

term(apply(M,N)) :- term(M), term(N).
term(lambda(X,M)) :- term(X), term(M).

6 changes: 6 additions & 0 deletions topics/exercises/lambda2/Makefile
@@ -0,0 +1,6 @@
test:
swipl -f variables.pro -t "free(`cat input.txt`,FV),write(FV),nl"

prompt:
swipl -s variables.pro

1 change: 1 addition & 0 deletions topics/exercises/lambda2/input.txt
@@ -0,0 +1 @@
apply(lambda(x,y),lambda(z,z))
12 changes: 12 additions & 0 deletions topics/exercises/lambda2/syntax.pro
@@ -0,0 +1,12 @@
% see slides #147

term(x).
term(y).
term(z).
term(f).
term(g).
term(h).

term(apply(M,N)) :- term(M), term(N).
term(lambda(X,M)) :- term(X), term(M).

25 changes: 25 additions & 0 deletions topics/exercises/lambda2/variables.pro
@@ -0,0 +1,25 @@
:- ['syntax.pro'].

%% see slide 153

free(x,[x]).
free(y,[y]).
free(z,[z]).
free(f,[f]).
free(g,[g]).
free(h,[h]).

free(apply(M,N),FV) :-
free(M,FV1),
free(N,FV2),
append(FV1,FV2,FV).

free(lambda(X,M),FV) :-
free(M,FV1),
(
append(L1,[X|L2],FV1),
append(L1,L2,FV)
;
FV = FV1
).

0 comments on commit c48555b

Please sign in to comment.