Questions tagged [gforth]

Gforth is a fast and portable implementation of the ANS Forth language. It works nicely with the Emacs editor, offers some nice features such as input completion and history and a powerful locals facility

Gforth is a fast and portable implementation of the ANS Forth language. It works nicely with the Emacs editor, offers some nice features such as input completion and history and a powerful locals facility, and it even has (the beginnings of) a manual.

Gforth employs traditional implementation techniques: its inner interpreter is indirect or direct threaded.

124 questions
16
votes
3 answers

Comparison of Common Lisp macros and Forth metaprogramming capabilities

Every Common Lisp programmer knows that macros are a powerful tool. Common Lisp macros have been used, among other things, to add object orientation on top of Lisp without changing the language specification; read-macros are another construct with…
user3750103
  • 193
  • 1
  • 5
10
votes
2 answers

Examples of Custom Control Flow Compiling Words

Forth famously allows users to alter the language by defining new words for control flow (beyond those given by the standard: DO, LOOP, BEGIN, UNTIL, WHILE, REPEAT, LEAVE IF, THEN, ELSE, CASE, ENDCASE, etc.) Are there common examples of people…
Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485
8
votes
1 answer

What does "local variable" mean in the Forth programming language?

In C, local variables exist inside of a function and contain the values like this: void main(){ int a = 5; int b = 9; } In the Gforth manual, they describe the local variables like this: : swap { a b -- b a } b a ; 1 2 swap .s 2drop but…
8
votes
4 answers

Dissassembly of Forth code words with 'see'

I am preparing overall knowledge on building a Forth interpreter and want to disassemble some of the generic Forth code words such as +, -, *, etc. My Gforth (I currently have version 0.7.3, installed on Ubuntu Linux) will allow me to disassemble…
thallia
  • 81
  • 6
8
votes
1 answer

How to list the current set of words in Forth

Is it possible to get the list of all words which are currently defined in Forth (for example in Gforth)?
ivand58
  • 773
  • 6
  • 19
8
votes
1 answer

How to write a while() loop in Gforth

I'd like to write a while() loop in Gforth. Unfortunately, the only tutorial online isn't useful due to a lack of examples, and examples on counted loops (what I'm not looking for) appear fundamentally different. What are some concrete examples of…
Phillip Carter
  • 4,895
  • 16
  • 26
7
votes
4 answers

Gforth storing string values in variables

I'm trying to store a string value into a variable. To define the variable, I use: : define CREATE 0 , ; define x I can easily store an integer/float value to x using 10 x ! or 10.0e x f! And to access it I use either @ or f@. Now I'm trying to…
Arian Motamedi
  • 7,123
  • 10
  • 42
  • 82
7
votes
1 answer

Add an integer value to a floating point value in Gforth

In Gforth, is there a way to add an integer value to a floating point value? Something like 1 + 2.1? If I do 1 2.1e f+ I get an error which I'm guessing is because the values are not on the same stack. I know that I could just do 1.0e 2.1e f+, but…
6
votes
3 answers

Gforth, FORGET and LIST words as in the original Forth

Is there an equivalent to forget word of Forth in Gforth? I've seen about marker, but it doesn't have the same behaviour. Also the list command doesn't seem to give a listing of the program. I'd like to view a list of the in-memory program, just…
Krackout
  • 282
  • 4
  • 14
6
votes
1 answer

A faulty algorithm for subtraction of big integers in Forth

I have a mysterious error with an algorithm for subtraction of unsigned integers of various lengths. It works for almost every pair of numbers, but if n isn't smaller than the number of bits in a cell then (2^n +1)-(2^n - 1) <> 2. I can't understand…
Lehs
  • 812
  • 6
  • 18
5
votes
1 answer

How can I exit Forth with a non-zero exit status?

I would like to exit a Forth program (using Gforth 0.7.3) with a non-zero exit status. I've tried: 1 bye But the 1 is not interpreted as an argument to bye (and I didn't expect this to work anyway; I couldn't find any hint in the documentation that…
Christian Hujer
  • 17,035
  • 5
  • 40
  • 47
5
votes
1 answer

How can I access a shadowed definition in Forth?

When a word is redefined, is it possible to access the old word? Imagine there is a word foo defined and redefined : foo ( n -- 2*n ) 2* ; ok : foo ( n -- 2*n+1 ) foo 1+ ; redefined foo ok 10 foo . 21 ok foo here executed both definitions. Is…
pmg
  • 106,608
  • 13
  • 126
  • 198
5
votes
2 answers

Is there a word for a conditional exit in Forth?

In Forth, is there a common word to conditionally exit a procedure (return) if the top of the stack is zero? I was thinking of using this in recursive procedures instead of IF.
Anthony
  • 410
  • 1
  • 4
  • 8
5
votes
1 answer

How to include a C library in Forth

As default, Forth has only a little amount of working libraries so that everything has to be programmed from scratch. The reason is, that the stackbased Forth virtual machine identifies itself as a slim system. According to the Gforth manual, it's…
Manuel Rodriguez
  • 734
  • 4
  • 18
5
votes
2 answers

GForth: Convert floating point number to String

A simple question that turned out to be quite complex: How do I turn a float to a String in GForth? The desired behavior would look something like this: 1.2345e fToString \ takes 1.2345e from the float stack and pushes (addr n) onto the data stack
nitowa
  • 1,079
  • 2
  • 9
  • 21
1
2 3
8 9