JavaScript in the browser : (yet another) bigint calculator toy language


I was curious to see how JavaScript in my various browser versions is performing lately in the case of both stack-greedy and numeric operations-intensive computations (well, or somehow).

So I made this small big integer-calculator toy language (three keywords only : const, print, and show) providing the usual four operations, the modulus (%), and four builtin functions: the square root (sqrt), the power (pow), the recursive factorial (fact) and a memoizing Fibonacci (fibo).

(the language isn't just a fluent interface hosted by JavaScript; it's parsed by an actual PEG-based parser I made after augmenting Chris Double's jsparse a bit for my needs.)

The results (timings) and differences observed are sometimes interesting.

1. the calculator also knows the first 20 Mersenne primes (consts M1 thru M20); e.g.:

show M20 ;

2. the semicolon is a statement terminator, not a separator
3. no parse error handling at all

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

(Updated with companion link

(Updated with companion link to a separate, simple demo of Hindley-Milner algorithm W, with 3 atomic types (bool, int, str), and in JS as well; inspired from B. McKenna's)

I was a bit surprised (*) to

I was a bit surprised (*) to notice that a rather straightforward, barely improving translation of this algorithm W PoC from JavaScript into its C# equivalent would actually end up being a little shorter :

217 lines of C# vs. 275 lines of the 1st shot at it in JavaScript (for the algorithm proper).

(*) not that much, really