-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_Logical_Negation.olly
90 lines (71 loc) · 2.45 KB
/
05_Logical_Negation.olly
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
##########################################################
Logical negation operations. Notice that we used a
new logical operator the unary '-', logical negation
operator, in the last tutorial text.
##########################################################
#! NO_EXCEPT = false
def adder(x):
def n():
def n(y):x + y;
-n
;
n
;
let f = (adder '42')
let x = '8'
"x = " << x << endl
"f = " << -f << endl
"(f x) = " << (f x) << endl
endl
##########################################################
Most often we think of logical negation in true and
false terms. Below are some example.
##########################################################
let p = true
let q = false
"p & -q = " << (p & -q) << endl
"p | -q = " << (p | -q) << endl
"p ^ -q = " << (p ^ -q) << endl
endl
##########################################################
So logical negation work oposite of the indetity
operator. Getting the value of what it is applied
to then inverts its value, if applicable, and places
the result on the deque.
##########################################################
let x = '42'
" x = " << (x) << endl
"-x = " << (-x) << endl
endl
##########################################################
Lets look again at the adder function again.
##########################################################
def adder(x):
def n():
def n(y):x + y;
-n
# By invoking the negation of 'n' we are binding
# or specializing the current scope to the funciton.
# Then it is being left on the deque. This way a
# new function cn be curried and assigned, like we
# do wiht the function 'f' below.
;
n
# By invoke the evaluation of this variable 'n'
# the internaly enclosed function of 'n' is then
# left as the result of the evaluation on the deque.
;
let f = (adder '42')
let x = '8'
"x = " << x << endl
"f = " << -f << endl # Here wer are asking for the
# specification of 'f'. So we
# can see the function.
"(f x) = " << (f x) << endl
endl
##########################################################
Notice one last thing concerning the negation of 'f'.
The body of the function has been evaluated to all
postscipt operations. That happens during when the
code is compiled, for most binary operators.
##########################################################