Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline command-line editing in Gforth console

Tags:

forth

gforth

I have just started learning the Forth programming language. I'm using Gforth on Ubuntu. In Gforth interactive console, I want to do indentation but it requires changing line. Enter key didn't work, it executed code. For comparison, for example, when one tests JavaScript code in web browser console, shift+enter change line without executing code. I want something like that. What key should I press? Is there a way other than using text editors like vim? Best.

like image 810
Mitsutoshi Avatar asked Apr 25 '26 16:04

Mitsutoshi


1 Answers

Gforth doesn't support multiline editing (see the manual).

A workaround is to edit a file in your favorite editor in another window and reload this file in Gforth console as:

include /tmp/scratch.fs

An external file can be also edited in Gforth console via a command like:

"vim /tmp/scratch.fs" system

So a one-liner for that is:

"vim /tmp/scratch.fs" system  "/tmp/scratch.fs" included

That can be wrapped into a definition as:

: scratch "vim /tmp/scratch.fs" system  "/tmp/scratch.fs" included ;

So the word scratch will open an editor and than load the edited file.

NB: if you use a quite old build of Gforth, you have to use s" ccc" instead of "ccc" for string literals.

To conditionally include/exclude some parts in a file the words [defined] and [if] can be used; to erase the previous instance of the loaded definitions the word marker can be used as:

[defined] _clear [if] _clear [then]
marker _clear

\ some definitions
\ ...

Take into account that usual control-flow words can be used in definitions only.

like image 155
ruvim Avatar answered Apr 27 '26 06:04

ruvim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!