hello,
I would reuse some external data to do something with
My idea was to :
1.capture data (get some string)
2. display
3. convertit to number
4. dostuff
5. display results
So I defined some
create buffer 1024 allot
5 constant SIZE
variable out
create outputgraph SIZE cells allot
: commandout ( "cmd" -- variable out as string )
r/o open-pipe throw dup buffer swap 256 swap read-file throw swap
regards
In article <ce094d5f-a29f-4a1e...@googlegroups.com>,
gobli...@gmail.com <gobli...@gmail.com> wrote:
hello,
I would reuse some external data to do something with
My idea was to :
1.capture data (get some string)
2. display
3. convertit to number
4. dostuff
5. display results
So I defined some
create buffer 1024 allotI know no Forth that know "open-pipe" like that
5 constant SIZE
variable out
create outputgraph SIZE cells allot
: commandout ( "cmd" -- variable out as string )
r/o open-pipe throw dup buffer swap 256 swap read-file throw swap
<SNIP>
regards
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring. You must not say "hey" before you have crossed the bridge. Don't sell the hide of the bear until you shot it. Better one bird in the hand than ten in the air. First gain is a cat spinning. - the Wise from Antrim -
On Monday, June 12, 2023 at 4:24:08 PM UTC-4, Brian Fox wrote:thanks you all
On Monday, June 12, 2023 at 3:55:13 PM UTC-4, gobli...@gmail.com wrote:
gForth seems to have NUMBER? .
It takes a byte counted string and returns the number and flag
S" 9999" PAD PLACE okIf you can tolerate single precision I wrote this one for Camel Forth
ok
ok
PAD NUMBER? ok
.S <2> 9999 -1 ok
It's weird because zero means a good conversion but that was
more consistent with ABORT" in my system.
: NUMBER? ( addr len -- n ?) \ ?=0 is good conversion
( -- addr len) \ bad conversion
OVER C@ [CHAR] - = DUP >R \ save flag for later
IF 1 /STRING THEN \ remove minus sign
0 0 2SWAP >NUMBER NIP NIP \ convert the number
IF SWAP NEGATE SWAP THEN \ negate if needed;
On Monday, June 12, 2023 at 3:55:13 PM UTC-4, gobli...@gmail.com wrote:
gForth seems to have NUMBER? .
It takes a byte counted string and returns the number and flag
S" 9999" PAD PLACE ok
ok
ok
PAD NUMBER? ok
.S <2> 9999 -1 ok
so I thouthg I could just
out 2@ s>number drop 0 outputgraph [] ! \ may be
NUMBER ( ud1 c-addr1 u1 – – ud2 c-addr2 u2 )So it expects and returns 4 stack items.
I know no Forth that know "open-pipe" like that
In article <ce094d5f-a29f-4a1e...@googlegroups.com>,
gobli...@gmail.com <gobli...@gmail.com> wrote:
hello,
I would reuse some external data to do something with
My idea was to :
1.capture data (get some string)
2. display
3. convertit to number
4. dostuff
5. display results
So I defined some
create buffer 1024 allotI know no Forth that know "open-pipe" like that
5 constant SIZE
variable out
create outputgraph SIZE cells allot
: commandout ( "cmd" -- variable out as string )
r/o open-pipe throw dup buffer swap 256 swap read-file throw swap
<SNIP>
regards
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring. You must not say "hey" before you have crossed the bridge. Don't sell the hide of the bear until you shot it. Better one bird in the hand than ten in the air. First gain is a cat spinning. - the Wise from Antrim -
hello,
I would reuse some external data to do something with
My idea was to :
1.capture data (get some string)
2. display
3. convertit to number
4. dostuff
5. display results
So I defined some
create buffer 1024 allot
5 constant SIZE
variable out
create outputgraph SIZE cells allot
: commandout ( "cmd" -- variable out as string )
r/o open-pipe throw dup buffer swap 256 swap read-file throw swap
close-pipe throw drop buffer swap out 2!
;
: [] ( n addr -- addr[n] ) swap cells + ; \ if i understood correctly the array model
here I can now test the capture
s\" psql -c \qselect sum(exp) from experience where champs ilike 'langues' ;\q | sed '3!d' " commandout
out 2@ type \ should be 40 40
ok
now the goal is to convert it as an int inside my array
so I thouthg I could just
out 2@ s>number drop 0 outputgraph [] ! \ may be
but before that even the out 2@ s>number just output 0 0 to the stack & not a number ...
Ideas to fit my goal to capture the "40" value from that example ?
regards
On Monday, June 12, 2023 at 9:51:20 PM UTC+2, none albert wrote:
In article <ce094d5f-a29f-4a1e...@googlegroups.com>,
gobli...@gmail.com <gobli...@gmail.com> wrote:
hello,I know no Forth that know "open-pipe" like that
I would reuse some external data to do something with
My idea was to :
1.capture data (get some string)
2. display
3. convertit to number
4. dostuff
5. display results
So I defined some
create buffer 1024 allot
5 constant SIZE
variable out
create outputgraph SIZE cells allot
: commandout ( "cmd" -- variable out as string )
r/o open-pipe throw dup buffer swap 256 swap read-file throw swap
<SNIP>
Groetjes Albert
regards
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in >> the air. First gain is a cat spinning. - the Wise from Antrim -
4tH can as well:
s" ls" input pipe + open error? abort" Cannot open pipe"
dup use begin refill while 0 parse type cr repeat close
Hans Bezemer
On Monday, June 12, 2023 at 3:55:13=E2=80=AFPM UTC-4, gobli...@gmail.com wr= >ote:
gForth seems to have NUMBER? .
Brian Fox <bria...@brianfox.ca> writes:
On Monday, June 12, 2023 at 3:55:13=E2=80=AFPM UTC-4, gobli...@gmail.com wr= >ote:
gForth seems to have NUMBER? .Not in the development version. As for S>NUMBER (mentioned also in
this thread), the source code says:
\ don't use this, there is no way to tell success
The current recommendation is
'rec-num' ( addr u -- n/d table | notfound ) gforth-experimental "rec-num" converts a number to a single/double integer
where table is the xt of TRANSLATE-NUM (and n below table) or
TRANSLATE-DNUM (and d below table); or the top of stack ist the xt of NOTFOUND.
I find the combination of single- and double-cell numbers in one
recognizer suboptimal as an interface, but it actally simplifies the implemetation compared to a variant that has separate recognizers for
singles and doubles and only combines them at the recognizer level.
albert@cherry.(none) (albert) writes:
I know no Forth that know "open-pipe" like that
Maybe Gforth: <https://gforth.org/manual/Pipes.html>
- anton
In article <2023Jun12.224343@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
albert@cherry.(none) (albert) writes:
I know no Forth that know "open-pipe" like that
Maybe Gforth: <https://gforth.org/manual/Pipes.html>
I intended to provoke an introductory remark:
"using a bleeding edge version of Gforth."
Nothing about "pipe" is to be found in the info docs of
gforth installed by Ubuntu.
I didn't realize that the open-pipe had nothing to do
with the question he asked.
I wasn't aware of the online documentation of gforth.
Nothing about "pipe" is to be found in the info docs of
gforth installed by Ubuntu.
albert@cherry.(none) (albert) writes:
In article <2023Jun12.224343@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
albert@cherry.(none) (albert) writes:
I know no Forth that know "open-pipe" like that
Maybe Gforth: <https://gforth.org/manual/Pipes.html>
I intended to provoke an introductory remark:
"using a bleeding edge version of Gforth."
Bleeding edge since at least gforth-0.2 (1996).
Nothing about "pipe" is to be found in the info docs of
gforth installed by Ubuntu.
That's not surprising given that Ubuntu follows Debian in not
installing the Gforth documentation (not even as a "non-free"
package).
What "info docs of gforth installed by Ubuntu" are you referring to?
There are no info docs of Gforth on my Ubuntu 22.04 laptop except
those that I installed myself.
- antongroetjes Albert
In article <2023Jun13.185532@mips.complang.tuwien.ac.at>,...
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
albert@cherry.(none) (albert) writes:
In article <2023Jun12.224343@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote: >>>>albert@cherry.(none) (albert) writes:
I know no Forth that know "open-pipe" like that
Maybe Gforth: <https://gforth.org/manual/Pipes.html>
I intended to provoke an introductory remark:
"using a bleeding edge version of Gforth."
Bleeding edge since at least gforth-0.2 (1996).
Maybe I have installed it myself. It commences with
"This manual corresponds to version 0.5.0."
Anton Ertl schrieb am Dienstag, 13. Juni 2023 um 09:48:28 UTC+2:
Brian Fox <bria...@brianfox.ca> writes:
On Monday, June 12, 2023 at 3:55:13=E2=80=AFPM UTC-4, gobli...@gmail.com wr=Not in the development version. As for S>NUMBER (mentioned also in
ote:
gForth seems to have NUMBER? .
this thread), the source code says:
\ don't use this, there is no way to tell success
The current recommendation is
'rec-num' ( addr u -- n/d table | notfound ) gforth-experimental "rec-num" >> converts a number to a single/double integer
where table is the xt of TRANSLATE-NUM (and n below table) or
TRANSLATE-DNUM (and d below table); or the top of stack ist the xt of
NOTFOUND.
I find the combination of single- and double-cell numbers in one
recognizer suboptimal as an interface, but it actally simplifies the
implemetation compared to a variant that has separate recognizers for
singles and doubles and only combines them at the recognizer level.
I use a non-standard
NUMBER? \ ( a u -- 0 | n 1 | d 2 ) convert to single or double number
that handles prefixes, 'c' chars, and the classic dpl. So no surprises here. Okay for interpreting legacy code.
On 13/06/2023 7:49 pm, minforth wrote:
Anton Ertl schrieb am Dienstag, 13. Juni 2023 um 09:48:28 UTC+2:
Brian Fox <bria...@brianfox.ca> writes:
On Monday, June 12, 2023 at 3:55:13=E2=80=AFPM UTC-4, gobli...@gmail.com wr=Not in the development version. As for S>NUMBER (mentioned also in
ote:
gForth seems to have NUMBER? .
this thread), the source code says:
\ don't use this, there is no way to tell success
The current recommendation is
'rec-num' ( addr u -- n/d table | notfound ) gforth-experimental "rec-num" >> converts a number to a single/double integer
where table is the xt of TRANSLATE-NUM (and n below table) or
TRANSLATE-DNUM (and d below table); or the top of stack ist the xt of
NOTFOUND.
I find the combination of single- and double-cell numbers in one
recognizer suboptimal as an interface, but it actally simplifies the
implemetation compared to a variant that has separate recognizers for
singles and doubles and only combines them at the recognizer level.
I use a non-standardSome well-known forths use that as it suits the forth interpreter. OTOH
NUMBER? \ ( a u -- 0 | n 1 | d 2 ) convert to single or double number
that handles prefixes, 'c' chars, and the classic dpl. So no surprises here.
Okay for interpreting legacy code.
it's overkill for most apps and requires more handling. What's missing
is the intermediate function, similar to >FLOAT but for integer.
On 14/06/2023 4:38 pm, minforth wrote:
dxforth schrieb am Mittwoch, 14. Juni 2023 um 05:54:04 UTC+2:
On 13/06/2023 7:49 pm, minforth wrote:
Anton Ertl schrieb am Dienstag, 13. Juni 2023 um 09:48:28 UTC+2:Some well-known forths use that as it suits the forth interpreter. OTOH
Brian Fox <bria...@brianfox.ca> writes:
On Monday, June 12, 2023 at 3:55:13=E2=80=AFPM UTC-4, gobli...@gmail.com wr=Not in the development version. As for S>NUMBER (mentioned also in
ote:
gForth seems to have NUMBER? .
this thread), the source code says:
\ don't use this, there is no way to tell success
The current recommendation is
'rec-num' ( addr u -- n/d table | notfound ) gforth-experimental "rec-num"
converts a number to a single/double integer
where table is the xt of TRANSLATE-NUM (and n below table) or
TRANSLATE-DNUM (and d below table); or the top of stack ist the xt of >>>> NOTFOUND.
I find the combination of single- and double-cell numbers in one
recognizer suboptimal as an interface, but it actally simplifies the >>>> implemetation compared to a variant that has separate recognizers for >>>> singles and doubles and only combines them at the recognizer level.
I use a non-standard
NUMBER? \ ( a u -- 0 | n 1 | d 2 ) convert to single or double number
that handles prefixes, 'c' chars, and the classic dpl. So no surprises here.
Okay for interpreting legacy code.
it's overkill for most apps and requires more handling. What's missing
is the intermediate function, similar to >FLOAT but for integer.
That's besides the point (there is still >NUMBER). The point is whether recognizers like rec-num or rec-dnum should be part of a Forth kernel.If ANS' >NUMBER is the reference then anything over becomes 'overkill'.
I won't criticise gforth design decisions, but ISTM that _this_ is overkill as long as there are easier ways.
Early forths had NUMBER (as did Forth-79 in the Reference wordset).
ANS ignored it - perhaps due to lack of common practice. I'm getting
the sense >NUMBER is not enough. The opportunity and willingness to
determine what is has likely passed us by.
dxforth schrieb am Mittwoch, 14. Juni 2023 um 05:54:04 UTC+2:
On 13/06/2023 7:49 pm, minforth wrote:
Anton Ertl schrieb am Dienstag, 13. Juni 2023 um 09:48:28 UTC+2:Some well-known forths use that as it suits the forth interpreter. OTOH
Brian Fox <bria...@brianfox.ca> writes:
On Monday, June 12, 2023 at 3:55:13=E2=80=AFPM UTC-4, gobli...@gmail.com wr=Not in the development version. As for S>NUMBER (mentioned also in
ote:
gForth seems to have NUMBER? .
this thread), the source code says:
\ don't use this, there is no way to tell success
The current recommendation is
'rec-num' ( addr u -- n/d table | notfound ) gforth-experimental "rec-num" >>>> converts a number to a single/double integer
where table is the xt of TRANSLATE-NUM (and n below table) or
TRANSLATE-DNUM (and d below table); or the top of stack ist the xt of
NOTFOUND.
I find the combination of single- and double-cell numbers in one
recognizer suboptimal as an interface, but it actally simplifies the
implemetation compared to a variant that has separate recognizers for
singles and doubles and only combines them at the recognizer level.
I use a non-standard
NUMBER? \ ( a u -- 0 | n 1 | d 2 ) convert to single or double number
that handles prefixes, 'c' chars, and the classic dpl. So no surprises here.
Okay for interpreting legacy code.
it's overkill for most apps and requires more handling. What's missing
is the intermediate function, similar to >FLOAT but for integer.
That's besides the point (there is still >NUMBER). The point is whether recognizers like rec-num or rec-dnum should be part of a Forth kernel.
I won't criticise gforth design decisions, but ISTM that _this_ is overkill as long as there are easier ways.
dxforth schrieb am Mittwoch, 14. Juni 2023 um 05:54:04 UTC+2:
On 13/06/2023 7:49 pm, minforth wrote:surprises here.
Anton Ertl schrieb am Dienstag, 13. Juni 2023 um 09:48:28 UTC+2:
Brian Fox <bria...@brianfox.ca> writes:
On Monday, June 12, 2023 at 3:55:13=E2=80=AFPM UTC-4, >gobli...@gmail.com wr=Not in the development version. As for S>NUMBER (mentioned also in
ote:
gForth seems to have NUMBER? .
this thread), the source code says:
\ don't use this, there is no way to tell success
The current recommendation is
'rec-num' ( addr u -- n/d table | notfound ) gforth-experimental "rec-num"
converts a number to a single/double integer
where table is the xt of TRANSLATE-NUM (and n below table) or
TRANSLATE-DNUM (and d below table); or the top of stack ist the xt of
NOTFOUND.
I find the combination of single- and double-cell numbers in one
recognizer suboptimal as an interface, but it actally simplifies the
implemetation compared to a variant that has separate recognizers for
singles and doubles and only combines them at the recognizer level.
I use a non-standard
NUMBER? \ ( a u -- 0 | n 1 | d 2 ) convert to single or double number
that handles prefixes, 'c' chars, and the classic dpl. So no
Okay for interpreting legacy code.Some well-known forths use that as it suits the forth interpreter. OTOH
it's overkill for most apps and requires more handling. What's missing
is the intermediate function, similar to >FLOAT but for integer.
That's besides the point (there is still >NUMBER). The point is whether >recognizers like rec-num or rec-dnum should be part of a Forth kernel.
I won't criticise gforth design decisions, but ISTM that _this_ is overkill >as long as there are easier ways.
The most important thing to realise is that >number is not meant to be the >final word but a stepping stone..
It applies to integers.
Its weakness is that if there is an overflow there is no signal to the caller.
NUMBER should a loadable extension. A typical example where it is usedin is a lisp interpreter.
In article <0a763f38-bc21-4486-a833-b55e668c0a87n@googlegroups.com>,
NN <november.nihal@gmail.com> wrote:
<SNIP>
The most important thing to realise is that >number is not meant to be the >> final word but a stepping stone..
It applies to integers.
Its weakness is that if there is an overflow there is no signal to the caller.
On the contrary, it has all options open. However you have to add overflow. It is a "Swiss army knife" (or egg vending machine).
The word >NUMBER used as a stepping stone suggest that it should be
used internally. Don't fall for the temptation. Forcing a Forth to use
this "switch army knife" result in a cumbersome Forth implementation.
In article <0a763f38-bc21-4486...@googlegroups.com>,
NN <novembe...@gmail.com> wrote:
<SNIP>
The most important thing to realise is that >number is not meant to be the >final word but a stepping stone..
It applies to integers.
Its weakness is that if there is an overflow there is no signal to the caller.On the contrary, it has all options open. However you have to add overflow. It is a "Swiss army knife" (or egg vending machine).
The word >NUMBER used as a stepping stone suggest that it should be
used internally. Don't fall for the temptation. Forcing a Forth to use
this "switch army knife" result in a cumbersome Forth implementation.
Come to think of this. >NUMBER is in the ciforth kernel and it is never
used there. It wastes a whopping 300 bytes there and it is one of the
5 most complicated definitions in my whole Forth, making it look worse
than it should be.
NUMBER should a loadable extension. A typical example where it is usedin is a lisp interpreter.
In normal situation it is rare. E.g. in my 400+ solutions of euler
problems, it came up once.
That was euler 13:
"
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
37107287533902102798797998220837590246510135740250
..
"
You can see how that is appropriate.
Groetjes Albert.
--
Don't praise the day before the evening. One swallow doesn't make spring. You must not say "hey" before you have crossed the bridge. Don't sell the hide of the bear until you shot it. Better one bird in the hand than ten in the air. First gain is a cat spinning. - the Wise from Antrim -
...
in fact >number or >float & so on words works on natural strings build from any s" mystring" and variables affectation from there
NUMBER is a general-purpose factor that can be used independently of the forth interpreter.
hello,
I would reuse some external data to do something with
My idea was to :
1.capture data (get some string)
2. display
3. convertit to number
4. dostuff
5. display results
So I defined some
create buffer 1024 allot
5 constant SIZE
variable out
create outputgraph SIZE cells allot
: commandout ( "cmd" -- variable out as string )
r/o open-pipe throw dup buffer swap 256 swap read-file throw swap
close-pipe throw drop buffer swap out 2!
;
: [] ( n addr -- addr[n] ) swap cells + ; \ if i understood correctly the array model
here I can now test the capture
s\" psql -c \qselect sum(exp) from experience where champs ilike 'langues' ;\q | sed '3!d' " commandout
out 2@ type \ should be 40 40
ok
now the goal is to convert it as an int inside my array
so I thouthg I could just
out 2@ s>number drop 0 outputgraph [] ! \ may be
but before that even the out 2@ s>number just output 0 0 to the stack & not a number ...
Ideas to fit my goal to capture the "40" value from that example ?
regards
R 2DUP R> SCAN NIP - \ good idea from bfox9900 reddit;
On Thursday, June 15, 2023 at 4:10:30 AM UTC-4, gobli...@gmail.com wrote:
I might as well chime in here too. :-)
Forth has a standard word called SPACES so you can make this simpler.
: test
dup \ for tailing spaces count
." ["
0 DO ." #" loop
100 swap - SPACES
." ]"
cr
;
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (2 / 14) |
Uptime: | 39:36:49 |
Calls: | 8,336 |
Calls today: | 13 |
Files: | 13,155 |
Messages: | 5,891,234 |
Posted today: | 1 |