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: array, counted string Message-ID: <4075@cosmo2.UUCP> Date: 13 Oct 89 00:57:00 GMT Sender: news@cosmo2.UUCP Reply-To: gamber@cosmo.UUCP (Johannes Teich) Organization: CosmoNet, D-3000 Hannover 1, FRG Lines: 67 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: V d variable -2 allot 1 , 2 , 3 , | V may be replaced by: d 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 ; V d variable -2 allot 1 c, 2 c, 3 c, | V may be replaced by: d 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 ; V d variable -2 allot 3 c, 1 , 2 , 3 , | V may be replaced by: d 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 ; V d variable -2 allot 3 c, 1 c, 2 c, 3 c, | V may be replaced by: d 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. V >>>--> In LMI Forth, V d variable -2 allot 3 c, ascii a c, ascii b c, ascii c c, | V may be replaced by: d " abc" $array | : $array create count dup c, here swap dup allot cmove ; In LMI Forth, the word d " | (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 d here |, with no address on the stack. So it works with d 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 ! +---------------------------------------+------------------------------------+