Forth utilities?
- From: Frank Buss <fb@xxxxxxxxxxxxx>
- Date: Sun, 29 Apr 2007 13:39:56 +0200
For Lisp there is a collection of small utilities:
http://common-lisp.net/project/cl-utilities/
http://common-lisp.net/project/cl-utilities/doc/
Do you know something like this for Forth? In the spirit of Forth it should
be a collection of small words or code snippets, for combining to bigger
solutions or for modifying to fit similar problems.
One example is a function, which I needed: Create a unicode (only for ASCII
input) string in memory:
\ Parse ccc delimited by " (double-quote) and store the characters as
\ unicode in memory. Return the number of characters stored.
: unicode" ( "ccc<quote>" -- u )
[char] " parse
dup if
tuck ( addr u -- u addr u )
over + swap ( addr u -- addr+u addr )
do
i @ c, 0 c,
loop
else
swap drop
then
;
Usage examples:
here unicode" Hello World!" 2 * dump
44EE52 | 48 00 65 00 6C 00 6C 00 6F 00 20 00 57 00 6F 00 |H.e.l.l.o. .W.o.|
44EE62 | 72 00 6C 00 64 00 21 00 |r.l.d.!.|
3 constant DESC_STRING
: usb-string-descriptor" ( "ccc<quote>" -- )
here 0 c, DESC_STRING c,
unicode"
swap c!
;
here usb-string-descriptor" LPC-2148" 18 dump
43BED0 | 08 03 4C 00 50 00 43 00 2D 00 32 00 31 00 34 00 |..L.P.C.-.2.1.4.|
43BEE0 | 38 00 |8.|
The utilities collection should show good Forth coding style, too, which is
useful if newbies like me wants to learn Forth, and every utility should
have at least one example how to use it.
BTW: Is there already a function for pasting normal strings to memory? I
found just s" , which is defined for compilation mode, only. But this is a
problem, if you need the string as part of an in-memory structure.
--
Frank Buss, fb@xxxxxxxxxxxxx
http://www.frank-buss.de, http://www.it4-systems.de
.
- Follow-Ups:
- Re: Forth utilities?
- From: Coos Haak
- Re: Forth utilities?
- From: Marcel Hendrix
- Re: Forth utilities?
- Prev by Date: Re: Forth and Co - The Return of the Jedi
- Next by Date: Re: Forth utilities?
- Previous by thread: local words?
- Next by thread: Re: Forth utilities?
- Index(es):
Relevant Pages
|