gforth

Writing a text file into an array on Forth

泪湿孤枕 提交于 2021-02-10 14:21:48
问题 I have a text file, containing an array of numbers such as: 1 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 I have opened the text file with the following code: variable file-id : open_file ( -- ) \ Opens the text file s" c:\etc\textfile.txt" r/w open-file throw file-id ! ; I have also created an array to store this data: create an_array 25 chars allot \ Create the array : reset_array ( -- ) big_array 25 0 fill ; reset_array \ Set all elements to 0 Is there a way to write the contents of

Writing a text file into an array on Forth

╄→гoц情女王★ 提交于 2021-02-10 14:20:18
问题 I have a text file, containing an array of numbers such as: 1 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 I have opened the text file with the following code: variable file-id : open_file ( -- ) \ Opens the text file s" c:\etc\textfile.txt" r/w open-file throw file-id ! ; I have also created an array to store this data: create an_array 25 chars allot \ Create the array : reset_array ( -- ) big_array 25 0 fill ; reset_array \ Set all elements to 0 Is there a way to write the contents of

ANSI Forth BASE upper limit vs. gforth upper limit, to and from?

删除回忆录丶 提交于 2020-01-17 06:14:10
问题 Fiddling with the gforth version of BASE shows that BASE can be used for values past those most languages permit. For example, this prints the number 0ABC (base 15950) in decimal, and vice versa: gforth -e '15950 base ! ABC decimal . cr bye' gforth -e '2544200462 15950 base ! . cr bye' Output: 2544200462 ABC Without writing additional Forth words, what are the default Gforth and ANSI Forth BASE upper limits for meaningful conversions both to and from numbers of different bases? (Ignore for

Forth local variable assigning variables

怎甘沉沦 提交于 2020-01-15 08:08:30
问题 I have a simple local variable in Forth: : subtraction { a b } a b - ; I would like to assign the output of a b - to another variable, say c. Is this possible? 回答1: TO works for both VALUE s and local variables, so: : subtraction { a b | c -- } a b - to c ; 来源: https://stackoverflow.com/questions/49115901/forth-local-variable-assigning-variables

Gforth conditional expression with variables - only partly correct

江枫思渺然 提交于 2020-01-03 03:43:08
问题 Simple expression: variable x ok 4 x ! ok 3 x < . -1 ok 3 x > . 0 ok This seems normal and correct, however: variable x ok 3 x ! ok x 4 < . 0 ok x 4 > . -1 ok The second block of code is wrong. What is evaluating wrongly? What is the problem here? 回答1: variable x makes a new variable, but x returns the address, not the value. You need something like this: variable x 3 x ! ok x @ 4 < . x @ 4 > . 来源: https://stackoverflow.com/questions/49040227/gforth-conditional-expression-with-variables-only

Does GNU FORTH have an editor?

♀尐吖头ヾ 提交于 2019-12-11 04:15:53
问题 Chapter 3 of Starting FORTH says, Now that you've made a block "current", you can list it by simply typing the word L . Unlike LIST , L does not want to be proceeded by a block number; instead it lists the current block. When I run 180 LIST , I get Screen 180 not modified 0 ... 15 ok But when I run L , I get an error :30: Undefined word >>>L<<< Backtrace: $7F0876E99A68 throw $7F0876EAFDE0 no.extensions $7F0876E99D28 interpreter-notfound1 What am I doing wrong? 回答1: Yes, gForth supports an

Load from the terminal input buffer to parameter stack

走远了吗. 提交于 2019-12-11 03:19:37
问题 Why does this code not work? TIB 10 ACCEPT TIB SP@ 1 cells - 10 cmove In that code I tried to enter a string and store it in the terminal input buffer and later store it on the parameter stack. But with .S I see that does not work. 回答1: The parameter stack grows towards low memory The main problem with the sample code is that the parameter stack grows towards low memory. So the starting point for the destination of the copy should be at a higher memory address (inside the existing/defined

How do I read raw code from a website in Gforth?

情到浓时终转凉″ 提交于 2019-12-08 00:21:32
问题 I would like a word like read-site ( add n buff max -- n flag ) where 'add n' is the site name buffer, 'buff max' is the buffer to which the ASCII text should be read to, 'n' is the number of bytes that was read and flag is true if operation succeeded. Is this possible in Gforth in Linux, Android or Windows? 回答1: Just a list of approaches The most easy proper way should be to use an HTTP-client library (or binding) in Forth (if any). It seems that some kind of such library exists in the

Gforth conditional expression with variables - only partly correct

这一生的挚爱 提交于 2019-12-07 07:35:29
Simple expression: variable x ok 4 x ! ok 3 x < . -1 ok 3 x > . 0 ok This seems normal and correct, however: variable x ok 3 x ! ok x 4 < . 0 ok x 4 > . -1 ok The second block of code is wrong. What is evaluating wrongly? What is the problem here? variable x makes a new variable, but x returns the address, not the value. You need something like this: variable x 3 x ! ok x @ 4 < . x @ 4 > . 来源: https://stackoverflow.com/questions/49040227/gforth-conditional-expression-with-variables-only-partly-correct

How do I read raw code from a website in Gforth?

谁都会走 提交于 2019-12-06 07:29:40
I would like a word like read-site ( add n buff max -- n flag ) where 'add n' is the site name buffer, 'buff max' is the buffer to which the ASCII text should be read to, 'n' is the number of bytes that was read and flag is true if operation succeeded. Is this possible in Gforth in Linux, Android or Windows? ruvim Just a list of approaches The most easy proper way should be to use an HTTP-client library (or binding) in Forth (if any). It seems that some kind of such library exists in the Gforth repository — see netlib/httpclient.fs . Obviously it doesn't work with HTTPS. The next way is to use