File tree 6 files changed +26
-86
lines changed
6 files changed +26
-86
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,14 @@ func (s Bool) Type() *Type {
16
16
return BoolType
17
17
}
18
18
19
+ // Make a new bool - returns the canonical True and False values
20
+ func NewBool (t bool ) Bool {
21
+ if t {
22
+ return True
23
+ }
24
+ return False
25
+ }
26
+
19
27
func (a Bool ) M__bool__ () Object {
20
28
return a
21
29
}
Original file line number Diff line number Diff line change @@ -224,22 +224,14 @@ func (a Complex) M__le__(other Object) Object {
224
224
225
225
func (a Complex ) M__eq__ (other Object ) Object {
226
226
if b , ok := convertToComplex (other ); ok {
227
- if a == b {
228
- return True
229
- } else {
230
- return False
231
- }
227
+ return NewBool (a == b )
232
228
}
233
229
return NotImplemented
234
230
}
235
231
236
232
func (a Complex ) M__ne__ (other Object ) Object {
237
233
if b , ok := convertToComplex (other ); ok {
238
- if a != b {
239
- return True
240
- } else {
241
- return False
242
- }
234
+ return NewBool (a != b )
243
235
}
244
236
return NotImplemented
245
237
}
Original file line number Diff line number Diff line change @@ -195,10 +195,7 @@ func (a Float) M__ipow__(other, modulus Object) Object {
195
195
}
196
196
197
197
func (a Float ) M__bool__ () Object {
198
- if a == 0 {
199
- return False
200
- }
201
- return True
198
+ return NewBool (a != 0 )
202
199
}
203
200
204
201
func (a Float ) M__int__ () Object {
@@ -229,66 +226,42 @@ func (a Float) M__round__(digitsObj Object) Object {
229
226
230
227
func (a Float ) M__lt__ (other Object ) Object {
231
228
if b , ok := convertToFloat (other ); ok {
232
- if a < b {
233
- return True
234
- } else {
235
- return False
236
- }
229
+ return NewBool (a < b )
237
230
}
238
231
return NotImplemented
239
232
}
240
233
241
234
func (a Float ) M__le__ (other Object ) Object {
242
235
if b , ok := convertToFloat (other ); ok {
243
- if a <= b {
244
- return True
245
- } else {
246
- return False
247
- }
236
+ return NewBool (a <= b )
248
237
}
249
238
return NotImplemented
250
239
}
251
240
252
241
func (a Float ) M__eq__ (other Object ) Object {
253
242
if b , ok := convertToFloat (other ); ok {
254
- if a == b {
255
- return True
256
- } else {
257
- return False
258
- }
243
+ return NewBool (a == b )
259
244
}
260
245
return NotImplemented
261
246
}
262
247
263
248
func (a Float ) M__ne__ (other Object ) Object {
264
249
if b , ok := convertToFloat (other ); ok {
265
- if a != b {
266
- return True
267
- } else {
268
- return False
269
- }
250
+ return NewBool (a != b )
270
251
}
271
252
return NotImplemented
272
253
}
273
254
274
255
func (a Float ) M__gt__ (other Object ) Object {
275
256
if b , ok := convertToFloat (other ); ok {
276
- if a > b {
277
- return True
278
- } else {
279
- return False
280
- }
257
+ return NewBool (a > b )
281
258
}
282
259
return NotImplemented
283
260
}
284
261
285
262
func (a Float ) M__ge__ (other Object ) Object {
286
263
if b , ok := convertToFloat (other ); ok {
287
- if a >= b {
288
- return True
289
- } else {
290
- return False
291
- }
264
+ return NewBool (a >= b )
292
265
}
293
266
return NotImplemented
294
267
}
Original file line number Diff line number Diff line change @@ -307,10 +307,7 @@ func (a Int) M__ior__(other Object) Object {
307
307
}
308
308
309
309
func (a Int ) M__bool__ () Object {
310
- if a == 0 {
311
- return False
312
- }
313
- return True
310
+ return NewBool (a != 0 )
314
311
}
315
312
316
313
func (a Int ) M__index__ () Int {
@@ -343,66 +340,42 @@ func (a Int) M__round__(digits Object) Object {
343
340
344
341
func (a Int ) M__lt__ (other Object ) Object {
345
342
if b , ok := convertToInt (other ); ok {
346
- if a < b {
347
- return True
348
- } else {
349
- return False
350
- }
343
+ return NewBool (a < b )
351
344
}
352
345
return NotImplemented
353
346
}
354
347
355
348
func (a Int ) M__le__ (other Object ) Object {
356
349
if b , ok := convertToInt (other ); ok {
357
- if a <= b {
358
- return True
359
- } else {
360
- return False
361
- }
350
+ return NewBool (a <= b )
362
351
}
363
352
return NotImplemented
364
353
}
365
354
366
355
func (a Int ) M__eq__ (other Object ) Object {
367
356
if b , ok := convertToInt (other ); ok {
368
- if a == b {
369
- return True
370
- } else {
371
- return False
372
- }
357
+ return NewBool (a == b )
373
358
}
374
359
return NotImplemented
375
360
}
376
361
377
362
func (a Int ) M__ne__ (other Object ) Object {
378
363
if b , ok := convertToInt (other ); ok {
379
- if a != b {
380
- return True
381
- } else {
382
- return False
383
- }
364
+ return NewBool (a != b )
384
365
}
385
366
return NotImplemented
386
367
}
387
368
388
369
func (a Int ) M__gt__ (other Object ) Object {
389
370
if b , ok := convertToInt (other ); ok {
390
- if a > b {
391
- return True
392
- } else {
393
- return False
394
- }
371
+ return NewBool (a > b )
395
372
}
396
373
return NotImplemented
397
374
}
398
375
399
376
func (a Int ) M__ge__ (other Object ) Object {
400
377
if b , ok := convertToInt (other ); ok {
401
- if a >= b {
402
- return True
403
- } else {
404
- return False
405
- }
378
+ return NewBool (a >= b )
406
379
}
407
380
return NotImplemented
408
381
}
Original file line number Diff line number Diff line change @@ -26,10 +26,7 @@ func (t List) M__len__() Object {
26
26
}
27
27
28
28
func (t List ) M__bool__ () Object {
29
- if len (t ) > 0 {
30
- return True
31
- }
32
- return False
29
+ return NewBool (len (t ) > 0 )
33
30
}
34
31
35
32
func (t List ) M__iter__ () Object {
Original file line number Diff line number Diff line change @@ -24,10 +24,7 @@ func (t Tuple) M__len__() Object {
24
24
}
25
25
26
26
func (t Tuple ) M__bool__ () Object {
27
- if len (t ) > 0 {
28
- return True
29
- }
30
- return False
27
+ return NewBool (len (t ) > 0 )
31
28
}
32
29
33
30
func (t Tuple ) M__iter__ () Object {
You can’t perform that action at this time.
0 commit comments