@@ -16,6 +16,7 @@ use std::fmt;
1616use std:: fmt:: Debug ;
1717use std:: hash:: { Hash , Hasher } ;
1818use std:: rc:: Rc ;
19+ use std:: cmp:: { Ord , Ordering } ;
1920
2021// @TODO Change IFn's name -- IFn is a function, not an IFn.
2122// The body it executes just happens to be an the IFn.
@@ -441,7 +442,7 @@ impl Value {
441442 . map ( |rc_arg| rc_arg)
442443 . collect :: < Vec < Rc < Value > > > ( ) ;
443444
444- if arg_rc_values. len ( ) < 1 {
445+ if arg_rc_values. is_empty ( ) {
445446 return Some ( Rc :: new ( Value :: Condition ( format ! (
446447 "Wrong number of arguments (Given: {}, Expect: >=1" ,
447448 arg_rc_values. len( )
@@ -500,7 +501,8 @@ impl Value {
500501 let arg_rc_values = PersistentList :: iter ( args)
501502 . map ( |rc_arg| rc_arg)
502503 . 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...
504506 return Some ( Rc :: new ( Value :: Condition ( std:: string:: String :: from (
505507 "Wrong number of arguments given to let (Given: 0, Expecting: 1 or 2)" ,
506508 ) ) ) ) ;
@@ -546,19 +548,16 @@ impl Value {
546548 // quote just involves an infinite loop of macroexpansion. Or so it seems
547549 //
548550 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 ! (
551553 "Wrong number of arguments (Given: {}, Expected: 1)" ,
552554 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 (
558558 "Wrong number of arguments (Given: 0, Expected: 1)" ,
559- ) ) ) )
560- } else {
561- Some ( args. nth ( 0 ) )
559+ ) ) ) ) ,
560+ Ordering :: Equal => Some ( args. nth ( 0 ) ) ,
562561 }
563562 }
564563 //
@@ -692,7 +691,7 @@ impl Evaluable for Rc<Value> {
692691 //
693692 // Sounds less correct but also seems clearer; the current error message relies on
694693 // 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 ! (
696695 "Execution Error: {} cannot be cast to clojure.lang.IFn" ,
697696 ifn. type_tag( )
698697 ) ) ) )
0 commit comments