• Re: convenient stack operation: a b c -- b a c

    From mhx@mhx@iae.nl (mhx) to comp.lang.forth on Sun Apr 14 15:23:52 2024
    From Newsgroup: comp.lang.forth

    dxf wrote:

    On 1/12/2023 9:04 pm, albert wrote:
    In article <ukalqa$1fmfg$1@dont-email.me>,
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
    I'm in need of a convenient way to do the following for the fp stack,
    but we can pose the problem for the data stack:
    [..]
    The presence of ROT SWAP ought to raise a red flag as it suggests
    something is awry. After examining the code we may conclude its
    use in this case was the least worst option.

    I can only find it 50 times in 1352 files. It seems to pop up
    when there are 3 strong-coupled parameters for a certain operation
    (like your MOVE).

    The classic HANOI demo uses it:

    hanoi.frt(53): -rot swap r@ 1- recurse \ extra dest source N-1
    hanoi.frt(55): -rot swap r>
    hanoi.frt(87): >r -rot swap r> 1- recurse exit \ extra dest source N-1 hanoi.frt(359): -ROT SWAP R@ 1- RECURSE \ EXTRA DEST SOURCE n-1 hanoi.frt(361): -ROT SWAP R>
    hanoi.frt(375): >R -ROT SWAP R> 1- RECURSE \ EXTRA DEST SOURCE n-1 hanoi.frt(507): . -ROT SWAP R@ 1- RECURSE \ EXTRA DEST SOURCE n-1 hanoi.frt(509): . -ROT SWAP R>

    The TAK test has the same coupling problem:

    tak.frt(8): : tak2 ( x y z -- y1- z x ) swap 1- -rot swap ;

    This classic utility (almost) mirrors your example:

    blocks\editor.frt(109): -ROT SWAP CMOVE

    Classic integer FFT

    numeric\fft.frt(22): : X- ROT SWAP - -ROT - SWAP ; ( cplx1 cplx2 -- cplx3 )

    Somebody remembers SOD64 ?

    sod64\kernel.frt(236): R> ROT ROT SWAP >R >R >R ;
    sod64\kernel.frt(240): OVER OVER - IF R> ROT ROT SWAP >R >R 8 + >R sod64\kernel.frt(814): 1+ ROT ROT SWAP 1- SWAP
    sod64\kernel.frt(825): 1+ ROT ROT SWAP 1- SWAP

    Too low a frequency to make it a new word (and then having to look it up).

    -marcel
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Hans Bezemer@the.beez.speaks@gmail.com to comp.lang.forth on Sun Apr 21 15:51:18 2024
    From Newsgroup: comp.lang.forth

    On 14-04-2024 17:23, mhx wrote:
    I can only find it 50 times in 1352 files. It seems to pop up
    when there are 3 strong-coupled parameters for a certain operation
    (like your MOVE).

    Same thing here -even lower- about 20 times in 900 files. Curiously, 25%
    of them as a part of "-rot swap". With that frequency, I see little use
    of adding a word like "RISE". As a metaphor for certain stack
    operations, I don't think it's very compelling.

    I mean - a stack operator is like telling a story:
    - drop the 2OS item;
    - duplicate 2OS to 2OS;
    - duplicate TOS to 3OS;
    - swap 3OS with TOS.

    I can all easily imagine uses for that. "SWAP 3OS with 2OS" isn't
    telling me such a story. Sorry.

    Hans Bezemer

    --- Synchronet 3.20a-Linux NewsLink 1.114