File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -741,6 +741,17 @@ pub fn standard_vm() -> VM {
741741 Ok ( Value :: bool ( args[ 0 ] . as_list ( ) . is_some ( ) ) )
742742 } ) ) ;
743743
744+ vm. define_global ( "empty?" , native ( "empty?" , |args| {
745+ if args. len ( ) != 1 { return Err ( "empty? expects 1 argument" . to_string ( ) ) ; }
746+ if let Some ( list) = args[ 0 ] . as_list ( ) {
747+ Ok ( Value :: bool ( list. is_empty ( ) ) )
748+ } else if let Some ( s) = args[ 0 ] . as_string ( ) {
749+ Ok ( Value :: bool ( s. is_empty ( ) ) )
750+ } else {
751+ Err ( "empty? expects list or string" . to_string ( ) )
752+ }
753+ } ) ) ;
754+
744755 vm. define_global ( "fn?" , native ( "fn?" , |args| {
745756 if args. len ( ) != 1 { return Err ( "fn? expects 1 argument" . to_string ( ) ) ; }
746757 Ok ( Value :: bool ( args[ 0 ] . as_function ( ) . is_some ( ) || args[ 0 ] . as_native_function ( ) . is_some ( ) || args[ 0 ] . as_compiled_function ( ) . is_some ( ) ) )
You can’t perform that action at this time.
0 commit comments