File: stack.kl1

package info (click to toggle)
klic 3.003-1.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 7,068 kB
  • ctags: 6,333
  • sloc: ansic: 101,584; makefile: 3,395; sh: 1,321; perl: 312; exp: 131; tcl: 111; asm: 102; lisp: 4; sed: 1
file content (48 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ---------------------------------------------------------- 
%   (C)1994,1995 Institute for New Generation Computer Technology 
%       (Read COPYRIGHT for detailed information.) 
%   (C)1996, 1997, 1998, 1999 Japan Information Processing Development Center
%       (Read COPYRIGHT-JIPDEC for detailed information.)
----------------------------------------------------------- */
:- module stack.


create(Stream) :-
	main(Stream,[],[]).

main([],		 []	   )+Pool.
main([],		 [S|ST])+Pool :- main(S,ST	  )+Pool.
main([do(S)|T],	 ST	   )+Pool :- main(S,[T|ST])+Pool.
otherwise.
main([Message|T],ST	   )+Pool :- message(Message)-Pool, main(T,ST)+Pool.


message(empty(YorN),[]		 )+Pool :-
	YorN = yes,
	Pool = [].
message(empty(YorN),[CAR|CDR])+Pool :-
	YorN = no,
	Pool = [CAR|CDR].


message(put(Value),Pool1,Pool2) :-
	Pool2 = [Value|Pool1].

message(get(Value),[CAR|CDR],Pool2) :-
	Value = CAR,
	Pool2 = CDR.

message(get_if_any(Value),[],       Pool2) :-
	Value = {},
	Pool2 = [].
message(get_if_any(Value),[CAR|CDR],Pool2) :-
	Value = {CAR},
	Pool2 = CDR.

message(get_all(Value),Pool1,Pool2) :-
	Value = Pool1,
	Pool2 = [].

message(carbon_copy(Value),Pool1,Pool2) :-
	Value = Pool1,
	Pool2 = Pool1.