Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!unido!cosmo2!gamber@cosmo.UUCP From: gamber@cosmo.UUCP (Johannes Teich) Newsgroups: comp.lang.forth Subject: comma-free arrays Keywords: arrays, counted strings Message-ID: <4076@cosmo2.UUCP> Date: 13 Oct 89 01:34:00 GMT Sender: news@cosmo2.UUCP Reply-To: gamber@cosmo.UUCP (Johannes Teich) Organization: CosmoNet, D-3000 Hannover 1, FRG Lines: 75 Sorry, reading my last message back (only possible at the next session), I detected some wrong characters. They evidently were replaced by CosmoNet. The backslash (hex 5C) echoes as 'V'. The braces (hex 7B and hex 7D) look like 'd' and the vertical bar, respectively. I think it is best to repeat the message without these characters. Sorry. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Forthers, I have two questions concerning 'comma-free' arrays. (Skip 40 lines.:-) If I have to preset a big array, I don't like to use a lot of commas. Instead, I prefer this way: 16 uwarray hex 0001 0002 0004 0008 0010 0020 0040 0080 0100 0200 0400 0800 1000 2000 4000 8000 decimal 16 !uwarray At load time, the 16 values are stacked and then filled into the array. Here are four versions with counted/uncounted arrays of words/bytes: ( variable -2 allot 1 , 2 , 3 , ) ( may be replaced by: 3 uwarray 1 2 3 3 !uwarray ) : uwarray create 0 ?do 0 , loop ; : !uwarray swap 1- 0 swap do tuck i 2* + ! -1 +loop drop ; ( variable -2 allot 1 c, 2 c, 3 c, ) ( may be replaced by: 3 ubarray 1 2 3 3 !ubarray ) : ubarray create 0 ?do 0 c, loop ; : !ubarray swap 1- 0 swap do tuck i + c! -1 +loop drop ; ( variable -2 allot 3 c, 1 , 2 , 3 , ) ( may be replaced by: 3 cwarray 1 2 3 3 !cwarray ) : cwarray create dup c, 0 ?do 0 , loop ; : !cwarray 1- swap 1 swap do tuck i 2* + ! -1 +loop drop ; ( variable -2 allot 3 c, 1 c, 2 c, 3 c, ) ( may be replaced by: 3 cbarray 1 2 3 3 !cbarray ) : cbarray create dup c, 0 ?do 0 c, loop ; : !cbarray swap 1 swap do tuck i + c! -1 +loop drop ; Now my questions are: - is there a better solution to create 'comma-free' arrays? - are there any naming conventions for them? """""""""""""""""" Here is another defining word, creating a 'counted string' array. ( >>>--> In LMI Forth, ) ( variable -2 allot 3 c, ascii a c, ascii b c, ascii c c, ) ( may be replaced by: " abc" $array ) : $array create count dup c, here swap dup allot cmove ; In LMI Forth, the word " (followed by a string) leaves the address of the counted string on the stack. I tried it with Tom Zimmer's F-PC, but the counted string compiles directly to here , with no address on the stack. So it works with variable -2 allot " abc" instead. (In real life, LMI Forth needs capital letters.) Cheers - Johannes Teich Murnau, Bavaria (FRG) +---------------------------------------+------------------------------------+ ! UUCP via CosmoNet: unido!cosmo!gamber ! FidoNet via TBUS-BBS: 2:507/414.20 ! +---------------------------------------+------------------------------------+