On 9/06/2025 12:41 am, LIT wrote:
0 VARIABLE FORMER...
0 VARIABLE PRESENT
HERE 73 C, 86 C, 88 C, 76 C, 67 C, 68 C, 77 C, \ I V X L C D M >> HERE 0 C, 1 C, 2 C, 10 C, 20 C, 100 C, 200 C,
Yep. Nothing better than FigForth :) How about ...
: CREATE 0 VARIABLE -2 ALLOT ;
Because conflicts can be avoided, there is no need to use a prefix
like your Or, so I do not use that. Here are some examples:
MCMXLVIII . \ 1948
mcmxlviii . \ error: undefined word
MIM \ error: undefined word
L . \ 50
LLL \ error: undefined word
MCMXLVIII LXXVII + . \ 2025
And here's the code: >------------------------------------------------------------------
0
value: rdigit-value
2value: rdigit-string
constant rdigit-size
: romandigit ( u "romandigit" -- )
, parse-name save-mem 2, ;
create romandigits
\ this table contains variants with 4 repetitions, you can comment
\ them out if desired
900 romandigit CM
500 romandigit D
400 romandigit CD
400 romandigit CCCC
300 romandigit CCC
200 romandigit CC
100 romandigit C
90 romandigit XC
50 romandigit L
40 romandigit XL
40 romandigit XXXX
30 romandigit XXX
20 romandigit XX
10 romandigit X
9 romandigit IX
5 romandigit V
4 romandigit IV
4 romandigit IIII
3 romandigit III
2 romandigit II
1 romandigit I
here constant end-romandigits
: roman>n? ( c-addr u -- n f )
\ if c-addr u contains a roman numeral, f is true and n is the value,
\ otherwise f is false.
dup >r 'M' skip r> over - 1000 *
romandigits case {: d: str1 n1 rd1 :}
rd1 end-romandigits = ?of n1 str1 nip 0= endof
str1 rd1 rdigit-string string-prefix? ?of
str1 rd1 rdigit-string nip /string
n1 rd1 rdigit-value +
rd1 rdigit-size + contof
str1 n1 rd1 rdigit-size + next-case ;
: rec-roman ( c-addr u -- n translate-num | 0 )
roman>n? if ['] translate-num else drop 0 then ;
' rec-roman action-of forth-recognize >stack
0
value: rdigit-value
2value: rdigit-string
constant rdigit-size
: romandigit ( u "romandigit" -- )[...]
, parse-name save-mem 2, ;
create romandigits
\ this table contains variants with 4 repetitions, you can comment
\ them out if desired
900 romandigit CM
500 romandigit D
400 romandigit CD
400 romandigit CCCC
300 romandigit CCC
200 romandigit CC
100 romandigit C
90 romandigit XC
50 romandigit L
40 romandigit XL
40 romandigit XXXX
30 romandigit XXX
20 romandigit XX
10 romandigit X
9 romandigit IX
5 romandigit V
4 romandigit IV
4 romandigit IIII
3 romandigit III
2 romandigit II
1 romandigit I
here constant end-romandigits
: roman>n? ( c-addr u -- n f )
\ if c-addr u contains a roman numeral, f is true and n is the value,
\ otherwise f is false.
dup >r 'M' skip r> over - 1000 *
romandigits case {: d: str1 n1 rd1 :}
rd1 end-romandigits = ?of n1 str1 nip 0= endof
str1 rd1 rdigit-string string-prefix? ?of
str1 rd1 rdigit-string nip /string
n1 rd1 rdigit-value +
rd1 rdigit-size + contof
str1 n1 rd1 rdigit-size + next-case ;
For ROMAN>N? I first tried an orthodox approach with data and return
stack only, and BEGIN etc., but with 4 stack items that have to be
updated possibly at every iteration that was somewhat unwieldy, and I >produced a buggy version. Then I tried this approach with the
extended CASE and locals, and I got it right on first try, despite its
bulk. I leave it to dxf to show how much better this becomes in
orthodox Forth.
AFAICS ITC presents no impediment to finding a credible solution
for FigForth's lack of a credible CREATE.
Yep. Nothing better than FigForth :) How about ...
: CREATE 0 VARIABLE -2 ALLOT ;
Actually CREATE wasn't needed here...
0 VARIABLE FORMER...
0 VARIABLE PRESENT
HERE 73 C, 86 C, 88 C, 76 C, 67 C, 68 C, 77 C, \ I V X L C D M
HERE 0 C, 1 C, 2 C, 10 C, 20 C, 100 C, 200 C,
Yep. Nothing better than FigForth :) How about ...
: CREATE 0 VARIABLE -2 ALLOT ;
Actually CREATE wasn't needed here...
Because conflicts can be avoided, there is no need to use a prefix
like your Or, so I do not use that. Here are some examples:
- anton
On 9/06/2025 2:23 am, LIT wrote:
I prefer ITC - the processors nowadays are so fast,
that DTC/STC aren't as much advantageous, as they
used to be — and I'm frequently tinkering with that
old fig-Forth I once found on forth.org pages. It's
fun. :)
AFAICS ITC presents no impediment to finding a credible solution
for FigForth's lack of a credible CREATE.
Yep. Nothing better than FigForth :) How about ...
: CREATE 0 VARIABLE -2 ALLOT ;
Actually CREATE wasn't needed here...
That's why I didn't use it.
I used LITERALs to avoid littering the
namespace with additional names, not
particularly needed to solve the task.
Word names are litter but hot patches and compiler-security
evasions are acceptable. Each day one learns something new
in Forth :)
Remember ciforth is actually fig.forth 5.5.1.
Word names are litter but hot patches and compiler-security
evasions are acceptable. Each day one learns something new
in Forth :)
No, no "hot patches"; I did that deliberately.
Noticed, that I need the limits only for
DO..LOOP - and for nothing more - then
conclusion was to use the numbers directly,
not naming them. Both lists are, in a way,
part of VAL word and (probably) won't be
used again by anothing else. So there wasn't
any need to name them.
In article <a281de112697213c8d16ce5eee1d08dbff2fb293@i2pn2.org>,
dxf <dxforth@gmail.com> wrote:
On 9/06/2025 2:23 am, LIT wrote:
I prefer ITC - the processors nowadays are so fast,
that DTC/STC aren't as much advantageous, as they
used to be — and I'm frequently tinkering with that
old fig-Forth I once found on forth.org pages. It's
fun. :)
AFAICS ITC presents no impediment to finding a credible solution
for FigForth's lack of a credible CREATE.
Remember ciforth is actually fig.forth 5.5.1.
<BUILDS DOES> is nearly as powerful as CREATE DOES>
I merely made vocabularies and <BUILDS DOES> iso standard .
I also introduced PREFIX.
(PREFIX is actually a two line addition to a properly designed Forth.)
I made more improvements but the above should be sufficient to reproduce
the example
in fig-Forth.
Groetjes Albert--
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 153:22:25 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
2,526 files (731M bytes) |
Messages: | 2,411,055 |