Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #135557
| Date | 2026-09-05 02:59 +1000 |
|---|---|
| Subject | Re: dynamic scoping in Forth in one line of code (was Re: coroutines) |
| Newsgroups | comp.lang.forth |
| References | (4 earlier) <875x0oa6fy.fsf@debian> <87ecfcld9r.fsf@nightsong.com> <87mrtxzz0p.fsf_-_@debian> <6a9a560f$1@news.ausics.net> <87ik4l6m11.fsf_-_@debian> |
| From | dxf <dxforth@gmail.com> |
| Message-ID | <6a9af8f3$1@news.ausics.net> (permalink) |
| Organization | Ausics - https://newsgroups.ausics.net |
On 5/09/2026 2:04 am, Kragen Javier Sitaker wrote: > dxf <dxforth@gmail.com> writes: >> I'm more pragmatist, so if it solves an existing problem then I'm interested. >> For years I knew how to 'localize' variables. But it was all done manually. >> When Albert and Hans showed me how to implement it simply and with auto-restore, >> it made my day. >> >> : ;: >r ; >> >> : LOCAL ( x adr -- ) r> -rot dup @ over 2>r ! ;: 2r> ! ; >> >> \\ Example >> variable A variable B 8 a ! 7 b ! >> >> : divide ( a b -- ) >> b local a local a @ b @ / . cr ; >> >> 15 3 divide a ? b ? >> >> I use it where re-entrancy is required. While I have loadable 'real' locals, >> I hardy bother as this is simpler. > > This seems to provide exactly the same dynamic-scoping functionality as > the `let!` I posted, but with a simpler implementation! > > How would you extend it to support `throw`? I've yet to need it but pushing locals requiring preserving to the return stack before the CATCH and popping them after should do it. It's additional overhead so only on a case by case basis.
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
dynamic scoping in Forth in one line of code Kragen Javier Sitaker <kragen@canonical.org> - 2026-08-28 18:04 -0300
Re: dynamic scoping in Forth in one line of code Paul Rubin <no.email@nospam.invalid> - 2026-08-28 18:12 -0700
Re: dynamic scoping in Forth in one line of code Kragen Javier Sitaker <kragen@canonical.org> - 2026-08-29 10:50 -0300
Re: dynamic scoping in Forth in one line of code albert@spenarnc.xs4all.nl - 2026-08-29 12:10 +0200
Re: dynamic scoping in Forth in one line of code Kragen Javier Sitaker <kragen@canonical.org> - 2026-08-29 11:17 -0300
Re: dynamic scoping in Forth in one line of code albert@spenarnc.xs4all.nl - 2026-08-30 12:49 +0200
Re: dynamic scoping in Forth in one line of code Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-01 20:38 -0300
Re: dynamic scoping in Forth in one line of code Paul Rubin <no.email@nospam.invalid> - 2026-09-01 17:15 -0700
coroutines (was Re: dynamic scoping in Forth in one line of code) Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-03 20:38 -0300
Re: coroutines (was Re: dynamic scoping in Forth in one line of code) dxf <dxforth@gmail.com> - 2026-09-04 15:24 +1000
dynamic scoping in Forth in one line of code (was Re: coroutines) Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-04 13:04 -0300
Re: dynamic scoping in Forth in one line of code (was Re: coroutines) dxf <dxforth@gmail.com> - 2026-09-05 02:59 +1000
csiph-web