free software resistance
the cost of computing freedom is eternal vigilance
### codecalc
*originally posted:* feb 2025
*updated:* mar 2025
codecalc is licensed gpl 3.0:
=> codecalc/gpl-3.0.html gpl-3.0.html
### 1.0
=> codecalc/codecalc10.html codecalc10
the previous version fixed a minor bug from 0.4 or 0.5, this version fixes a bug from the version before it- 0.8.
the reason youre supposed to test your code is that sometimes you say:
> some unused code is removed
but that actually includes code that was needed for most of the buttons to work.
then because you didnt test the buttons, you just assume theyre still working in version 0.9.
and thats how you get to version 1.0. its fixed now. it was tested this time. it probably works...
### 0.9
=> codecalc/codecalc09.html codecalc09
version 0.9 fixes a bug in 0.4 or 0.5 that lost the ability to add quoted text labels as part of the user-edited code.
### 0.8
=> codecalc/codecalc08.html codecalc08
version 0.8 creates unique loop variables (so you can nest loops) and implements error messages that prevent execution; the first error of this type will complain if the "next" command isnt on its own line.
keyboard layout and help text are cleaned up, some unused code is removed, conditionals were abandoned due to overly-complicated behaviour.
repeat is renamed "rep" to make code shorter and the button smaller.
### 0.7
=> codecalc/codecalc07.html codecalc07
version 0.7 fixes the tricky "cosmetic" bug that outputs "= 0" when looping due to it counting "next" as part of an expression. the parser knows better, but the display output code did not.
also it turns out the only command that didnt already treat negative values properly was topwr? this is now fixed...
+ and - and / and * also do math and have a single parameter (which should allow negative values rather than assuming the minus operator is being called) but that was already fixed. commands like sin and cos also do math, however "sin -5" should be treated as "sin minus 5" because sin has no parameters (it applies to the existing value instead). repeat does not accept a negative value, and it also is not an math function. all this is to explain why topwr should be the only existing function that requires special treatment of negative values, after the basic operators.
another minor display bug is fixed, next (when at appears at the end of a loop, not during each iteration, which this version fixes) should now append a newline when displayed.
### 0.6
=> codecalc/codecalc06.html codecalc06
version 0.6 drastically increases output efficiency, by utilising the buffered print features of its predecessor, consolidating most of the updates to the output display. in practical terms, while repeating a loop 100 times before could cause the browser to stop responding and write a 2gb .core file while you wait, it is now possible for it to write the output of 1000 lines fairly quickly. the loop feature may not get very broad use and its implementation could be a mistake. either way, the efficiency of the loop feature for this version has increased more than 100 times.
### 0.5
=> codecalc/codecalc05.html codecalc05
version 0.5 adds the "set" button that 0.4 shouldve had, it changes the "for" command to "repeat", which is now implemented- presently only one repeat loop is possible, as the mechanism to provide unique counter variables is not implemented.
there is also a cosmetic bug that has been partially fixed, in that it tries to show the "next" command on the end of each loop... instead, next only appears after the loop is completed. but the "= 0" where the extra "next" commands were displayed is trickier to deal with.
the repeat command can have math expressions before it on the same line, but this is not required (nor recommended), while the "next" command should be the first and only command on the line that includes it. there are no plans to make the "next" command more flexible, its really better on its own line.
### 0.4
=> codecalc/codecalc04.html codecalc04
version 0.4 adds the set command, which lets you use variables like this:
```
5 set apples
10 * 11 set oranges
apples + oranges
```
### 0.3
=> codecalc/codecalc03.html codecalc03
version 0.3 moves handling of - / + and * to the preprocessor, accomplishing two goals- the first is that it better handles a lack of spaces between what are technically keywords. the parser was never designed to do that, and it was easier to have the preprocessor handle this than the parser. as a bonus, it now tries to handle the division, subtraction, multiplication and addition of negative numbers properly- the difference between "minus" and "negative", even though the same character is used.
it was then discovered that negative infinity can also result from dividing by zero, so that now also results in an appropriate error message.
not much else has changed yet- a grey equals sign is now displayed before the evaluation of the expression- but the preprocessor is now aware of and can take advantage of context that the main parser was never designed to.
note that this is still a calculator, and operator order is strictly left-to-right, just as the keys would be pressed on a traditional calculator (rather than a computer). there are no plans to create an expression evaluator that uses parentheses, and that was never intended as part of the design.
also, named mathematical functions like "topwr" or "atn" do not yet work with negative values, as so far the preprocessor only tracks context for + - / and *. trying to raise something to the power of -5 should at this time result in topwr being called without a parameter, before calling the routine for subtraction instead of treating -5 as a negative value.
### 0.2
=> codecalc/codecalc02.html codecalc02
version 0.2 makes it a little more obvious what the design for codecalc is meant to be; it shows an optimisation of each expression next to the evaluation that was shown in 0.1. a division by zero error is created when the expression is "infinity".
it was clear that a preprocessor (a second parser) specific to codecalc features would help, this was originally intended to help further the implementation of variable handling, as the project codecalc is based on has stricter rules for those that wouldnt benefit codecalc users.
0.2 includes a fun bug when trying to add, subtract, multiply or divide a negative number. quasi didnt have this problem, as the code to subtract or divide by -5 is "minus -5" or "divby -5" respectively. but for codecalc its "- -5" and the parser now turns that into "minus minus 5" which at best means two calls to a function with a missing parameter and a positive number, rather than one call with a negative number.
### 0.1
=> codecalc/codecalc01.html codecalc01
the first version shows the general concept and direction for codecalc; as many changes as were made from quasi (a basic-like toy programming language with a similar interface) a lot more time was spent deciding what codecalc would be like to use, and which features it would retain.
a good example of this is functions. functions could be a very useful feature for a calculator like this, and keeping them was definitely considered at length.
but considering users who want a calculator they can understand, whether or not theyre coders (coders would probably be happier with the python repl than codecalc, but this is made in the hope it will have at least a bit of appeal for everyone) and what would make an ideal way of doing functions for codecalc, it was decided that this was unlikely to be implemented in any ideal fashion, and it would be better to go in another direction as a compromise.
you wont see that yet, even in version 3, because it was decided to have SOME support for variables but how exactly to do that hasnt been fully implemented yet. for now, a hack makes it so codecalc can be used without variables.
license: 0-clause bsd
```
# 2020, 2025
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
```
=> https://freesoftwareresistance.neocities.org