@@ -16,6 +16,7 @@ use std::fmt;
16
16
use std:: fmt:: Debug ;
17
17
use std:: hash:: { Hash , Hasher } ;
18
18
use std:: rc:: Rc ;
19
+ use std:: cmp:: { Ord , Ordering } ;
19
20
20
21
// @TODO Change IFn's name -- IFn is a function, not an IFn.
21
22
// The body it executes just happens to be an the IFn.
@@ -441,7 +442,7 @@ impl Value {
441
442
. map ( |rc_arg| rc_arg)
442
443
. collect :: < Vec < Rc < Value > > > ( ) ;
443
444
444
- if arg_rc_values. len ( ) < 1 {
445
+ if arg_rc_values. is_empty ( ) {
445
446
return Some ( Rc :: new ( Value :: Condition ( format ! (
446
447
"Wrong number of arguments (Given: {}, Expect: >=1" ,
447
448
arg_rc_values. len( )
@@ -500,7 +501,8 @@ impl Value {
500
501
let arg_rc_values = PersistentList :: iter ( args)
501
502
. map ( |rc_arg| rc_arg)
502
503
. collect :: < Vec < Rc < Value > > > ( ) ;
503
- if arg_rc_values. len ( ) < 1 || arg_rc_values. len ( ) > 2 {
504
+ if arg_rc_values. is_empty ( ) || arg_rc_values. len ( ) > 2 {
505
+ // @TODO: we give 0 but it may be 3, 4, 5...
504
506
return Some ( Rc :: new ( Value :: Condition ( std:: string:: String :: from (
505
507
"Wrong number of arguments given to let (Given: 0, Expecting: 1 or 2)" ,
506
508
) ) ) ) ;
@@ -546,19 +548,16 @@ impl Value {
546
548
// quote just involves an infinite loop of macroexpansion. Or so it seems
547
549
//
548
550
QuoteMacro => {
549
- if args. len ( ) > 1 {
550
- Some ( Rc :: new ( Value :: Condition ( format ! (
551
+ match args. len ( ) . cmp ( & 1 ) {
552
+ Ordering :: Greater => Some ( Rc :: new ( Value :: Condition ( format ! (
551
553
"Wrong number of arguments (Given: {}, Expected: 1)" ,
552
554
args. len( )
553
- ) ) ) )
554
- }
555
- // @TODO define is_empty()
556
- else if args. len ( ) < 1 {
557
- Some ( Rc :: new ( Value :: Condition ( std:: string:: String :: from (
555
+ ) ) ) ) ,
556
+ // @TODO define is_empty()
557
+ Ordering :: Less => Some ( Rc :: new ( Value :: Condition ( std:: string:: String :: from (
558
558
"Wrong number of arguments (Given: 0, Expected: 1)" ,
559
- ) ) ) )
560
- } else {
561
- Some ( args. nth ( 0 ) )
559
+ ) ) ) ) ,
560
+ Ordering :: Equal => Some ( args. nth ( 0 ) ) ,
562
561
}
563
562
}
564
563
//
@@ -692,7 +691,7 @@ impl Evaluable for Rc<Value> {
692
691
//
693
692
// Sounds less correct but also seems clearer; the current error message relies on
694
693
// you pretty much already knowing when this error message is called
695
- try_apply_ifn. unwrap_or ( Rc :: new ( Value :: Condition ( format ! (
694
+ try_apply_ifn. unwrap_or_else ( || Rc :: new ( Value :: Condition ( format ! (
696
695
"Execution Error: {} cannot be cast to clojure.lang.IFn" ,
697
696
ifn. type_tag( )
698
697
) ) ) )
0 commit comments