This version works and seems to give the same results as BASIC.
It uses an old trick that I use to create easy string lists.
It was not as easy as I thought to RPN all those calculations. It really makes the point for the late Julian Noble's "FORmula TRANslator" (FORTRAN)
It was an evaluator that let you input infix equations and it spit out Forth.
This program also points out a sticky situation with Forth. There is no "standard" way to convert text to a number.
Every Forth has one but they seem to all have different names. CAMEL Forth uses ?NUMBER ( c$adr-- n flag) .
But without that , I can't make a truly portable "INPUT" statement to put this in a loop like the BASIC version.
I can do it, but it will probably not compile on other systems without some editing.
This compiles on CAMEL99 and gives correct results according to http://www.calculato...ay-of-week.html
DECIMAL : ," ( -- ) [CHAR] " WORD C@ 1+ ALLOT ALIGNED ; IMMEDIATE : [[ 0 C, ; : ]] [[ ; CREATE DAYS [[ ," SUN" ," MON" ," TUES" ," WEDNES" ," THURS" ," FRI" ," SATUR" ]] : NTH ( n adr -- adr') SWAP 0 ?DO COUNT + LOOP ; : DAY. ( n -- $adr ) 1+ DAYS NTH COUNT TYPE ." DAY" ; VARIABLE D VARIABLE M VARIABLE Y : INPUT ( d m y -- ) Y ! M ! D ! ; : (M-2)/12 ( -- n ) M @ 2- 12 / ; ( factored out of below) : YR ( -- ) Y @ (M-2)/12 + Y ! ; ( line 130 a) : MNTH ( -- ) M @ (M-2)/12 12 * - M ! ; ( line 130 b) : MAGIC ( -- n ) YR MNTH D @ M @ 2* + M @ 1+ 6 * 10 / + Y @ + Y @ 4 / + Y @ 100 / - Y @ 400 / + 1+ DUP 7 / 7 * - ; ( line 150) : DOW ( D M Y -- ) CR ." That's a " INPUT MAGIC DAY. ;
BUT! the same code on HsForth under Intel DOSBOX gives wrong results. In both cases I am using the machine's native divide instruction.
Is that the problem? No idea.
(I could not get it to compile on TurboForth because I don't know the equivalent to the ANS word ALIGNED)
Edited by TheBF, Thu Mar 23, 2017 7:30 AM.