-
I'd like to define a word that sets a marker at the start of a group of tests and clean-up those tests at the end of the group. Something like:
However |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Perhaps simply using the HERE word to put the current address on the
stack?
…On Thu, 26 Jan 2023, Anthony Howe wrote:
Date: Thu, 26 Jan 2023 12:05:08 -0800
From: Anthony Howe ***@***.***>
Reply-To: ForthHub/discussion
***@***.***>
To: ForthHub/discussion ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [ForthHub/discussion] Using MARKER within a colon definition?
(Discussion #133)
I'd like to define a word that sets a marker at the start of a group of tests and clean-up those tests at the end of the group. Something like:
: test_group ... MARKER rm_test_group ... ;
: test_group_end ... rm_test_group ;
However MARKER wants to add a word to the word list, which makes it problematic while in the middle of a word definition. Is there some trick or method I'm missing that could achieve
this? Or is it just not possible?
?
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.[AAS2KEUZMYKW4XC4VEUWCWLWULKHJA5CNFSM6AAAAAAUH5BVMSWGG33NNVSW45C7OR4XAZNKIRUXGY3VONZWS33OVJRW63LNMVXHIX3JMTHAASJN2U.gif]
Message ID: ***@***.***>
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Robert S. Sciuk ***@***.***
Principal Consultant Phone: 289.312.1278 Cell: 905.706.1354
Control-Q Research 97 Village Rd. Wellesley, ON N0B 2T0
|
Beta Was this translation helpful? Give feedback.
-
A simple solution is to use
Or
The original code:
is not correct due to the following problems:
|
Beta Was this translation helpful? Give feedback.
-
If I understand what you're asking for you could do:
defer do-marker
: test-group >in @ marker >in ! ' ['] do-marker defer! ;
: test-group-end do-marker ;
\ Example
wordlist constant mk-wl \ to see tests defined and removed
mk-wl >order definitions
test-group foo
: test1 ( ... ) ;
: test2 ( ... ) ;
: test3 ( ... ) ;
words
test-group-end
words
\ Works in Gforth
Gforth 0.7.9_20180905, Copyright (C) 1995-2017 Free Software Foundation,
Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
defer do-marker
: test-group >in @ marker >in ! ' ['] do-marker defer! ;
: test-group-end do-marker ;
\ Example
Gforth 0.7.9_20180905, Copyright (C) 1995-2017 Free Software Foundation,
Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `help' for basic help
wordlist constant mk-wl \ not needed - to see tests defined and removed
mk-wl >order definitions
test-group foo
: test1 ( ... ) ;
: test2 ( ... ) ;
: test3 ( ... ) ;
words \ Display definitions in mk-wl
test3 test2 test1 foo
test-group-end
words \ Ditto - test group removed
\ Alternatively more simply
: test-group marker ;
: test-group-end ' execute ;
\ Usage
test-group foo
\ Test code as above
end-test-group foo
…On 26/01/2023 20:05, Anthony Howe wrote:
I'd like to define a word that sets a marker at the start of a group
of tests and clean-up those tests at the end of the group. Something like:
|: test_group ... MARKER rm_test_group ... ; : test_group_end ...
rm_test_group ; |
However |MARKER| wants to add a word to the word list, which makes it
problematic while in the middle of a word definition. Is there some
trick or method I'm missing that could achieve this? Or is it just not
possible?
—
Reply to this email directly, view it on GitHub
<#133>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADH775NGSTDNXEKKHKDCC4TWULKHXANCNFSM6AAAAAAUH5BVMQ>.
You are receiving this because you are subscribed to this
thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I realised soon after I'd posted, that in my first solution the word
do-marker is unnecesssary. Just have
defer test-group-end
and replace do-marker in the definition of test-group with test-group-end.
…On 26/01/2023 23:22, ruv wrote:
@gerryjackson <https://github.com/gerryjackson>, nice solution!
Though, as I can see, the idea of Anthony was to have a kind of
anonymous lexical blocks of tests:
|test_group ... test_group_end |
They also work as expected if they are nested.
NB: since |test_group_end| is a word that should be encountered by the
Forth text interpreter, the tests shall not shadow this word or make
it unfindable (due to changes in the search order).
—
Reply to this email directly, view it on GitHub
<#133 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADH775JC2HPJ2ZRCYWCLXADWUMBMPANCNFSM6AAAAAAUH5BVMQ>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
A simple solution is to use
evaluate
:Or
execute-parsing
in the first case:The original code:
is not correct due to the following problems:
marker
is an ordinary word. Therefore it doesn't parse anything when it's used inside a definition (i.e., when it's compiled), — just likeconstant
and:
(colon). So the Forth text interpreter will encounterrm_test_group
and raise an error.test_group_end
is being defined,rm_test_group
…