Friday, December 7, 2018

My hero

String handling is not one of Forth strong points. Out-of-the-box support for strings is all but non-existent in standard Forth. Whilst the concept of strings does exist in the language, relatively few words are provided to allow effective string manipulation. The normal approach for Forth programmers is to roll one’s own string functions as required. Issues such as heap allocation and de-allocation, and memory fragmentation are thorny issues which are often passed over in preference for a ‘quick-and-dirty’ solution that solves the problem at hand. This paper presents an Forth-83 Forth compliant library which affords the Forth programmer such facilities as string constants, transient strings, and a wide range of string manipulation words. Issues such as memory allocation, memory de-allocation and memory fragmentation are rendered irrelevant through the provision of a string stack, which is used to host and manipulate transient strings.

Says Mark Wills who created exactly what I need.  Use directly, or adapt is. I was thinking the same, a separate stack for strings if that was his thing. So, great, look into it. I am not sure he is the only one, I have seen code pop up looking like it did the same. We need the simplicity of swapping arg strings around in the arg list, and generating an arg list on a stack of pointers, and just expose it to the console loop. Really simple, totally dangerous.  But it gets us linux command format directly embedded in Forth function methods, ready for exposure.   Even the subsystems get access to the Forth argument manager, across the linux command bus. Sub commands able to convert symbols off the arg list into expanded sequences.

It seems the lib allocates a character, $, as string stack indicator, and does all the standard Forth push and pop as well as a host of great string operations, ideal to generate linux command.

I find some 250 lines of Forth initialization files, really net implementation of the new string stack and a powerful model. We an create more kinds of stacks than just string stacks. I can create a stack of join instances, embed command and control for join right in the system. Or embed  a stack of graphics commands for Xchars and more.  Then Forth has the 'display' methods son stack for rewriting the screen, make an easy message manager for Xchars.


No comments: