@@ -711,7 +711,7 @@ impl Executor {
711
711
print ! ( "{a}" ) ;
712
712
}
713
713
}
714
-
714
+
715
715
// Standard output with new line
716
716
"println" => {
717
717
let a = self . pop_stack ( ) . get_string ( ) ;
@@ -769,6 +769,16 @@ impl Executor {
769
769
play_sine_wave ( frequency, duration_secs) ;
770
770
}
771
771
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
+
772
782
// Commands of control
773
783
774
784
// evaluate string as program
@@ -925,6 +935,29 @@ impl Executor {
925
935
} ) ;
926
936
}
927
937
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
+
928
961
// Mapping a list
929
962
"map" => {
930
963
let code = self . pop_stack ( ) . get_string ( ) ;
@@ -1005,27 +1038,6 @@ impl Executor {
1005
1038
. or_insert ( Type :: String ( "" . to_string ( ) ) ) ;
1006
1039
}
1007
1040
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
-
1029
1041
// Commands of memory manage
1030
1042
1031
1043
// pop in the stack
@@ -1386,28 +1398,11 @@ impl Executor {
1386
1398
} )
1387
1399
}
1388
1400
1389
- "cls" => {
1390
- self . clearscreen ( ) ;
1391
- }
1392
-
1393
- "clear" => {
1394
- self . clearscreen ( ) ;
1395
- }
1396
-
1397
1401
// If it is not recognized as a command, use it as a string.
1398
1402
_ => self . stack . push ( Type :: String ( command) ) ,
1399
1403
}
1400
1404
}
1401
1405
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
-
1411
1406
/// Pop stack's top value
1412
1407
fn pop_stack ( & mut self ) -> Type {
1413
1408
if let Some ( value) = self . stack . pop ( ) {
0 commit comments