File tree Expand file tree Collapse file tree 1 file changed +15
-14
lines changed Expand file tree Collapse file tree 1 file changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -772,6 +772,21 @@ impl Executor {
772
772
self . stack . push ( Type :: List ( list) ) ;
773
773
}
774
774
775
+ // Get index of the list
776
+ "index" => {
777
+ let findhint = self . pop_stack ( ) . get_string ( ) ;
778
+ let findtarget = self . pop_stack ( ) . get_list ( ) ;
779
+
780
+ for index in 0 ..( findtarget. len ( ) ) {
781
+ if findhint == findtarget[ index] . clone ( ) . get_string ( ) {
782
+ self . stack . push ( Type :: Number ( index as f64 ) ) ;
783
+ return ;
784
+ }
785
+ }
786
+ self . log_print ( String :: from ( "Error! item not found in the list" ) . as_str ( ) . to_owned ( ) + "\n " ) ;
787
+ self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
788
+ }
789
+
775
790
// Sorting in the list
776
791
"sort" => {
777
792
let mut list: Vec < String > = self
@@ -1277,20 +1292,6 @@ impl Executor {
1277
1292
} )
1278
1293
}
1279
1294
1280
- "index" => {
1281
- let findhint = self . pop_stack ( ) . get_string ( ) ;
1282
- let findtarget = self . pop_stack ( ) . get_list ( ) ;
1283
-
1284
- for index in 0 ..( findtarget. len ( ) ) {
1285
- if findhint == findtarget[ index] . clone ( ) . get_string ( ) {
1286
- self . stack . push ( Type :: Number ( index as f64 ) ) ;
1287
- return ;
1288
- }
1289
- }
1290
- self . log_print ( String :: from ( "Error! item not found in this list" ) . as_str ( ) . to_owned ( ) + "\n " ) ;
1291
- self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
1292
- }
1293
-
1294
1295
// If it is not recognized as a command, use it as a string.
1295
1296
_ => self . stack . push ( Type :: String ( command) ) ,
1296
1297
}
You can’t perform that action at this time.
0 commit comments