@@ -519,7 +519,7 @@ final class Interpreter(
519
519
)
520
520
exprValue match
521
521
case IntegerVal (newValue) =>
522
- values(index1)(index1 ) = newValue
522
+ values(index1)(index2 ) = newValue
523
523
exprValue
524
524
case other =>
525
525
throw EvalException (
@@ -536,10 +536,10 @@ final class Interpreter(
536
536
)
537
537
exprValue match
538
538
case RealVal (newValue) =>
539
- values(index1)(index1 ) = newValue
539
+ values(index1)(index2 ) = newValue
540
540
exprValue
541
541
case IntegerVal (newValue) =>
542
- values(index1)(index1 ) = newValue
542
+ values(index1)(index2 ) = newValue
543
543
exprValue
544
544
case other =>
545
545
throw EvalException (
@@ -556,7 +556,7 @@ final class Interpreter(
556
556
)
557
557
exprValue match
558
558
case StringVal (newValue) =>
559
- values(index1)(index1 ) = newValue
559
+ values(index1)(index2 ) = newValue
560
560
exprValue
561
561
case other =>
562
562
throw EvalException (
@@ -573,7 +573,7 @@ final class Interpreter(
573
573
)
574
574
exprValue match
575
575
case BooleanVal (newValue) =>
576
- values(index1)(index1 ) = newValue
576
+ values(index1)(index2 ) = newValue
577
577
exprValue
578
578
case other =>
579
579
throw EvalException (
@@ -690,7 +690,7 @@ final class Interpreter(
690
690
IntegerVal (value)
691
691
} catch {
692
692
case _ : NumberFormatException =>
693
- throw EvalException (s " You entered invalid value for ' ${sym.asVar} ' : ' ${inputValue}'. " , id)
693
+ throw EvalException (s " You entered invalid value for ' ${matrixName} [ ${index1} ][ ${index2} ] ' : ' ${inputValue}'. " , id)
694
694
}
695
695
case RunVal .RealMatrixVal (values) =>
696
696
if ! values.indices.contains(index1) then
@@ -706,7 +706,7 @@ final class Interpreter(
706
706
RealVal (value)
707
707
} catch {
708
708
case _ : NumberFormatException =>
709
- throw EvalException (s " You entered invalid value for ' ${sym.asVar} ' : ' ${inputValue}'. " , id)
709
+ throw EvalException (s " You entered invalid value for ' ${matrixName} [ ${index1} ][ ${index2} ] ' : ' ${inputValue}'. " , id)
710
710
}
711
711
case RunVal .StringMatrixVal (values) =>
712
712
if ! values.indices.contains(index1) then
@@ -732,7 +732,7 @@ final class Interpreter(
732
732
BooleanVal (value)
733
733
} catch {
734
734
case _ : IllegalArgumentException =>
735
- throw EvalException (s " You entered invalid value for ' ${sym.asVar} ' : ' ${inputValue}'. " , id)
735
+ throw EvalException (s " You entered invalid value for ' ${matrixName} [ ${index1} ][ ${index2} ] ' : ' ${inputValue}'. " , id)
736
736
}
737
737
case _ =>
738
738
throw EvalException (
@@ -760,7 +760,7 @@ final class Interpreter(
760
760
IntegerVal (value)
761
761
} catch {
762
762
case _ : NumberFormatException =>
763
- throw EvalException (s " You entered invalid value for ' ${sym.asVar} ' : ' ${inputValue}'. " , id)
763
+ throw EvalException (s " You entered invalid value for ' ${arrayName} [ ${index} ] ' : ' ${inputValue}'. " , id)
764
764
}
765
765
case RunVal .RealArrayVal (values) =>
766
766
if ! values.indices.contains(index) then
@@ -771,7 +771,7 @@ final class Interpreter(
771
771
RealVal (value)
772
772
} catch {
773
773
case _ : NumberFormatException =>
774
- throw EvalException (s " You entered invalid value for ' ${sym.asVar} ' : ' ${inputValue}'. " , id)
774
+ throw EvalException (s " You entered invalid value for ' ${arrayName} [ ${index} ] ' : ' ${inputValue}'. " , id)
775
775
}
776
776
case RunVal .StringArrayVal (values) =>
777
777
if ! values.indices.contains(index) then
@@ -787,7 +787,7 @@ final class Interpreter(
787
787
BooleanVal (value)
788
788
} catch {
789
789
case _ : IllegalArgumentException =>
790
- throw EvalException (s " You entered invalid value for ' ${sym.asVar} ' : ' ${inputValue}'. " , id)
790
+ throw EvalException (s " You entered invalid value for ' ${arrayName} [ ${index} ] ' : ' ${inputValue}'. " , id)
791
791
}
792
792
case _ =>
793
793
throw EvalException (
@@ -1331,6 +1331,23 @@ final class Interpreter(
1331
1331
args.head match
1332
1332
case n : StringVal => Future (IntegerVal (n.value.toInt))
1333
1333
case _ => throw EvalException (s " Expected a String argument in function ${func.name}" , id)
1334
+ // matrices
1335
+ case func @ NumRows =>
1336
+ validateArgsNumber(id, func.name, 1 , args.size)
1337
+ args.head match
1338
+ case m : IntegerMatrixVal => Future (IntegerVal (m.values.length))
1339
+ case m : RealMatrixVal => Future (IntegerVal (m.values.length))
1340
+ case m : StringMatrixVal => Future (IntegerVal (m.values.length))
1341
+ case m : BooleanMatrixVal => Future (IntegerVal (m.values.length))
1342
+ case _ => throw EvalException (s " Expected Matrix argument in function ${func.name}" , id)
1343
+ case func @ NumCols =>
1344
+ validateArgsNumber(id, func.name, 1 , args.size)
1345
+ args.head match
1346
+ case m : IntegerMatrixVal => Future (IntegerVal (if m.values.isEmpty then 0 else m.values(0 ).length))
1347
+ case m : RealMatrixVal => Future (IntegerVal (if m.values.isEmpty then 0 else m.values(0 ).length))
1348
+ case m : StringMatrixVal => Future (IntegerVal (if m.values.isEmpty then 0 else m.values(0 ).length))
1349
+ case m : BooleanMatrixVal => Future (IntegerVal (if m.values.isEmpty then 0 else m.values(0 ).length))
1350
+ case _ => throw EvalException (s " Expected Matrix argument in function ${func.name}" , id)
1334
1351
// misc
1335
1352
case ReadInput =>
1336
1353
state = State .WAITING_FOR_INPUT
0 commit comments