-
Notifications
You must be signed in to change notification settings - Fork 0
/
6th_Sept_data_structure_2
42 lines (27 loc) · 1.1 KB
/
6th_Sept_data_structure_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
// lists from pair
// pair(data, pair(...)) - nested pair
//const denoms = pair(100,pair(50,pair(20,pair(10,5)));
//head(denoms); // 100 -> single elements
//tail(denoms); // pair(50,pair(20,pair(10,5))) -> set of remaining elements
// when denoms = (100,50)
// it should return 50 and set of elements
// => empty list : null
const denoms = pair(100,
pair(50,
pair(20,
pair(10,
pair(5,
null)))));
// a list is either a null or a pair whose tail is a list (recursive definition of list cause we are using list itself to define list)
const my_list = null;
const your_list = pair(8, null);
// null is a list
// evaluation of null in an if condition?
// retreiving data from the list:
head(denoms); // 100
head(tail(denoms)); // 50
head(tail(tail(denoms))); // 20
head(tail(tail(tail(denoms)))); // 10
head(tail(tail(tail(tail(denoms))))); // 5
tail(tail(tail(tail(tail(denoms))))); // null
// null is absence of value?