@@ -711,7 +711,7 @@ impl Executor {
711711 print ! ( "{a}" ) ;
712712 }
713713 }
714-
714+
715715 // Standard output with new line
716716 "println" => {
717717 let a = self . pop_stack ( ) . get_string ( ) ;
@@ -769,6 +769,16 @@ impl Executor {
769769 play_sine_wave ( frequency, duration_secs) ;
770770 }
771771
772+ // Claer the console screen
773+ "cls" | "clear" => {
774+ let result = clearscreen:: clear ( ) ;
775+ if result. is_err ( ) {
776+ println ! ( "Error! Failed to clear screen" ) ;
777+ self . stack
778+ . push ( Type :: Error ( String :: from ( "failed-to-clear-screen" ) ) ) ;
779+ }
780+ }
781+
772782 // Commands of control
773783
774784 // evaluate string as program
@@ -925,6 +935,29 @@ impl Executor {
925935 } ) ;
926936 }
927937
938+ // Generate a range
939+ "range" => {
940+ let step = self . pop_stack ( ) . get_number ( ) ;
941+ let max = self . pop_stack ( ) . get_number ( ) ;
942+ let min = self . pop_stack ( ) . get_number ( ) ;
943+
944+ let mut range: Vec < Type > = Vec :: new ( ) ;
945+
946+ for i in ( min as usize ..max as usize ) . step_by ( step as usize ) {
947+ range. push ( Type :: Number ( i as f64 ) ) ;
948+ }
949+
950+ self . stack . push ( Type :: List ( range) ) ;
951+ }
952+
953+ // Get length of list
954+ "len" => {
955+ let data = self . pop_stack ( ) . get_list ( ) ;
956+ self . stack . push ( Type :: Number ( data. len ( ) as f64 ) ) ;
957+ }
958+
959+ // Commands of functional programming
960+
928961 // Mapping a list
929962 "map" => {
930963 let code = self . pop_stack ( ) . get_string ( ) ;
@@ -1005,27 +1038,6 @@ impl Executor {
10051038 . or_insert ( Type :: String ( "" . to_string ( ) ) ) ;
10061039 }
10071040
1008- // Generate a range
1009- "range" => {
1010- let step = self . pop_stack ( ) . get_number ( ) ;
1011- let max = self . pop_stack ( ) . get_number ( ) ;
1012- let min = self . pop_stack ( ) . get_number ( ) ;
1013-
1014- let mut range: Vec < Type > = Vec :: new ( ) ;
1015-
1016- for i in ( min as usize ..max as usize ) . step_by ( step as usize ) {
1017- range. push ( Type :: Number ( i as f64 ) ) ;
1018- }
1019-
1020- self . stack . push ( Type :: List ( range) ) ;
1021- }
1022-
1023- // Get length of list
1024- "len" => {
1025- let data = self . pop_stack ( ) . get_list ( ) ;
1026- self . stack . push ( Type :: Number ( data. len ( ) as f64 ) ) ;
1027- }
1028-
10291041 // Commands of memory manage
10301042
10311043 // pop in the stack
@@ -1386,28 +1398,11 @@ impl Executor {
13861398 } )
13871399 }
13881400
1389- "cls" => {
1390- self . clearscreen ( ) ;
1391- }
1392-
1393- "clear" => {
1394- self . clearscreen ( ) ;
1395- }
1396-
13971401 // If it is not recognized as a command, use it as a string.
13981402 _ => self . stack . push ( Type :: String ( command) ) ,
13991403 }
14001404 }
14011405
1402- fn clearscreen ( & mut self ) {
1403- let result = clearscreen:: clear ( ) ;
1404- if result. is_err ( ) {
1405- println ! ( "Error! Failed to clear screen" ) ;
1406- self . stack
1407- . push ( Type :: Error ( String :: from ( "failed-to-clear-screen" ) ) ) ;
1408- }
1409- }
1410-
14111406 /// Pop stack's top value
14121407 fn pop_stack ( & mut self ) -> Type {
14131408 if let Some ( value) = self . stack . pop ( ) {
0 commit comments