Here's a short repro for a problem I'm now encountering with the circular buffer I posted a few days ago. Whereas the words toX and toY below work as expected interactively, using them inside another word fails. Have I misunderstand something important about '?
marker-reprodecimalram:point:( "name" x y -- )ramcreateswap,( x),( y);:xy.( a-addr -- )@+.@.;:toX( "name" x -- )'execute!;:toY( "name" y -- )'execute2+!;23point:AAxy.4toXA5toYAAxy.:fine( x -- )A!Axy.;7fine:hmm( x -- )toXA;\ FF replies '?' to the following:8hmm-repro
I'm doing this on PIC24.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Although the above repro aimed to crystallize the issue into as simple a package as possible, it may have obscured my underlying motivation a bit. My actual trouble is with the INTO word of abovementioned circular buffer, which I would have hoped to use in the same manner as TO. (Is TO itself state-smart?)
The Ertl article looks pretty challenging to me, but already I see that I've stumbled on this state-smartness issue in 'the usual way'. In §4.3, he says,
The most frequent reason for wanting a combined word is parsing words : words that read the input stream.
A bit earlier, Ertl says,
The general solution is to provide two words: one for the interpretation semantics and one for the compilation semantics. Examples: ' and ['], char and [char], and s"-int and s"-comp.
So I could perhaps implement as well an [INTO] word for use during compilation, but that destroys the simplicity of aligning with TO, which needs no companion [TO].
Another solution might be, if I have defined a CIRCBUF: MYBUF, to define also a word !MYBUF following the same, standard naming convention as your !X above.
Still, the dangers Ertl highlights (that users might someday TICK or POSTPONE a state-smart word) seems somehow unlikely in the case of INTO. But then again, my first thought upon initial encounter with the concept of state-smartness was, "Oh, I would never write such a word!"
Addendum: Ha! Looking again at that §6.11.1 of the GForth manual, I see the following:
This feature was introduced for implementing TO and S". I recommend that you do not define such words, as cute as they may be: they make it hard to get at both parts of the word in some contexts.
So the design I'll pursue now will require defining a !MYBUF word.
Last edit: David C. Norris 2024-07-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
when I put data into a circular buffer or fifo, as can be seen from the CQ: character fifos in FF PIC24. The CQ: fifos are used by the UART RX and UART buffered TX.
In order to survive a restart CIRCBUF: should store persistent data ( like size) in flash and variable data (like current index) in ram.
❤️
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here's a short repro for a problem I'm now encountering with the circular buffer I posted a few days ago. Whereas the words
toX
andtoY
below work as expected interactively, using them inside another word fails. Have I misunderstand something important about'
?I'm doing this on PIC24.
In hmm you would need toX to use ['] for it to work. ' is not state smart.
Something like this might work.
I tend to avoid words that use TICK and have to interpret. So I would do
There are also wordsets for structs, but I have not used or defined them for FF.
Thank you, Mikael. Appreciating this as a question of state-smartness is most helpful. This looks like an excellent opportunity for me to read Ertl's article, State-smartness — Why it is Evil and How to Exorcise it, cited at the bottom of https://gforth.org/manual/Combined-words.html.
Although the above repro aimed to crystallize the issue into as simple a package as possible, it may have obscured my underlying motivation a bit. My actual trouble is with the INTO word of abovementioned circular buffer, which I would have hoped to use in the same manner as TO. (Is TO itself state-smart?)
The Ertl article looks pretty challenging to me, but already I see that I've stumbled on this state-smartness issue in 'the usual way'. In §4.3, he says,
A bit earlier, Ertl says,
So I could perhaps implement as well an [INTO] word for use during compilation, but that destroys the simplicity of aligning with TO, which needs no companion [TO].
Another solution might be, if I have defined a CIRCBUF: MYBUF, to define also a word !MYBUF following the same, standard naming convention as your !X above.
Still, the dangers Ertl highlights (that users might someday TICK or POSTPONE a state-smart word) seems somehow unlikely in the case of INTO. But then again, my first thought upon initial encounter with the concept of state-smartness was, "Oh, I would never write such a word!"
Addendum: Ha! Looking again at that §6.11.1 of the GForth manual, I see the following:
So the design I'll pursue now will require defining a !MYBUF word.
Last edit: David C. Norris 2024-07-27
I usually would write
when I put data into a circular buffer or fifo, as can be seen from the CQ: character fifos in FF PIC24. The CQ: fifos are used by the UART RX and UART buffered TX.
In order to survive a restart CIRCBUF: should store persistent data ( like size) in flash and variable data (like current index) in ram.