Digest #180 2022-04-06

Contributions

[232] 2022-04-05 14:05:53 JimPeterson wrote:

referenceImplementation - Possible Reference Implementation

Would the following be a viable reference implementation?

: VARIABLE ALIGN HERE 0 , CONSTANT ;

Of course... this initializes the contents, and you might not want to imply that such is required in an implementation. So maybe this more verbose definition:?

: VARIABLE ALIGN HERE 1 CELLS ALLOT CONSTANT ;

[233] 2022-04-05 14:43:43 JimPeterson wrote:

referenceImplementation - Possible Reference Implementation

I'm not sure of the value of reference implementations for such simple words, but here's one:

: MIN 2DUP < IF DROP EXIT THEN NIP ;

... there's also an equivalent for MAX:

: MAX 2DUP < IF NIP EXIT THEN DROP ;

But hen, NIP is in CORE-EXT, and providing a reference for a CORE word that uses words from CORE-EXT may seem invalid, so would these be more preferred?:

: MIN 2DUP > IF SWAP THEN DROP ;
: MAX 2DUP < IF SWAP THEN DROP ;

[234] 2022-04-05 17:44:08 JimPeterson wrote:

example - Possible Reference Implementation

Just taking a stab at this:

: ALIGN HERE ALIGNED HERE - ALLOT ;

Replies

[r814] 2022-04-05 07:21:20 AntonErtl replies:

requestClarification - Double>

$7FFFFFFFFFFFFFFF 1 lshift produces $FFFFFFFFFFFFFFFE (on a 64-bit system).

$7FFFFFFFFFFFFFFF 1 lshift 0 produces $FFFFFFFFFFFFFFFE 0.

I.e., the right side of the test case produces the values that you correctly identified as correct answer.


[r815] 2022-04-05 12:53:09 AdrianMcMenamin replies:

requestClarification - Double>

Thank you for the clarification but can I suggest that, if at all possible, the formatting of the test answer is changed? It looks very much like there are two groups here and the second is "1 LSHIFT 0" which obviously makes no sense as Forth but which I assumed meant 1 shifted left by zero (ie 1). Perhaps that is my mistake, but the formatting encouraged me in it.


[r816] 2022-04-05 15:03:31 JimPeterson replies:

referenceImplementation - Suggested reference implementation

With DECIMAL, you could:

BASE @ DECIMAL : HEX 16 BASE ! ; BASE !

... but then it's difficult to define DECIMAL (without HEX or BIN).

The best I could come up with for the entire set is:

BASE @        \ remember it ...
1 2* BASE !   \ get to binary

: BIN        10 BASE ! ;
: DECIMAL  1010 BASE ! ;
: HEX     10000 BASE ! ;

BASE !        \ ... and restore it