Variables in ND1 [FIXED IN v.1.5]

Bugs in ND1 (report'em, get'em fixed)

Variables in ND1 [FIXED IN v.1.5]

Postby d_motto » Thu Aug 02, 2012 11:49 am

I have noticed that, sometimes, if you use i for an index variable in JavaScript, when your function is done the value of i (the square root of -1) has been changed to whatever your index was. The annoying thing is, sometimes it is not changed. For an example, try the "p" program in Number Theory (partitions).

Other variables sometimes have values outside the function as well. This seems to happen whether the value is initiated with the "var" keyword, or not.

Also, when editing a program like p, if you attempt to position the cursor after the letter i in the phrase "i++", you cannot do it. Also a phrase like i+ does not allow you to position the cursor after the i (for backspace to delete it). These things are more of an annoyance than a bug, I think.

David Motto
d_motto
 
Posts: 35
Joined: Tue Apr 17, 2012 9:19 am

Re: Variables in ND1

Postby d_motto » Thu Aug 02, 2012 8:36 pm

I think the issue with editing something like "i+" or "i++" or even "i+++" is a problem in iOS prior to version 5. I am running 4.2 on my iPod touch 3rd generation.

David Motto
d_motto
 
Posts: 35
Joined: Tue Apr 17, 2012 9:19 am

Re: Variables in ND1

Postby oliver » Fri Aug 03, 2012 2:01 am

Hi Dave,

Yes. i getting changed is a serious known problem. Only the constants i and e should in practice be affected by this. (Important as they are!) Currently, you have to switch away from the calculator to a different tab, and back, to revert an overwritten variable.

I know what causes it but don't yet quite know how to fix it.

There's an obscure way to make sure this doesn't happen: put a comment /*as is*/ (written exactly like this), in your JS program.
For example,
Code: Select all
function(x) { /*as is*/
    return ME.isInt(x);
}


This disables the code morpher in ND1 and uses your function exactly as typed.

What's the code morpher and what does it have to do with i?

ND1 gives you the convenience of typing the names of calculator built-in functions and variables names without a prefix. This is accomplished by using a series of invisible with() statements that surrounds your code during execution.
A function
Code: Select all
function(x) {
    return isInt(x);
}

internally really is
Code: Select all
function(x) {
    with(calculator.vars[calculator.currentDataCategory]) with(calculator.vars) with(calculator.vars.local) with(calculator.functions) with(calculator.functions[calculator.currentDataCategory]) {
    return isInt(x);
    }
}

These with() statements also blend the variables and functions defined in your local folder into the active scope.
Now, i is part of the constants in calculator.vars and, weirdly, even if you use "var i", the with()s will make any assignments to i affect calculator.vars.i instead of your local copy! I will upgrade to using JavaScript v1.7 or v1.8 soon which allows for variables with block scope via "let". That should solve the problem, but I'm trying to find a solution for use of var i, too.

Note that if you disable the code morpher, built-in and your folder's functions need to properly scoped. Hence, ME.isInt() and not just isInt(), in the example. (Or ME.vector.total() instead of vector.total().) To access a function in your folder: calculator.functions[calculator.currentDataCategory]["myFunc"]().

Thanks for reporting. This will be addressed.

As for the cursor positioning problem. I dunno. I've seen little weirdness like that before but it's entirely down to iOS trying to be smart about what "text" is. My suggestion would be to position the cursor further to the right, and then backspace more than you originally intended, and re-type the lost text again (hopefully only one or two characters). But you sure figured that out yourself.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Re: Variables in ND1

Postby oliver » Mon Aug 13, 2012 2:03 am

This problem has been solved. The fix will appear in the next update.

For those interested: The solution was simple: the with() chain mentioned above no longer includes calculator.vars. The ability to type i or e in JavaScript and refer to the mathematical and physical constants respectively was a bit suspect anyway. A new global alias cons has been created, and you now type cons.i or cons.e (or Math.E) to get them.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron