Hi 4tH-ers!
Well, the only connection between 4tH and uBasic/4tH is that the latter is written in 4tH. And you know how I went about. Use what you have and respect the original architecture. That mentality has kept 4tH maintainable for close to 30 years.
For uBasic I've thrown in a bit of C and Forth - which has resulted in a completely insane structure. Take a look at this Recaman sequence, which I wrote for Rosetta code.
a = 0
Print "First 15 numbers:"
For i = 1 Step 1
If i<16 Then Print a,
b = Iif ((a-i<1) + (Func(_Peek(Max(0, a-i))) = 1), a+i, a-i)
If Func(_Peek(b)) = 1) Then Print "\nFirst repetition: ";b : Break
Proc _Set(Set(a, b))
Next
End
_Set Param(1) : Let @(a@/32) = Func(_Poke(a@/32, a@%32)) : Return
_Poke Param(2) : Return (Or(@(a@), Shl(1, b@)))
_Peek Param(1) : Return (And(@(a@/32), Shl(1, a@%32))>0)
For the Recaman sequence you have to keep track which numbers you've already visited. I did that by turning uBasic's only array into a bitmap - which is serviced by the last three functions and subroutines. Oneliners, of course - are we Forthers or not?
The FOR statement is the first indication that this is not your mummies Basic, since it doesn't have a limit. It loops forever, but STEP makes sure it still counts up.
The assignment of variable "b" is another indication that something strange if going on. It is done by an IIF() statement, which evaluates if it renders a negative number -or- if it resides in the bitmap.
Now that might very well end up before the beginning of the bitmap (since it might render a negative value), so the Forth-like MAX() function clips it at ZERO.
At the end of the loop variable "a" is SET() to "b" and the value of "b" is passed to user-defined function _SET() to set the appropriate bit in the bitmap.
Although it doesn't fulfill the optional part of the Rosetta assignment, it's pretty short compared to other implementations. Even with comments it's less than 1K sourcecode.
I love it ;-)
Hans Bezemer