Backtrace:abort<<<
Backtrace:REVERSE<<<
Backtrace:REVERSE<<<
Backtrace:REVERSE<<<
Backtrace:REVERSE<<<
Hi all, trying to reverse order, I'm working of the stack although I will be using a file and buffer for the end result, I created what seem like the logical word defines as:
: REVERSE ( i*x i -- i*y ) 0 DO I DUP ROLL . LOOP ;
Here is the interactive successions ( or is that frustration :D )
At fist I was missing a character, then it all was weird...
Thoughts... I leave the interactive session for the enjoyment of the gurus! :D
.S <0> ok
0 1 2 3 4 5 6 7 8 9 ok
.S <10> 1 2 3 4 5 6 7 8 9 ok
: REVERSE ( i*x i -- i*y ) 0 DO I DUP ROLL . LOOP ; redefined REVERSE ok REVERSE 0 8 7 6 5 4 3 2 1 ok
.s <9> 0 1 2 3 4 5 6 7 8 ok
: REVERSE ( i*x i -- i*y ) 0 DO I DUP ROLL . DROP LOOP ; redefined REVERSE ok
abort
:148: Aborted
Backtrace:abort<<<
$7F8B79A03A78 throw
.S <0> ok
0 1 2 3 4 5 6 7 8 9 ok
.S <10> 1 2 3 4 5 6 7 8 9 ok
REVERSE 0 7 5 3 1
:152: Stack underflow
Backtrace:REVERSE<<<
$7F8B79A031D0 swap
$7F8B79A031C0 roll
$2
$7F8B79A031C0 roll
$4
$7F8B79A031C0 roll
$6
$7F8B79A031C0 roll
$5
$7F8B79A57178 roll
$5
$9
: REVERSE ( i*x i -- i*y ) 0 DO I ROLL . LOOP ; redefined REVERSE ok
.S <0> ok
0 1 2 3 4 5 6 7 8 9 ok
REVERSE 8 6 4 2 0
:156: Stack underflow
Backtrace:REVERSE<<<
$7F8B79A031A0 swap
$7F8B79A031C0 roll
$1
$7F8B79A031C0 roll
$3
$7F8B79A031C0 roll
$5
$7F8B79A031C0 roll
$7
$7F8B79A57208 roll
$5
$9
.S <0> ok
ok
ok
ok
0 1 2 3 4 5 6 7 8 9 ok
REVERSE 8 6 4 2 0
:162: Stack underflow
Backtrace:REVERSE<<<
$7F8B79A031A0 swap
$7F8B79A031C0 roll
$1
$7F8B79A031C0 roll
$3
$7F8B79A031C0 roll
$5
$7F8B79A031C0 roll
$7
$7F8B79A57208 roll
$5
$9
: REVERSE ( i*x i -- i*y ) 0 DO I DUP ROLL . DROP LOOP ; redefined REVERSE ok
ok
ok
0 1 2 3 4 5 6 7 8 9 ok
REVERSE 0 7 5 3 1
:167: Stack underflow
Backtrace:REVERSE<<<
$7F8B79A031D0 swap
$7F8B79A031C0 roll
$2
$7F8B79A031C0 roll
$4
$7F8B79A031C0 roll
$6
$7F8B79A031C0 roll
$5
$7F8B79A57298 roll
$5
$9
ok
ok
ok
ok
bye
clearstack okWell,
ok
ok
0 1 2 3 4 5 6 7 8 9 \ last is 9 ok 10
. 9 ok 9
: rev depth 0 do I roll loop ; ok 9
rev ok 9
\ should go 0 1 2 .. ok 9
. . . . 0 1 2 3 ok 5
0 do here i cells - @ loopdepth cells negate allot
: revs
depth >r
depth cells allot
depth 0 do here i cells - ! loop
0 do here i cells - @ loopdepth cells negate allot
;
I just tried it, it is the same as my initial issue, it misses the "9" on the stack....: revsOh, but actually why allocating anything for that brief moment?
depth >r
depth cells allot
depth 0 do here i cells - ! loop
0 do here i cells - @ loopdepth cells negate allot
;
It can be shorter:
: reverse-stack ( -- )
depth dup >r 0 do here i cells + ! loop
0 do here i cells + @ loop ;
0 do here i cells + @ loop ; ok0 1 2 3 4 5 6 7 8 9 ok
On Thursday, August 24, 2023 at 4:05:43 PM UTC+2, Zbig wrote:
: revsOh, but actually why allocating anything for that brief moment?
depth >r
depth cells allot
depth 0 do here i cells - ! loop
0 do here i cells - @ loopdepth cells negate allot
;
It can be shorter:
: reverse-stack ( -- )I just tried it, it is the same as my initial issue, it misses the "9" on the stack....
depth dup >r 0 do here i cells + ! loop
0 do here i cells + @ loop ;
: reverse-stack ( -- ) compiled
depth dup >r 0 do here i cells + ! loop compiled
0 do here i cells + @ loop ; ok0 1 2 3 4 5 6 7 8 9 ok
reverse-stack ok
.S <10> 8 7 6 5 4 3 2 1 0 ok
On Thursday, August 24, 2023 at 5:45:04 PM UTC+2, Zbig wrote:
If your compiler uses the return stack as an actual return stack, you can try this:
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `help' for basic help
: reverse begin dup while 1- swap r> swap >r >r repeat drop ; ok
: test 1 2 3 4 5 6 6 reverse r> . r> . r> . r> . r> . r> . ; ok
ok
test 1 2 3 4 5 6 ok
„Houston…”
nine „highest” values from the stack. You didn't notice „ten” in triangles directly before value list? It displays the stack's depth.Really? Man, the rat holes I have been trough... I did not know that...
czwartek, 24 sierpnia 2023 o 17:29:38 UTC+2 SpainHackForth napisał(a):Really? Man, the rat holes I have been trough... I did not know that...
On Thursday, August 24, 2023 at 4:05:43 PM UTC+2, Zbig wrote:
: revsOh, but actually why allocating anything for that brief moment?
depth >r
depth cells allot
depth 0 do here i cells - ! loop
0 do here i cells - @ loopdepth cells negate allot
;
It can be shorter:
: reverse-stack ( -- )I just tried it, it is the same as my initial issue, it misses the "9" on the stack....
depth dup >r 0 do here i cells + ! loop
0 do here i cells + @ loop ;
: reverse-stack ( -- ) compiledIt doesn't missing anything; Gforth displays just the nine
depth dup >r 0 do here i cells + ! loop compiled
0 do here i cells + @ loop ; ok0 1 2 3 4 5 6 7 8 9 ok
reverse-stack ok
.S <10> 8 7 6 5 4 3 2 1 0 ok
„highest” values from the stack. You didn't notice „ten” in triangles directly before value list? It displays the stack's depth.
Really? Man, the rat holes I have been trough... I did not know that...
On Thursday, August 24, 2023 at 5:45:04 PM UTC+2, Zbig wrote:
czwartek, 24 sierpnia 2023 o 17:29:38 UTC+2 SpainHackForth napisał(a):Really? Man, the rat holes I have been trough... I did not know that...
On Thursday, August 24, 2023 at 4:05:43 PM UTC+2, Zbig wrote:It doesn't missing anything; Gforth displays just the nine
I just tried it, it is the same as my initial issue, it misses the "9" on the stack....: revsOh, but actually why allocating anything for that brief moment?
depth >r
depth cells allot
depth 0 do here i cells - ! loop
0 do here i cells - @ loopdepth cells negate allot
;
It can be shorter:
: reverse-stack ( -- )
depth dup >r 0 do here i cells + ! loop
0 do here i cells + @ loop ;
: reverse-stack ( -- ) compiled
depth dup >r 0 do here i cells + ! loop compiled
0 do here i cells + @ loop ; ok0 1 2 3 4 5 6 7 8 9 ok
reverse-stack ok
.S <10> 8 7 6 5 4 3 2 1 0 ok
„highest” values from the stack. You didn't notice „ten” in
triangles directly before value list? It displays the stack's depth.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 55:29:42 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,397 |