Project

General

Profile

ternary_automatic_type_conversion.p

Greg Shah, 03/18/2013 06:49 PM

Download (6.96 KB)

 
1
def var i as int init 14.
2
def var d as dec init 30.0.
3
def var i64 as int64 init 9.
4
def var da as date init today.
5
def var dt1 as datetime init ?. 
6
def var dtz1 as datetime-tz init ?.
7
def var dt2 as datetime init now. 
8
def var dtz2 as datetime-tz init now.
9
def var bool as log init true.
10
def var bool2 as log init false.
11
def var h as handle.
12
def var h2 as handle.
13
def var ch1 as char init "99".
14
def var ch2 as char init "99".
15
def var lc1 as longchar init "99999".
16
def var lc2 as longchar init "99999".
17
def var r1 as recid.
18
def var re1 as recid.
19
def var r2 as rowid.
20
def var ro2 as rowid.
21
def var m1 as memptr.
22
def var mp1 as memptr.
23
def var m2 as raw.
24
def var mr2 as raw.
25

    
26
def var bogus as int init ?.
27

    
28
/*
29
 for integer/int64 op1, the op2 is not allowed to be:
30
 - non-unknown datetime (but unknown is fine)
31
 - non-unknown datetime-tz (but unknown is fine)
32
 - longchar
33
 - memptr
34
 - raw
35
*/
36

    
37
i = if bogus <> ? then i else ?.
38
i = if bogus <> ? then i else d.
39
i = if bogus <> ? then i else i64.
40
i = if bogus <> ? then i else 42.1.
41
i = if bogus <> ? then i else da.   /* equivalent to the julian day number */
42
i = if bogus <> ? then i else dt1.  /* if init to a real value, there is a runtime failure */
43
i = if bogus <> ? then i else dtz1. /* if init to a real value, there is a runtime failure */
44
i = if bogus <> ? then i else 01/01/2000.
45
i = if bogus <> ? then i else bool.  /* equivalent to int 1 */
46
i = if bogus <> ? then i else true.  /* equivalent to int 1 */
47
i = if bogus <> ? then i else false. /* equivalent to int 0 */
48
i = if bogus <> ? then i else h.
49
i = if bogus <> ? then i else ch1.    /* must be a valid number in the text, else a runtime error */
50
i = if bogus <> ? then i else "14".  /* must be a valid number in the text, else a runtime error */
51
i = if bogus <> ? then i else r1.
52
i = if bogus <> ? then i else r2.
53
i64 = if bogus <> ? then i64 else ?.
54
i64 = if bogus <> ? then i64 else d.
55
i64 = if bogus <> ? then i64 else i.
56
i64 = if bogus <> ? then i64 else 42.1.
57
i64 = if bogus <> ? then i64 else 42.
58
i64 = if bogus <> ? then i64 else da.   /* equivalent to the julian day number */
59
i64 = if bogus <> ? then i64 else dt1.  /* if init to a real value, there is a runtime failure */
60
i64 = if bogus <> ? then i64 else dtz1. /* if init to a real value, there is a runtime failure */
61
i64 = if bogus <> ? then i64 else 01/01/2000.
62
i64 = if bogus <> ? then i64 else bool.  /* equivalent to int 1 */
63
i64 = if bogus <> ? then i64 else true.  /* equivalent to int 1 */
64
i64 = if bogus <> ? then i64 else false. /* equivalent to int 0 */
65
i64 = if bogus <> ? then i64 else h.
66
i64 = if bogus <> ? then i64 else ch1.   /* must be a valid number in the text, else a runtime error */
67
i64 = if bogus <> ? then i64 else "14". /* must be a valid number in the text, else a runtime error */
68
i64 = if bogus <> ? then i64 else r1.
69
i64 = if bogus <> ? then i64 else r2.
70

    
71
/* for decimal op1, the op2 must be numeric or the unknown literal */
72

    
73
d = if bogus <> ? then d else ?.
74
d = if bogus <> ? then d else i.
75
d = if bogus <> ? then d else i64.
76
d = if bogus <> ? then d else 42.
77

    
78
/* for date/datetime/datetime-tz op1, the op2 must be one of the date types or the unknown literal */
79
/* even if the character expression is a properly formatted date, they can't be used */
80

    
81
da = if bogus <> ? then da else ?.
82
da = if bogus <> ? then da else dt1.
83
da = if bogus <> ? then da else dt2.
84
da = if bogus <> ? then da else dtz1.
85
da = if bogus <> ? then da else dtz2.
86
da = if bogus <> ? then da else 01/01/2000.
87
dt1 = if bogus <> ? then dt1 else ?.
88
dt1 = if bogus <> ? then dt1 else da.
89
dt1 = if bogus <> ? then dt1 else dtz1.
90
dt1 = if bogus <> ? then dt1 else dtz2.
91
dt1 = if bogus <> ? then dt1 else 01/01/2000.
92
dtz1 = if bogus <> ? then dtz1 else ?.
93
dtz1 = if bogus <> ? then dtz1 else da.
94
dtz1 = if bogus <> ? then dtz1 else dt1.
95
dtz1 = if bogus <> ? then dtz1 else dt2.
96
dtz1 = if bogus <> ? then dtz1 else 01/01/2000.
97

    
98
/* for logical op1, the op2 must be logical or the unknown literal */
99
/* even if the character expression is a properly formatted logical, they can't be used */
100

    
101
bool = if bogus <> ? then bool else ?.
102
bool = if bogus <> ? then bool else bool2.
103
bool = if bogus <> ? then bool else true.
104
bool = if bogus <> ? then bool else false.
105

    
106
/* for handle op1, the op2 must be handle or the unknown literal */
107

    
108
h = if bogus <> ? then h else ?.
109
h = if bogus <> ? then h else h2.
110

    
111
/* for recid op1, the op2 must be recid or the unknown literal */
112
/* rowid is not allowed! */
113

    
114
r1 = if bogus <> ? then r1 else ?.
115
r1 = if bogus <> ? then r1 else re1.
116

    
117
/* for rowid op1, the op2 must be rowid or the unknown literal */
118
/* recid is not allowed! */
119

    
120
r2 = if bogus <> ? then r2 else ?.
121
r2 = if bogus <> ? then r2 else ro2.
122

    
123
/* for memptr op1, the op2 must be memptr or the unknown literal */
124
/* raw is not allowed! */
125

    
126
m1 = if bogus <> ? then m1 else ?.
127
m1 = if bogus <> ? then m1 else mp1.
128

    
129
/* for raw op1, the op2 must be raw or the unknown literal */
130
/* memptr is not allowed! */
131

    
132
m2 = if bogus <> ? then m2 else ?.
133
m2 = if bogus <> ? then m2 else mr2.
134

    
135
/* for character op1, the op2 must be character, longchar or the unknown literal */
136

    
137
ch1 = if bogus <> ? then ch1 else ?.
138
ch1 = if bogus <> ? then ch1 else ch2.
139
ch1 = if bogus <> ? then ch1 else lc1.
140
ch1 = if bogus <> ? then ch1 else "yep".
141

    
142
/* for longchar op1, the op2 must be character, longchar or the unknown literal */
143

    
144
lc1 = if bogus <> ? then lc1 else ?.
145
lc1 = if bogus <> ? then lc1 else ch1.
146
lc1 = if bogus <> ? then lc1 else lc2.
147
lc1 = if bogus <> ? then lc1 else "yep".
148

    
149
/* unknown literal as op1, takes the type of op2 */
150
/* unknown literal cannot be both op1 and op2 */
151

    
152
i = if bogus <> ? then ? else i.
153
i = if bogus <> ? then ? else i64.
154
i = if bogus <> ? then ? else 42.
155
i = if bogus <> ? then ? else 42.1.
156
i = if bogus <> ? then ? else d.
157
i64 = if bogus <> ? then ? else i.
158
i64 = if bogus <> ? then ? else i64.
159
i64 = if bogus <> ? then ? else 42.
160
i64 = if bogus <> ? then ? else 42.1.
161
i64 = if bogus <> ? then ? else d.
162
d = if bogus <> ? then ? else i.
163
d = if bogus <> ? then ? else i64.
164
d = if bogus <> ? then ? else 42.
165
d = if bogus <> ? then ? else 42.1.
166
d = if bogus <> ? then ? else d.
167
da = if bogus <> ? then ? else da.
168
da = if bogus <> ? then ? else dt1.
169
da = if bogus <> ? then ? else dtz1.
170
dt1 = if bogus <> ? then ? else dt2.
171
dt1 = if bogus <> ? then ? else da.
172
dt1 = if bogus <> ? then ? else dtz1.
173
dtz1 = if bogus <> ? then ? else dtz2.
174
dtz1 = if bogus <> ? then ? else da.
175
dtz1 = if bogus <> ? then ? else dt1.
176
da = if bogus <> ? then ? else 01/01/2000.
177
dt1 = if bogus <> ? then ? else 01/01/2000.
178
dtz1 = if bogus <> ? then ? else 01/01/2000.
179
bool = if bogus <> ? then ? else bool2.
180
bool = if bogus <> ? then ? else true.
181
bool = if bogus <> ? then ? else false.
182
h = if bogus <> ? then ? else h2.
183
ch1 = if bogus <> ? then ? else ch2.
184
ch1 = if bogus <> ? then ? else lc1.
185
ch1 = if bogus <> ? then ? else "14".
186
lc1 = if bogus <> ? then ? else ch1.
187
lc1 = if bogus <> ? then ? else lc2.
188
lc1 = if bogus <> ? then ? else "14".
189
r1 = if bogus <> ? then ? else r1.
190
r2 = if bogus <> ? then ? else r2.
191
m1 = if bogus <> ? then ? else m1.
192
m2 = if bogus <> ? then ? else m2.
193