numbas / Numbas

A completely browser-based e-assessment/e-learning system, with an emphasis on mathematics
http://www.numbas.org.uk
Apache License 2.0
207 stars 122 forks source link

Arrays within arrays: accessing subarrays #141

Closed BillFoster closed 11 years ago

BillFoster commented 12 years ago

Not working properly.

Easiest example is

{abs([ 1, [ 2 , 3 ] ] [ 1 ] )} gives NaN

I have pulled in the last fix on null arrays

More complicated examples can be given - but this is typical.

christianp commented 12 years ago

This is yet another shonky type-system problem. It will need some thinking.

christianp commented 12 years ago

Lazy evaluation and weak type-analysis don't mix. This will keep popping up until I rewrite the JME system in the Summer.

BillFoster commented 12 years ago

I still have the same problems.

I have put the code of an attempt to use subarrays (only the variables part of the code) here git://gist.github.com/1892601.git

No problem about accepting the variable factmess It is the variable valmess:"if(si[2][0]=0, etc"

If not equal to 0 then fine, if equal to 0 then the following error:

TypeError: Cannot use ‘in’ operator to search for ‘0’ in 0 at [object Object].evaluate (file:///D:/Numbas/output/q4home/scripts/jme.js:1491:19) at Object.evaluate (file:///D:/Numbas/output/q4home/scripts/jme.js:460:18) at Object.texsubvars (file:///D:/Numbas/output/q4home/scripts/jme.js:725:17) at Object.contentsubvars (file:///D:/Numbas/output/q4home/scripts/jme.js:642:16) at Object.evaluate (file:///D:/Numbas/output/q4home/scripts/jme.js:450:27) at [object Object].evaluate (file:///D:/Numbas/output/q4home/scripts/jme.js:1400:15) at Object.evaluate (file:///D:/Numbas/output/q4home/scripts/jme.js:460:18) at compute (file:///D:/Numbas/output/q4home/scripts/jme-variables.js:171:26) at Object.makeVariables (file:///D:/Numbas/output/q4home/scripts/jme-variables.js:176:4) at file:///D:/Numbas/output/q4home/scripts/question.js:59:39

BillFoster commented 12 years ago

Forget the last comment - found an obvious error in the code