by veltas · 3d ago · 0 comments
The object on top of the stack should be a Javascript value, numbers are all doubles, and you can use strings, arrays, objects-as-dicts and in fact ordinary objects you could write something like
>> {"a": [1, 2], "b": "hello" }
>> DUP
>> "a" GET{ 0 GET[
>> .
1
>> "something" "c" PUT{
>> .
{"a": [1, 2], "b": "hello", "c": "something" }
You could use all the metaprogramming tricks you use in other FORTHs, be able to do anything Javascript can do, I don't think it would be too hard to unpack the stack and turn a word that takes N parameters from the stack into a Javascript function the JS compiler can make fastThere is some precedent:
https://www.forth.org/svfig/kk/11-2019-O'Connor.pdf
I just realized there is exception handling in FORTH now
https://forth-standard.org/standard/exception
and wonder if that could be harmonized with JS exceptions
This strategy though competes with writing a Lisp which gives you better metaprogramming.