larsbrinkhoff / forth-mode

Wants to be the SLIME of Forth
GNU General Public License v3.0
61 stars 17 forks source link

User-Forth interaction #15

Open larsbrinkhoff opened 7 years ago

larsbrinkhoff commented 7 years ago

I initially wanted something like SLIME. But perhaps it's not quite the right model for interacting with Forth.

In the Lisp mode, every function can be redefined which affects the rest of the program immediately.

But this isn't the case in Forth. Maybe it's better to embrace a model which embraces the stack-like nature of the Forth dictionary. Definitions can be pushed to the dictionary, and popped later.

Reepca commented 7 years ago

I think I see what you mean... we can have a behind-the-scenes MARKER for every word defined, and a command with a nice keybinding that can act as an "undo definition"? I wish there could be an opposite to C-M-x, a sort of "undo current definition", but gforth doesn't support FORGET.

Is that similar to what you had in mind?

I have noticed in my little bit of forth coding that often I'll want to change some definition and then immediately test it with the words that use it, especially after I've located the problem in the lower-level word. What I usually do there is just mark from the start of the definition to the end of the file and then send the entire region. One of the features that SLIME has is the ability to see which functions use a certain function (I think they say it as "who calls"). Would similar functionality be possible here, to find all the words that use this one and then recompile them (or maybe even just change their reference to use the new version)? That would actually be a feature that would be generally useful for a forth system to have, I would think. And then a certain command could be used to send-and-refresh (not used by default, of course, because the hyperstatic global scope thingy is the default case).

On a somewhat unrelated note, it'd be great to have a special buffer that could show the current state of the dictionary at some place, and that would interactively update as it changed. DUMP is nice and all, but it's not quite the same as being able to just browse through the memory and see what happens. And maybe something similar for the stack. I'm not sure how to implement those, though. I guess the simplest thing that could possibly work in my mind would be to insert before-and-after every word some word that keeps emacs updated on the state. I don't suppose any forths have NEXT as a deferred word, do they? ;~)

larsbrinkhoff commented 7 years ago

Yes @Reepca, that's what I have in mind. I'm not sure it's a good idea, I just wanted to jot down a thought.

For your use case, maybe the best solution is to just reload the entire file, using a hidden MARKER to roll back the dictionary. (But then, what if you loaded some other file after the first one?)

Your idea to recompile all call sites of a particular word would be feasible. It's just a long way to get there at the moment.

larsbrinkhoff commented 7 years ago

Interactive display of stack, dictionary, memory, search order etc would be great! A visualisation of the dictionary would make pusing and popping definitions much more usable.

As for how to track the state, see #16.