55 ARRAY RND DOES> SWAP 1- CELLS + ; ( 55 RANDOM NRS IN RND )
Well, from the posting's comments one might think it is a truthful
copy of the code in the original paper, for 16-bit Forth79.
Assuming William Boyle did not have a 64-bit Forth79 compiler,
"314159296" and "1000000000" differ from the original critical
constants. This makes it doubtful the generator has the
statistical properties Knuth intended. (Given that William
Boyd converted Knuth's Fortran code correctly! Was there ever
a Fortran with a 16-bit integer RND function?)
On Wednesday, November 8, 2023 at 2:02:32 PM UTC+1, minforth wrote:
Hans Bezemer wrote:
55 ARRAY RND DOES> SWAP 1- CELLS + ; ( 55 RANDOM NRS IN RND )This DOES> must either have defined interpretation semantics
or something else is missing here...
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `help' for basic help
: array create cells allot ; ok
55 ARRAY RND DOES> SWAP 1- CELLS + ; ok
25 1 rnd ! ok
Works fine.. As Bernd said "It's trivial to add interpretation semantics.. So why not?"
But if you're happier with ": ARRAY CREATE CELLS ALLOT DOES> SWAP 1- CELLS + ;"
then go for it. I told you: "some assembly required"..
I like my interpretative DO..LOOP or better FOR..NEXT as well.
On 9/11/2023 3:58 am, minforth wrote:Since everything in 4tH is compiled, you can do:
I like my interpretative DO..LOOP or better FOR..NEXT as well.What is that?
On Thursday, November 9, 2023 at 11:42:14 PM UTC+1, dxf wrote:
On 9/11/2023 3:58 am, minforth wrote:Since everything in 4tH is compiled, you can do:
What is that?
I like my interpretative DO..LOOP or better FOR..NEXT as well.
20 0 ?DO I . LOOP
*outside* of a definition. I've also seen Forths that have [DO] and [LOOP]
as interpreted equivalents. I suppose you could embed those within a regular >DO..LOOP in order to create "interpretative DO..LOOP".
In 4tH code like:
10 0 DO variable i LOOP
doesn't create a bunch of variables. As a matter of fact, it will not compile >because "I" as a name is taken. You could do that in the preprocessor though, >although the code to achieve this will not look like this - at all.
I suppose you could do something like:
10 0 [DO] variable var i & [LOOP]
in an interpreted version .. but here I'm just guessing.
Hans Bezemer
[..]
After (in ciforth)
WANT -scripting-
you can do *all* control construct in interpreter mode.
(It is implicit in the -s option, for scripting)
T] and T[ switch to a temporary compile area. It is typically 4 Gbyte
away in a 8 Gbyte Forth, but beware of large buffers. (The same
mechanism is used for classes.)
Then it is one screen worth of definitions:
--------------------------------------------
"T]" WANTED
: IF T] POSTPONE IF ; IMMEDIATE
: DO T] POSTPONE DO ; IMMEDIATE
: ?DO T] POSTPONE ?DO ; IMMEDIATE
: BEGIN T] POSTPONE BEGIN ; IMMEDIATE
: THEN POSTPONE THEN POSTPONE T[ ; IMMEDIATE
: LOOP POSTPONE LOOP POSTPONE T[ ; IMMEDIATE
: +LOOP POSTPONE +LOOP POSTPONE T[ ; IMMEDIATE
: REPEAT POSTPONE REPEAT POSTPONE T[ ; IMMEDIATE
: UNTIL POSTPONE UNTIL POSTPONE T[ ; IMMEDIATE
: AGAIN POSTPONE AGAIN POSTPONE T[ ; IMMEDIATE --------------------------------------------
It is insane to mint different words for this behaviour.
T] and T[ is left as an exercise. Hint: they are state-smart.
On 10/11/2023 9:37 pm, albert wrote:
[..]
After (in ciforth)
WANT -scripting-
you can do *all* control construct in interpreter mode.
(It is implicit in the -s option, for scripting)
T] and T[ switch to a temporary compile area. It is typically 4 Gbyte
away in a 8 Gbyte Forth, but beware of large buffers. (The same
mechanism is used for classes.)
Then it is one screen worth of definitions:
--------------------------------------------
"T]" WANTED
: IF T] POSTPONE IF ; IMMEDIATE
: DO T] POSTPONE DO ; IMMEDIATE
: ?DO T] POSTPONE ?DO ; IMMEDIATE
: BEGIN T] POSTPONE BEGIN ; IMMEDIATE
: THEN POSTPONE THEN POSTPONE T[ ; IMMEDIATE
: LOOP POSTPONE LOOP POSTPONE T[ ; IMMEDIATE
: +LOOP POSTPONE +LOOP POSTPONE T[ ; IMMEDIATE
: REPEAT POSTPONE REPEAT POSTPONE T[ ; IMMEDIATE
: UNTIL POSTPONE UNTIL POSTPONE T[ ; IMMEDIATE
: AGAIN POSTPONE AGAIN POSTPONE T[ ; IMMEDIATE
--------------------------------------------
It is insane to mint different words for this behaviour.
T] and T[ is left as an exercise. Hint: they are state-smart.
Do you have some examples? I'm still puzzled what these have over the >regular functions.
In article <uil4i4$2q6cm$1@dont-email.me>, dxf <dxforth@gmail.com> wrote:
On 10/11/2023 9:37 pm, albert wrote:
[..]
After (in ciforth)
WANT -scripting-
you can do *all* control construct in interpreter mode.
(It is implicit in the -s option, for scripting)
T] and T[ switch to a temporary compile area. It is typically 4 Gbyte
away in a 8 Gbyte Forth, but beware of large buffers. (The same
mechanism is used for classes.)
Then it is one screen worth of definitions:
--------------------------------------------
"T]" WANTED
: IF T] POSTPONE IF ; IMMEDIATE
: DO T] POSTPONE DO ; IMMEDIATE
: ?DO T] POSTPONE ?DO ; IMMEDIATE
: BEGIN T] POSTPONE BEGIN ; IMMEDIATE
: THEN POSTPONE THEN POSTPONE T[ ; IMMEDIATE
: LOOP POSTPONE LOOP POSTPONE T[ ; IMMEDIATE
: +LOOP POSTPONE +LOOP POSTPONE T[ ; IMMEDIATE
: REPEAT POSTPONE REPEAT POSTPONE T[ ; IMMEDIATE
: UNTIL POSTPONE UNTIL POSTPONE T[ ; IMMEDIATE
: AGAIN POSTPONE AGAIN POSTPONE T[ ; IMMEDIATE
--------------------------------------------
It is insane to mint different words for this behaviour.
T] and T[ is left as an exercise. Hint: they are state-smart.
Do you have some examples? I'm still puzzled what these have over the
regular functions.
A typical example is
( CRC64 ) CF: ?64 \ AvdH C2feb27
"BOUNDS" WANTED "-scripting-" WANTED HEX
\ Well the polynomial
C96C,5795,D787,0F42 CONSTANT CRC64_POLYNOMIAL \ ECMA-182
\ Auxiliary table with values for single bytes.
CREATE CRCTable
100 0 DO I 8 0 DO
DUP >R 1 RSHIFT R> 1 AND IF CRC64_POLYNOMIAL XOR THEN
LOOP , LOOP
\ For initial CRC and BUFFER COUNT pair, leave the updated CRC
: CRC-MORE BOUNDS ?DO DUP I C@ XOR 0FF AND CELLS CRCTable + @
SWAP 8 RSHIFT XOR LOOP ;
\ For BUFFER COUNT pair, leave the CRC .
: CRC64 -1 ROT ROT CRC-MORE INVERT ;
DECIMAL
------------------
Building the crc table you need not worry about a temp definition
and whether its code land in the middle of the table you want to
define. Also there is no entry in the dictionary that you never
want to use again.
Maybe it is useful to someone. It seems to work just fine. I have no Forth-79 compiler to verify it.
: ARRAY CELLS ALLOT ;
I think it's quite obvious but anyways. The curious part is that the author seems to prefer 1-indexed arrays instead of 0-indexed ones.
Hans Bezemer
A Portable FORTH Random Number Generator, William T. Doyle
The Journal of Forth Application and Research Vol. I. Number 2. Dec. 1983
When seeded with the word RND.INIT the sequences produced are identical
to those produced by Knuth's FORTRAN subroutine with the same seed and
number range.
ANS conversion by Hans Bezemer, 2023
Converted to a single word version
VARIABLE (RND) HERE (RND) ! ( dummy seed must not be zero )
VARIABLE (RND) HERE (RND) ! ( dummy seed must not be zero )
This will 'sporadically" fail on a transputer (signed addresses).
-marcel--
VARIABLE (RND) HERE (RND) ! ( dummy seed must not be zero )
This will 'sporadically" fail on a transputer (signed addresses).
This will 'sporadically" fail on a transputer (signed addresses).
Easily fixed :
VARIABLE (RND) HERE 1+ (RND) ! ( dummy seed must not be zero )
On 5/12/2023 10:04 pm, mhx wrote:
VARIABLE (RND) HERE (RND) ! ( dummy seed must not be zero )
This will 'sporadically" fail on a transputer (signed addresses).
Presumably @EXECUTE and all routines that treat address 0 as a special
case would be problematic too? Perhaps it's a good thing transputers
are a forgotten technology remembered only by OT forthers :)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 504 |
Nodes: | 16 (2 / 14) |
Uptime: | 16:50:14 |
Calls: | 9,904 |
Files: | 13,797 |
Messages: | 6,344,986 |