Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #59930 > unrolled thread
| Started by | admin@simple.gopher |
|---|---|
| First post | 2017-05-27 17:03 +0000 |
| Last post | 2017-05-27 21:10 +0200 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.forth
pforth return stack strangeness admin@simple.gopher - 2017-05-27 17:03 +0000
Re: pforth return stack strangeness Julian Fondren <julian.fondren@gmail.com> - 2017-05-27 10:22 -0700
Re: pforth return stack strangeness admin@simple.gopher - 2017-05-27 19:15 +0000
Re: pforth return stack strangeness Julian Fondren <julian.fondren@gmail.com> - 2017-05-27 12:37 -0700
Re: pforth return stack strangeness Roelf Toxopeus <rt4all@nothishetnet.nl> - 2017-05-27 21:10 +0200
| From | admin@simple.gopher |
|---|---|
| Date | 2017-05-27 17:03 +0000 |
| Subject | pforth return stack strangeness |
| Message-ID | <ogcbht$10da$1@gioia.aioe.org> |
Maybe there are some pforth users here..
QUADRATIC example from page 112 in Starting Forth book:
% pforth
/ compute a * X^2 + b * X + c
: QUAD ( a b c X -- n) >R SWAP ROT I * + R> * + ; ok
2 7 9 3 QUAD . ==> 30 ok
The answer should be 48. TRACE suggests stuff is getting drop/corrupted:
2 7 9 3 TRACE QUAD .
<< QUAD +0 <10:4> 2 7 9 3 || >R >> 3 ok
s
<< QUAD +4 <10:2> 2 7 || SWAP >> ok
s
<< QUAD +8 <10:2> 7 2 || ROT >> ok
s
<< QUAD +12 <10:2> 2 0 || I >> ok
s
<< QUAD +16 <10:3> 2 0 1515870810 || * >> ok
s
<< QUAD +20 <10:2> 2 0 || + >> ok
s
<< QUAD +24 <10:1> 2 || R> >> ok
s
<< QUAD +28 <10:2> 2 9 || * >> ok
s
<< QUAD +32 <10:1> 18 || + >> ok
s
<< QUAD +36 <10:0> || EXIT >> ok
s Finished.
ok
For reference, same thing in gforth:
% gforth -e ": quad >r swap rot i * + r> * + ; 2 7 9 3 quad . bye"
48
pforth documentation doesn't suggest limited return stack functionality; not
sure why it doesn't work..
[toc] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2017-05-27 10:22 -0700 |
| Message-ID | <594c406f-a82d-4fbb-beeb-e2760a98641d@googlegroups.com> |
| In reply to | #59930 |
On Saturday, May 27, 2017 at 12:04:00 PM UTC-5, ad...@simple.gopher wrote: > Maybe there are some pforth users here.. > > QUADRATIC example from page 112 in Starting Forth book: > % pforth > / compute a * X^2 + b * X + c > : QUAD ( a b c X -- n) >R SWAP ROT I * + R> * + ; ok > 2 7 9 3 QUAD . ==> 30 ok > > The answer should be 48. The answer's also wrong under SwiftForth. You can get the intended answer under both by accessing the top of the return stack with R@ , rather than I : $ ./pforth_standalone PForth V27-LE/64, built May 27 2017 12:18:53 (static) : quad >r swap rot r@ * + r> * + ; 2 7 9 3 quad . 48 ok Stack<10>
[toc] | [prev] | [next] | [standalone]
| From | admin@simple.gopher |
|---|---|
| Date | 2017-05-27 19:15 +0000 |
| Message-ID | <ogcj8p$1egr$1@gioia.aioe.org> |
| In reply to | #59932 |
>On Saturday, May 27, 2017 at 12:04:00 PM UTC-5, ad...@simple.gopher wrote: >> Maybe there are some pforth users here.. >> >> QUADRATIC example from page 112 in Starting Forth book: >> % pforth >> / compute a * X^2 + b * X + c >> : QUAD ( a b c X -- n) >R SWAP ROT I * + R> * + ; ok >> 2 7 9 3 QUAD . ==> 30 ok >> >> The answer should be 48. > >The answer's also wrong under SwiftForth. > >You can get the intended answer under both by accessing the top >of the return stack with R@ , rather than I : > > $ ./pforth_standalone > PForth V27-LE/64, built May 27 2017 12:18:53 (static) > > : quad >r swap rot r@ * + r> * + ; 2 7 9 3 quad . 48 ok > Stack<10> Hey nice! Seems to also work with 'ff'[1] forth: % echo ": quad >r swap rot r@ * + r> * + ; 2 7 9 3 quad . cr bye" | ff ok 48 Thanks ; it was probably a very novice question.. J. [1] http://bitbucket.org/bunny351/ff
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2017-05-27 12:37 -0700 |
| Message-ID | <958f1dd5-41b4-49e9-ae72-12b34dce6d4d@googlegroups.com> |
| In reply to | #59943 |
On Saturday, May 27, 2017 at 2:15:40 PM UTC-5, ad...@simple.gopher wrote:
> Hey nice! Seems to also work with 'ff'[1] forth:
>
> % echo ": quad >r swap rot r@ * + r> * + ; 2 7 9 3 quad . cr bye" | ff
> ok
> 48
Neat, don't think I've seen this one.
README:
`2nip ( x y -- y )`
Drops the 2nd item on the stack.
README (later):
2nip ( x y z -- z )
core.f:
: 2nip ( x y z q -- z q ) rot drop rot drop ;
At least the implementation does what I'd expect :p
>
> Thanks ; it was probably a very novice question..
>
don't sweat it. First the code in the book is rotting a bit and this
is a natural question to have about it. Second, there aren't so many
novice questions around here that people are having to ask for
directions to the loony threads.
[toc] | [prev] | [next] | [standalone]
| From | Roelf Toxopeus <rt4all@nothishetnet.nl> |
|---|---|
| Date | 2017-05-27 21:10 +0200 |
| Message-ID | <5929cf31$0$1578$e4fe514c@textnews.kpn.nl> |
| In reply to | #59930 |
On 27/05/17 19:03, admin@simple.gopher wrote: > Maybe there are some pforth users here.. > > QUADRATIC example from page 112 in Starting Forth book: % pforth / > compute a * X^2 + b * X + c : QUAD ( a b c X -- n) >R SWAP ROT I * + > R> * + ; ok 2 7 9 3 QUAD . ==> 30 ok > > The answer should be 48. TRACE suggests stuff is getting > drop/corrupted: > > 2 7 9 3 TRACE QUAD . << QUAD +0 <10:4> 2 7 9 3 || >R > >> 3 ok s << QUAD +4 <10:2> 2 7 || SWAP > >> ok s << QUAD +8 <10:2> 7 2 || ROT > >> ok s << QUAD +12 <10:2> 2 0 || I > >> ok s << QUAD +16 <10:3> 2 0 1515870810 || * > >> ok s << QUAD +20 <10:2> 2 0 || + > >> ok s << QUAD +24 <10:1> 2 || R> > >> ok s << QUAD +28 <10:2> 2 9 || * > >> ok s << QUAD +32 <10:1> 18 || + > >> ok s << QUAD +36 <10:0> || EXIT > >> ok s Finished. ok > > For reference, same thing in gforth: % gforth -e ": quad >r swap rot > i * + r> * + ; 2 7 9 3 quad . bye" 48 > > pforth documentation doesn't suggest limited return stack > functionality; not sure why it doesn't work.. > It's like Julian said, use R@ instead of I. Has to do with loop implementation strategies (and standards). Use I as the current index for the innermost loop. Use R@ to copy the top of the return stack to data stack. Both the second Starting Forth edition (p.100) and the online version use R@ (it's now also called QUADRATIC). : QUADRATIC ( a b c x -- n ) >R SWAP ROT R@ * + R> * + ; In case you run into more issues using the first edition and whatever Forth, you could consult/try the online updated version: http://home.iae.nl/users/mhx/sf.html https://www.forth.com/starting-forth/ or just ask here of course.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web