Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #19387 > unrolled thread
| Started by | AKE <assadebrahim2000@gmail.com> |
|---|---|
| First post | 2013-02-03 06:18 -0800 |
| Last post | 2013-02-05 18:08 +0200 |
| Articles | 17 — 11 participants |
Back to article view | Back to comp.lang.forth
On-the-fly updating of word definitions? AKE <assadebrahim2000@gmail.com> - 2013-02-03 06:18 -0800
Re: On-the-fly updating of word definitions? Mark Wills <forthfreak@gmail.com> - 2013-02-03 07:15 -0800
Re: On-the-fly updating of word definitions? AKE <assadebrahim2000@gmail.com> - 2013-02-03 07:25 -0800
Re: On-the-fly updating of word definitions? Bruno Gauthier <bgauthier@free.fr> - 2013-02-03 16:24 +0100
Re: On-the-fly updating of word definitions? AKE <assadebrahim2000@gmail.com> - 2013-02-03 07:33 -0800
Re: On-the-fly updating of word definitions? Mark Wills <forthfreak@gmail.com> - 2013-02-03 09:27 -0800
Re: On-the-fly updating of word definitions? Paul Rubin <no.email@nospam.invalid> - 2013-02-03 07:34 -0800
Re: On-the-fly updating of word definitions? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-03 10:32 -0600
Re: On-the-fly updating of word definitions? "Elizabeth D. Rather" <erather@forth.com> - 2013-02-03 08:44 -1000
Re: On-the-fly updating of word definitions? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-04 16:07 +0000
Re: On-the-fly updating of word definitions? Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-02-04 17:27 -0800
Re: On-the-fly updating of word definitions? Mark Wills <forthfreak@gmail.com> - 2013-02-04 23:57 -0800
ACTION-OF (was: On-the-fly updating of word definitions?) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-05 11:45 +0000
Re: On-the-fly updating of word definitions? stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-05 12:58 +0000
Re: On-the-fly updating of word definitions? Mark Wills <forthfreak@gmail.com> - 2013-02-05 05:20 -0800
Re: On-the-fly updating of word definitions? Lars Brinkhoff <lars.spam@nocrew.org> - 2013-02-05 09:22 +0100
Re: On-the-fly updating of word definitions? mhx@iae.nl (Marcel Hendrix) - 2013-02-05 18:08 +0200
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-02-03 06:18 -0800 |
| Subject | On-the-fly updating of word definitions? |
| Message-ID | <f4412dce-5396-42ce-8c87-0a6c7ab6f6f4@googlegroups.com> |
Hi: One of the strong points of Forth is continuous refactoring. But if a low level word, then it seems that all of the higher words that use the lower level word need to be resubmitted to the dictionary in order that their definitions become updated with the new word. Is there a way around this? Simple Example: : first ." Hello World!" ; : later ." Do this that the other and then " first ; later : first ." Goodbye World!" ; later The second time 'later' is called, it has not received the updated 'first' word. In order to update 'later', I have to redefine it. Is it somehow possible to structure the definitions so that a later modification of an earlier word propagates to all the other words that use it in their definition? Thanks!
[toc] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-02-03 07:15 -0800 |
| Message-ID | <db516534-5b29-4f4a-8509-6395c86d8352@l9g2000yqp.googlegroups.com> |
| In reply to | #19387 |
On Feb 3, 2:18 pm, AKE <assadebrahim2...@gmail.com> wrote: > Hi: > > One of the strong points of Forth is continuous refactoring. > > But if a low level word, then it seems that all of the higher words that use the lower level word need to be resubmitted to the dictionary in order that their definitions become updated with the new word. > > Is there a way around this? > > Simple Example: > > : first ." Hello World!" ; > : later ." Do this that the other and then " first ; > later > : first ." Goodbye World!" ; > later > > The second time 'later' is called, it has not received the updated 'first' word. > In order to update 'later', I have to redefine it. > > Is it somehow possible to structure the definitions so that a later modification of an earlier word propagates to all the other words that use it in their definition? > > Thanks! Yes. But there are many ways to skin that particular cat, all (probably) requiring carnal knowledge of the system that you are using. As far as I know there's no portable way in which it can be done. Here's how I do it on my system: http://www.turboforth.net/ed.html
[toc] | [prev] | [next] | [standalone]
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-02-03 07:25 -0800 |
| Message-ID | <14be6ab4-3225-4492-9886-60c00c162323@googlegroups.com> |
| In reply to | #19389 |
On Sunday, February 3, 2013 3:15:28 PM UTC, M.R.W Wills wrote: > On Feb 3, 2:18 pm, AKE <assadebrahim2...@gmail.com> wrote: > > > Hi: > > > > > > One of the strong points of Forth is continuous refactoring. > > > > > > But if a low level word, then it seems that all of the higher words that use the lower level word need to be resubmitted to the dictionary in order that their definitions become updated with the new word. > > > > > > Is there a way around this? > > > > > > Simple Example: > > > > > > : first ." Hello World!" ; > > > : later ." Do this that the other and then " first ; > > > later > > > : first ." Goodbye World!" ; > > > later > > > > > > The second time 'later' is called, it has not received the updated 'first' word. > > > In order to update 'later', I have to redefine it. > > > > > > Is it somehow possible to structure the definitions so that a later modification of an earlier word propagates to all the other words that use it in their definition? > > > > > > Thanks! > > > > Yes. But there are many ways to skin that particular cat, all > > (probably) requiring carnal knowledge of the system that you are > > using. As far as I know there's no portable way in which it can be > > done. > > > > Here's how I do it on my system: > > > > http://www.turboforth.net/ed.html Thanks for the article -- very interesting. But wouldn't there be a simpler solution that uses a variable like a function pointer?
[toc] | [prev] | [next] | [standalone]
| From | Bruno Gauthier <bgauthier@free.fr> |
|---|---|
| Date | 2013-02-03 16:24 +0100 |
| Message-ID | <510e8120$0$1860$426a74cc@news.free.fr> |
| In reply to | #19387 |
Le 03/02/2013 15:18, AKE a écrit : > Hi: > > One of the strong points of Forth is continuous refactoring. > > But if a low level word, then it seems that all of the higher words that use the lower level word need to be resubmitted to the dictionary in order that their definitions become updated with the new word. > > Is there a way around this? > > Simple Example: > > : first ." Hello World!" ; > : later ." Do this that the other and then " first ; > later > : first ." Goodbye World!" ; > later > > The second time 'later' is called, it has not received the updated 'first' word. > In order to update 'later', I have to redefine it. > > Is it somehow possible to structure the definitions so that a later modification of an earlier word propagates to all the other words that use it in their definition? > > Thanks! > hi, : later ."Do this that the other and then" s" first" evaluate ; at the execution times the word will be evaluate and executed in that case. bruno
[toc] | [prev] | [next] | [standalone]
| From | AKE <assadebrahim2000@gmail.com> |
|---|---|
| Date | 2013-02-03 07:33 -0800 |
| Message-ID | <5c9acd0c-2073-4f9e-a9bd-093f1101bb11@googlegroups.com> |
| In reply to | #19391 |
On Sunday, February 3, 2013 3:24:16 PM UTC, Bruno Gauthier wrote: > Le 03/02/2013 15:18, AKE a écrit : > > > Hi: > > > > > > One of the strong points of Forth is continuous refactoring. > > > > > > But if a low level word, then it seems that all of the higher words that use the lower level word need to be resubmitted to the dictionary in order that their definitions become updated with the new word. > > > > > > Is there a way around this? > > > > > > Simple Example: > > > > > > : first ." Hello World!" ; > > > : later ." Do this that the other and then " first ; > > > later > > > : first ." Goodbye World!" ; > > > later > > > > > > The second time 'later' is called, it has not received the updated 'first' word. > > > In order to update 'later', I have to redefine it. > > > > > > Is it somehow possible to structure the definitions so that a later modification of an earlier word propagates to all the other words that use it in their definition? > > > > > > Thanks! > > > > > hi, > > : later ."Do this that the other and then" s" first" evaluate ; > > > > at the execution times the word will be evaluate and executed in that case. > Very nice! That meets the desire.
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-02-03 09:27 -0800 |
| Message-ID | <96b525e7-d9f2-4a62-a88c-4b8d661ef34c@h8g2000yqa.googlegroups.com> |
| In reply to | #19391 |
On Feb 3, 3:24 pm, Bruno Gauthier <bgauth...@free.fr> wrote: > Le 03/02/2013 15:18, AKE a écrit : > > > > > > > > > Hi: > > > One of the strong points of Forth is continuous refactoring. > > > But if a low level word, then it seems that all of the higher words that use the lower level word need to be resubmitted to the dictionary in order that their definitions become updated with the new word. > > > Is there a way around this? > > > Simple Example: > > > : first ." Hello World!" ; > > : later ." Do this that the other and then " first ; > > later > > : first ." Goodbye World!" ; > > later > > > The second time 'later' is called, it has not received the updated 'first' word. > > In order to update 'later', I have to redefine it. > > > Is it somehow possible to structure the definitions so that a later modification of an earlier word propagates to all the other words that use it in their definition? > > > Thanks! > > hi, > : later ."Do this that the other and then" s" first" evaluate ; > > at the execution times the word will be evaluate and executed in that case. > > bruno That's a clever solution! My system recently had EVALUATE added so I should use that. I also have DEFER/IS but only as a loadable extension. DEFER/IS is probably preferable since the source code would not need to be changed gain post-debugging.
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2013-02-03 07:34 -0800 |
| Message-ID | <7xfw1de7i8.fsf@ruckus.brouhaha.com> |
| In reply to | #19387 |
AKE <assadebrahim2000@gmail.com> writes: > Is it somehow possible to structure the definitions so that a later > modification of an earlier word propagates to all the other words that > use it in their definition? I don't know if this is gforth-specific: http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Deferred-Words.html I think Forthers usually just rely on Forth's very high compilation speed and recompile everything when they make such a change.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2013-02-03 10:32 -0600 |
| Message-ID | <HrednUi72deVDJPMnZ2dnUVZ_q6dnZ2d@supernews.com> |
| In reply to | #19396 |
Paul Rubin <no.email@nospam.invalid> wrote: > > I think Forthers usually just rely on Forth's very high compilation > speed and recompile everything when they make such a change. Indeed. I felt the need to overwrite words in the dictionary with new definitions the first time I used Forth. I added the ability instantly to "redefine" the behaviour of an existing word -- it's easy to do if you have indirect threaded code. However, I never used it and it wasn't in my next Forth. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2013-02-03 08:44 -1000 |
| Message-ID | <n-idnYszTo60LZPMnZ2dnUVZ_qadnZ2d@supernews.com> |
| In reply to | #19397 |
On 2/3/13 6:32 AM, Andrew Haley wrote:
> Paul Rubin <no.email@nospam.invalid> wrote:
>>
>> I think Forthers usually just rely on Forth's very high compilation
>> speed and recompile everything when they make such a change.
>
> Indeed. I felt the need to overwrite words in the dictionary with new
> definitions the first time I used Forth. I added the ability
> instantly to "redefine" the behaviour of an existing word -- it's easy
> to do if you have indirect threaded code. However, I never used it
> and it wasn't in my next Forth.
Yes. When we speak of "refactoring" we normally do *not* mean what the
OP assumed. What's he's talking about is *redefining* a word.
"Refactoring" means adjusting the definition of a procedure such that
some of its components are available in other contexts, their stack
management is simpler, or other rearrangements that are transparent at
higher levels. For example:
: Proccess ( ... -- ... ) step1 step2 step3 step4 <test> IF
... DO step4A step4B step4C LOOP
ELSE ... DO step5A step5B step5C LOOP
THEN ...step6... ;
Such a complicated definition will be very hard to test, and all its
steps, if spelled out in the definition, are unavailable for individual
testing or reuse.
Refactoring might yield something like this:
: Setup step1 step2 step3 step4 ;
: Factor2 step4A step4B step4c ;
: Factor3 step5A step5B step5C ;
: Process1 ( ... -- ... ) ... do Factor2 loop ;
: Process2 ( ... -- ... ) ... do Factor3 loop ;
: Process ( ... -- ... ) setup
<test> IF Process1 else Process2 then step6 ;
The components of the process become much easier to read and test, as
well as being potentially reusable elsewhere, and the words that call
Process don't need to change at all.
Cheers,
Elizabeth
--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com
"Forth-based products and Services for real-time
applications since 1973."
==================================================
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2013-02-04 16:07 +0000 |
| Message-ID | <2013Feb4.170741@mips.complang.tuwien.ac.at> |
| In reply to | #19396 |
Paul Rubin <no.email@nospam.invalid> writes:
>I don't know if this is gforth-specific:
>
>http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Deferred-Words.html
This is in Forth 200x (except DEFERS) and widely available:
http://www.forth200x.org/deferred.html
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2013: http://www.euroforth.org/ef13/
[toc] | [prev] | [next] | [standalone]
| From | Hugh Aguilar <hughaguilar96@yahoo.com> |
|---|---|
| Date | 2013-02-04 17:27 -0800 |
| Message-ID | <b97aec7b-18fc-48b9-863a-9a4b04520a5b@j9g2000vbz.googlegroups.com> |
| In reply to | #19424 |
On Feb 4, 9:07 am, an...@mips.complang.tuwien.ac.at (Anton Ertl) wrote: > Paul Rubin <no.em...@nospam.invalid> writes: > >I don't know if this is gforth-specific: > > >http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Deferred-Word... > > This is in Forth 200x (except DEFERS) and widely available: > > http://www.forth200x.org/deferred.html I have DEFER in my novice package because DEFER is the traditional way to do this. This is the only use of CREATE DOES> in my novice package. I also have code to do this that doesn't use CREATE DOES> and hence is faster executing. http://www.forth.org/novice.html
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-02-04 23:57 -0800 |
| Message-ID | <8578fce1-c6c6-4450-ab80-6f2e60f066fb@y8g2000vbb.googlegroups.com> |
| In reply to | #19424 |
On Feb 4, 4:07 pm, an...@mips.complang.tuwien.ac.at (Anton Ertl) wrote: > Paul Rubin <no.em...@nospam.invalid> writes: > >I don't know if this is gforth-specific: > > >http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Deferred-Word... > > This is in Forth 200x (except DEFERS) and widely available: > > http://www.forth200x.org/deferred.html > > - anton > -- > M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html > comp.lang.forth FAQs:http://www.complang.tuwien.ac.at/forth/faq/toc.html > New standard:http://www.forth200x.org/forth200x.html > EuroForth 2013:http://www.euroforth.org/ef13/ What's the use case for ACTION-OF ? I'm struggling to see why/how it's useful. Okay, from the command line, I can say: HEX ACTION-OF PLUS . and I can see the XT of PLUS's action. So it's a bit of syntactic sugar to save you typing: ' PLUS DEFER@ . What's its utility in compilation state?
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2013-02-05 11:45 +0000 |
| Subject | ACTION-OF (was: On-the-fly updating of word definitions?) |
| Message-ID | <2013Feb5.124510@mips.complang.tuwien.ac.at> |
| In reply to | #19445 |
Mark Wills <forthfreak@gmail.com> writes:
>What's the use case for ACTION-OF ?
>
>I'm struggling to see why/how it's useful.
>
>Okay, from the command line, I can say:
>
>HEX
>ACTION-OF PLUS .
>
>and I can see the XT of PLUS's action. So it's a bit of syntactic
>sugar to save you typing:
>
>' PLUS DEFER@ .
Yes.
>What's its utility in compilation state?
If guess your question also extends to DEFER@.
One example is the ~~ tracer in Gforth; the programmer plants it into
a word he wants to debug, and when it is executed, it prints the
position of the tracer and the stack contents. It does that with TYPE
and EMIT, but these are deferred words that the debugged word or its
callers may have changed to print to somewhere else. We don't want
the debugging output to go there, so we change TYPE and EMIT to do
what they do normally.
After having printed the debugging stuff, we need to change TYPE and
EMIT back to what they were. In order to do that, we need to know
what they were before, and that's where ACTION-OF or DEFER@ comes into
play: We first save the old actions of TYPE and EMIT, then change
them, do the printing, and restore TYPE and EMIT. The code is:
: .debugline-directed ( nfile nline -- )
action-of type action-of emit { oldtype oldemit }
try
['] (type) is type ['] (emit) is emit
['] .debugline debug-fid outfile-execute
0
restore
oldemit is emit oldtype is type
endtry
throw ;
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2013: http://www.euroforth.org/ef13/
[toc] | [prev] | [next] | [standalone]
| From | stephenXXX@mpeforth.com (Stephen Pelc) |
|---|---|
| Date | 2013-02-05 12:58 +0000 |
| Message-ID | <5111010b.943842178@192.168.0.50> |
| In reply to | #19445 |
On Mon, 4 Feb 2013 23:57:49 -0800 (PST), Mark Wills <forthfreak@gmail.com> wrote: >What's the use case for ACTION-OF ? > >I'm struggling to see why/how it's useful. > >Okay, from the command line, I can say: > >HEX >ACTION-OF PLUS . > >and I can see the XT of PLUS's action. So it's a bit of syntactic >sugar to save you typing: > >' PLUS DEFER@ . > >What's its utility in compilation state? You want to change the action of a DEFERred word and will later want to restore it. variable old-action defer actor : new-foo ... ; : set \ -- action-of actor old-action ! ['] new-foo is actor ; : restore \ -- old-action @ is actor ; Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-02-05 05:20 -0800 |
| Message-ID | <38169fb6-2e39-4e83-a726-5300cefbbeab@y9g2000vbb.googlegroups.com> |
| In reply to | #19455 |
On Feb 5, 12:58 pm, stephen...@mpeforth.com (Stephen Pelc) wrote: > On Mon, 4 Feb 2013 23:57:49 -0800 (PST), Mark Wills > > > > > > <forthfr...@gmail.com> wrote: > >What's the use case for ACTION-OF ? > > >I'm struggling to see why/how it's useful. > > >Okay, from the command line, I can say: > > >HEX > >ACTION-OF PLUS . > > >and I can see the XT of PLUS's action. So it's a bit of syntactic > >sugar to save you typing: > > >' PLUS DEFER@ . > > >What's its utility in compilation state? > > You want to change the action of a DEFERred word and will > later want to restore it. > > variable old-action > defer actor > > : new-foo ... ; > > : set \ -- > action-of actor old-action ! > ['] new-foo is actor > ; > > : restore \ -- > old-action @ is actor > ; > > Stephen > > -- > Stephen Pelc, stephen...@mpeforth.com > MicroProcessor Engineering Ltd - More Real, Less Time > 133 Hill Lane, Southampton SO15 5AF, England > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 > web:http://www.mpeforth.com- free VFX Forth downloads- Hide quoted text - > > - Show quoted text - Thank you both. I just got another Forth "lesson": I typed in the definitions of DEFER et al from the http://www.forth200x.org/deferred.html page but I could not get action-of to work on my system. It was working in immediate mode but not compile mode. I had changed POSTPONE to COMPILE since I don't have POSTPONE but it wasn't working. I just shrugged and moved on. After reading the responses here I took another look. Of course ['] is immediate, so he needs [COMPILE] not COMPILE. Maybe it's time I implemented POSTPONE... It saves the head-scratching if nothing else!
[toc] | [prev] | [next] | [standalone]
| From | Lars Brinkhoff <lars.spam@nocrew.org> |
|---|---|
| Date | 2013-02-05 09:22 +0100 |
| Message-ID | <85mwvjgog8.fsf@junk.nocrew.org> |
| In reply to | #19387 |
How about this? I'm not sure the return address manipulation is portable.
\ Run time: The return address points to a counted string.
\ Try to find that word, and execute it. Return to the right place.
: ([ex]) r@ find if execute else count type abort" not found" then
r> count + align >r ;
\ Compile ([ex]), and append a word name to the definition.
: [execute] postpone ([ex]) bl word count nip allot align ; immediate
\ Sample usage.
: foo [execute] bar ; \ bar can now be redefined at will
: bar ." hello" cr ;
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2013-02-05 18:08 +0200 |
| Message-ID | <99951798018434@frunobulax.edu> |
| In reply to | #19446 |
Lars Brinkhoff <lars.spam@nocrew.org> writes Re: On-the-fly updating of word definitions?
> How about this? I'm not sure the return address manipulation is portable.
[..]
It works in iForth. However, you forgot "1+" to include the count in the
allotted area. It matters for 64bit Forths.
\ Run time: The return address points to a counted string.
\ Try to find that word, and execute it. Return to the right place.
: ([ex]) r@ find if execute else count type abort" not found" then
r> count + align >r ;
\ Compile ([ex]), and append a word name to the definition.
: [execute] postpone ([ex]) bl word count nip 1+ allot align ; immediate
\ -----------------------------------------------^^
\ Sample usage.
: foo [execute] bar ; \ bar can now be redefined at will
: bar ." hello" cr ;
-marcel
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web