<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2678811648497643881</id><updated>2011-07-28T22:13:31.728-07:00</updated><category term='ventureforth'/><category term='colorforth'/><category term='windows'/><category term='programming'/><category term='tutorial'/><title type='text'>ColorForth Programming Tutorial</title><subtitle type='html'>A blog to document my efforts on building an online tutorial for the wonderful ColorForth language - operating system.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-327267958587864718</id><published>2010-03-30T19:31:00.000-07:00</published><updated>2010-03-30T19:58:54.476-07:00</updated><title type='text'>Matrix Multiplication example ported to arrayForth</title><content type='html'>&lt;p&gt;I'm going to put up a better description later.  Right now I just want to get this up on the web.  It works!  (Took a while).  The source HTML was generated by the built in arrayForth &lt;a href="http://www.greenarrays.com/home/documents/greg/cf-html-listing.htm"&gt;HTML generator.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To run the code put the following at the top of block 1302:&lt;br /&gt;&lt;br /&gt;0 node 200 load 1 node 204 load 2 node 206 node 3 node 210 load exit&lt;br /&gt;&lt;p&gt;Note that the multicore matrix example is in blocks 200 to 208 and uses nodes 0, 1 and 2.  Block 210 does the same thing with a singlecore (node 3).  The multicore example finishes in 1479 cycles and the singlecore example takes 3040 cycles.  I verified that the multiplications are correct using the statistical language R.  At some point I plan to make a video explaining how this all works, but again right now I just want to get the results up.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tbody&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;code class="t9"&gt;multicore matrix multiplication example&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;a&lt;/code&gt;&lt;code class="df"&gt; 2&lt;/code&gt;&lt;code class="t9"&gt; row by&lt;/code&gt;&lt;code class="df"&gt; 8&lt;/code&gt;&lt;code class="t9"&gt; col matrix is multiplied by&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;a&lt;/code&gt;&lt;code class="df"&gt; 2&lt;/code&gt;&lt;code class="t9"&gt; col by&lt;/code&gt;&lt;code class="df"&gt; 8&lt;/code&gt;&lt;code class="t9"&gt; row matrix&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;resuting in vector r1*c1 r1*c2 r2*c1 r2*c2&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;r1out send vector r1 to right node&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;r2out send vector r2 to down node&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;rtdwn set port to right and down&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;synch dummy write to synchronize nodes&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;c1c2out send vectors c1 and c2 to right&lt;/code&gt;&lt;code class="te"&gt; indent&lt;br /&gt;    &lt;/code&gt;&lt;code class="t9"&gt; and down nodes&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;getres get results from right and down vectors&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;  &lt;/td&gt;&lt;br /&gt;&lt;td&gt;200 list&lt;br /&gt;&lt;br /&gt;&lt;code class="d8"&gt;0&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="t9"&gt; r1out&lt;/code&gt;&lt;code class="t4"&gt; right b!&lt;/code&gt;&lt;code class="d6"&gt; 7&lt;/code&gt;&lt;code class="t4"&gt; for @p !b unext&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;1&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 2&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 3&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 4&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 5&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 6&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 7&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 8&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;r2out&lt;/code&gt;&lt;code class="t4"&gt; down b!&lt;/code&gt;&lt;code class="d6"&gt; 7&lt;/code&gt;&lt;code class="t4"&gt; for @p !b unext&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;9&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 10&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 11&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 12&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 13&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 14&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 15&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 16&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;rtdwn&lt;/code&gt;&lt;code class="h6"&gt; B5&lt;/code&gt;&lt;code class="t4"&gt; b!&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;synch&lt;/code&gt;&lt;code class="d6"&gt; 0&lt;/code&gt;&lt;code class="t4"&gt; !b&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;c1c2out&lt;/code&gt;&lt;code class="d6"&gt; 15&lt;/code&gt;&lt;code class="t4"&gt; for @p !b unext&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;17&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 18&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 19&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 20&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 21&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 22&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 23&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 24&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;25&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 26&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 27&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 28&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 29&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 30&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 31&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 32&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;getres&lt;/code&gt;&lt;code class="t4"&gt; right b! @b @b down b! @b @b r---      &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;code class="t3"&gt;invect&lt;/code&gt;&lt;code class="t9"&gt; a- read in vector and store at a&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;*&lt;/code&gt;&lt;code class="t9"&gt; ab-a*b&lt;/code&gt;&lt;code class="df"&gt; 17&lt;/code&gt;&lt;code class="t9"&gt; bit multiply&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;.prod&lt;/code&gt;&lt;code class="t9"&gt; a-n read in vector and do dot product wi&lt;br /&gt;th vector stored at a&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;r*c1,c2&lt;/code&gt;&lt;code class="t9"&gt; p- read r from port p then read c1 and&lt;br /&gt;c2 and do dot products with r. return results&lt;br /&gt;to port p                                     &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;  &lt;/td&gt;&lt;br /&gt;&lt;td&gt;202 list&lt;br /&gt;&lt;br /&gt;&lt;code class="t3"&gt;invect&lt;/code&gt;&lt;code class="t4"&gt; a!&lt;/code&gt;&lt;code class="d6"&gt; 7&lt;/code&gt;&lt;code class="t4"&gt; for @b !+ unext ;&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;*&lt;/code&gt;&lt;code class="t4"&gt; a! dup dup or&lt;/code&gt;&lt;code class="d6"&gt; 17&lt;/code&gt;&lt;code class="t4"&gt; push . begin +* unext drop&lt;br /&gt;drop a ;&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;.prod&lt;/code&gt;&lt;code class="t4"&gt; a! dup dup or&lt;/code&gt;&lt;code class="d6"&gt; 7&lt;/code&gt;&lt;code class="t4"&gt; for @b @+ a push * + pop&lt;br /&gt;a! next ;&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;r*c1,c2&lt;/code&gt;&lt;code class="t4"&gt; b!&lt;/code&gt;&lt;code class="h6"&gt; 60&lt;/code&gt;&lt;code class="t4"&gt; invect&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;synch&lt;/code&gt;&lt;code class="t4"&gt; @b drop&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="h6"&gt;60&lt;/code&gt;&lt;code class="t4"&gt; .prod&lt;/code&gt;&lt;code class="h6"&gt; 60&lt;/code&gt;&lt;code class="t4"&gt; .prod !b !b ;                     &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;code&gt;                                              &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;  &lt;/td&gt;&lt;br /&gt;&lt;td&gt;204 list&lt;br /&gt;&lt;br /&gt;&lt;code class="d8"&gt;0&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="d8"&gt; 202&lt;/code&gt;&lt;code class="t1"&gt; load&lt;/code&gt;&lt;code class="h8"&gt; 69&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="t4"&gt; right r*c1,c2 r---      &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;code&gt;                                              &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;  &lt;/td&gt;&lt;br /&gt;&lt;td&gt;206 list&lt;br /&gt;&lt;br /&gt;&lt;code class="d8"&gt;0&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="d8"&gt; 202&lt;/code&gt;&lt;code class="t1"&gt; load&lt;/code&gt;&lt;code class="h8"&gt; 69&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="t4"&gt; down r*c1,c2 r---       &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;code&gt;                                              &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;  &lt;/td&gt;&lt;br /&gt;&lt;td&gt;208 list&lt;br /&gt;&lt;br /&gt;&lt;code class="d8"&gt;0&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;*&lt;/code&gt;&lt;code class="t4"&gt; a! dup dup or&lt;/code&gt;&lt;code class="d6"&gt; 17&lt;/code&gt;&lt;code class="t4"&gt; push . begin +* unext drop&lt;br /&gt;drop a ;&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="h8"&gt;69&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="d6"&gt; 3 3&lt;/code&gt;&lt;code class="t4"&gt; * r---                             &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;code class="t9"&gt;singlecore matrix multiplication example&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t3"&gt;*&lt;/code&gt;&lt;code class="t9"&gt; ab-a*b&lt;/code&gt;&lt;code class="df"&gt; 17&lt;/code&gt;&lt;code class="t9"&gt; bit multiplication&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;*sum&lt;/code&gt;&lt;code class="t9"&gt; v2ofs-n vector v1 is stored in a and&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;v2ofs is the offset to vector v2. sum the&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="t9"&gt;products of v1 and v2.                        &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;  &lt;/td&gt;&lt;br /&gt;&lt;td&gt;210 list&lt;br /&gt;&lt;br /&gt;&lt;code class="d8"&gt;0&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;*&lt;/code&gt;&lt;code class="t4"&gt; a push a! dup dup or&lt;/code&gt;&lt;code class="d6"&gt; 17&lt;/code&gt;&lt;code class="t4"&gt; push . begin +* unex&lt;br /&gt;t drop drop a pop a! ;&lt;/code&gt;&lt;code class="t3"&gt;&lt;br /&gt;*sum&lt;/code&gt;&lt;code class="t4"&gt; dup dup or&lt;/code&gt;&lt;code class="d6"&gt; 7&lt;/code&gt;&lt;code class="t4"&gt; for over a + b! @+ @b * + ne&lt;br /&gt;xt push drop pop ;&lt;/code&gt;&lt;code class="h8"&gt; 69&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="h6"&gt;40&lt;/code&gt;&lt;code class="t4"&gt; a!&lt;/code&gt;&lt;code class="h6"&gt; 10&lt;/code&gt;&lt;code class="t4"&gt; *sum&lt;/code&gt;&lt;code class="h6"&gt; 8&lt;/code&gt;&lt;code class="t4"&gt; *sum&lt;/code&gt;&lt;code class="h6"&gt; 40&lt;/code&gt;&lt;code class="t4"&gt; a!&lt;/code&gt;&lt;code class="h6"&gt; 18&lt;/code&gt;&lt;code class="t4"&gt; *sum&lt;/code&gt;&lt;code class="h6"&gt; 10&lt;/code&gt;&lt;code class="t4"&gt; *sum r--&lt;br /&gt;-&lt;/code&gt;&lt;code class="h8"&gt; 40&lt;/code&gt;&lt;code class="t1"&gt; org&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;1&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 2&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 3&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 4&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 5&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 6&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 7&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 8&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;9&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 10&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 11&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 12&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 13&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 14&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 15&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 16&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;17&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 18&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 19&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 20&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 21&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 22&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 23&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 24&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;&lt;/code&gt;&lt;code class="d8"&gt;25&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 26&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 27&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 28&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 29&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 30&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 31&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="d8"&gt; 32&lt;/code&gt;&lt;code class="t1"&gt; ,&lt;/code&gt;&lt;code class="te"&gt; cr&lt;br /&gt;                                              &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-327267958587864718?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/327267958587864718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=327267958587864718' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/327267958587864718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/327267958587864718'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2010/03/matrix-multiplication-example-ported-to.html' title='Matrix Multiplication example ported to arrayForth'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-9216163078876349609</id><published>2009-06-14T04:36:00.000-07:00</published><updated>2009-06-16T19:01:57.100-07:00</updated><title type='text'>Primary ColorForth Chapter 2</title><content type='html'>&lt;span style="font-size:180%;"&gt;First some housekeeping:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Since Starting Forth is based on traditional Forth, there are some examples that won't work out of the box on ColorForth. Most of the required words can be easily implemented such as spaces back in chapter 1. Some words already exist but are not available in interactive mode because they have only been defined in the macro wordlist.  I will define definitions needed for the Starting Forth examples as we go along.  Alternatively here are the new definitions together.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;/mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-qr&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;/mod ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-r&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;mod ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;swap&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-ba&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;swap ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;over&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-aba&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;abc-bca&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push swap pop swap ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2swap&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;abcd-cdab&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push rot rot pop rot rot ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2dup&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-abab&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over over ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2over&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;abcd-abcdab&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push push 2dup pop pop 2swap ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2drop&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;drop drop ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:180%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Forth Arithmetic -- Calculator Style&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Starting Forth identifies the four fundamental arithmetic instructions in traditional Forth are +, -, *, and /.  ColorForth has &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;+&lt;/span&gt;&lt;span style="font-size:130%;"&gt;, &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;*&lt;/span&gt;&lt;span style="font-size:130%;"&gt; and &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;/&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  You might be wondering what happened to &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;-&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  It is a macro that returns the one's complement (the same as &lt;a href="http://www.forth.org/ansforth/node2.html#SECTION00020000000000000000"&gt;invert&lt;/a&gt; in ANS Forth).  This corresponds to the way &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;-&lt;/span&gt;&lt;span style="font-size:130%;"&gt; is used in Charles Moore's MISC processors since MuP21.  You can still subtract by adding the negative.  For constants just use the negative value.  For variables or calculated results you can get the negative using &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;NEGATE&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.&lt;br /&gt;&lt;br /&gt;Starting Forth then gives several examples of postfix math.  Note as mentioned in chapter 2, in ColorForth you don't need to use &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;.&lt;/span&gt;&lt;span style="font-size:130%;"&gt; in interactive mode except as a shortcut for &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;drop&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  You can also clear the entire stack using &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;c&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  ColorForth continuously displays the parameter stack in the lower left of the screen.  Try the following:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;17 5 +&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;7 8 *&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;3 4 +&lt;br /&gt;500 -300 +&lt;br /&gt;5 6 *&lt;br /&gt;20 4 /&lt;br /&gt;c&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;An example of adding multiple numbers:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;17 20 + 132 + 3 + 9 + .&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Converting infix expressions to postfix (quizzie 2-a)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Here is a little trick I learned as a computer science undergraduate.  Fully parenthesize your expression and move all operators to the end of the corresponding parenthesis.  Examples:&lt;br /&gt;&lt;br /&gt;c(a + b) =&gt; (c*(a+b)) =&gt; (c(a b)+)* =&gt; c a b + *&lt;br /&gt;&lt;br /&gt;a*b/100 =&gt; ((a * b)/100) =&gt; ((a b)*100)/ =&gt; a b * 100 /&lt;br /&gt;&lt;br /&gt;Try the following on your own:&lt;br /&gt;&lt;br /&gt;(3a - b)/4 + c&lt;br /&gt;&lt;br /&gt;(a + 1)/4&lt;br /&gt;&lt;br /&gt;x(7x + 5)&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Forth Arithmetic -- Definition Style&lt;/span&gt;&lt;span style="font-size:180%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;The next examples are for converting from yards or feet to inches.  We know 1 yard = 36 inches and 1 foot = 12 inches.  Here is the conversion code:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;yards-inches&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;36 * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;feet-inches&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;12 * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Usage example:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;10 yards-inches&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;2 feet-inches&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;If we always want results to be in inches, we can define:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;yards&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;36 * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;feet&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;12 * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;inches&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;to get the phrase&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;10 yards 2 feet + 9 inches +&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Now perhaps you want to be able to use singular or plural words for better readability.  Starting Forth used the following code:&lt;br /&gt;&lt;br /&gt;: yard yards ;&lt;br /&gt;: foot feet ;&lt;br /&gt;: inch ;&lt;br /&gt;&lt;br /&gt;That has the undesiable effect of adding an extra word call just for the sake of readability.  ColorForth can do the same without the overhead using &lt;a href="http://primarycolorforth.blogspot.com/2009/06/fall-through-factoring.html"&gt;fall through factoring&lt;/a&gt;.  The same definition can have multiple entry points.  So in ColorForth you can define:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;yard&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;yards&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;36 * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;foot&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;feet&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;12 * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;inch&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;inches&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Note that yard and yards, foot and feet, inch and inches all point to the same memory location.&lt;br /&gt;&lt;br /&gt;Now let's consider the earlier example of adding 5 numbers together.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;17 20 + 132 + 3 + 9 + &lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;The same thing could be accomplished by moving the &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;+&lt;/span&gt;&lt;span style="font-size:130%;"&gt;'s to the end.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;17 20 132 3 9 + &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;+ &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;+ &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;+&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Changing this to a definition we get:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;5sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;+ + + + ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Now say if in the same program sometimes we needed to add 5 numbers together and sometimes we needed to add 3?  We could use &lt;a href="http://primarycolorforth.blogspot.com/2009/06/fall-through-factoring.html"&gt;fall through factoring&lt;/a&gt; here.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;5sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;+ +&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;3sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;+ + ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;This time &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;5sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt; and &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;3sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt; point to different locations in memory.  If you call &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;5sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt; it does the first 2 additions and then "falls through" to the remaining 2 additions in &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;3sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  If you call &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;3sum&lt;/span&gt;&lt;span style="font-size:130%;"&gt; it just does the required 2 additions and returns.&lt;br /&gt;&lt;br /&gt;An equation for another definition:&lt;br /&gt;&lt;br /&gt;(a + b) * c&lt;br /&gt;&lt;br /&gt;In postfix:&lt;br /&gt;&lt;br /&gt;a b + c *&lt;br /&gt;&lt;br /&gt;Alternatively we could say:&lt;br /&gt;&lt;br /&gt;c * (a + b)&lt;br /&gt;&lt;br /&gt;In postfix:&lt;br /&gt;&lt;br /&gt;c a b + *&lt;br /&gt;&lt;br /&gt;from which we can write the definition:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;solution&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;+ * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;It's a good time to point out that in Forth it's sometimes better to re-write an equation to make it easier to manipulate on the parameter stack.  Here is the same code as a word problem:&lt;br /&gt;&lt;br /&gt;If a jet plane flies at an average air speed of 600 mph and if it flies with a tail wind of 25 mph, how far will it travel in five hours?&lt;br /&gt;&lt;br /&gt;If we define:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;flight-dist&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;+ * ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;we could enter &lt;/span&gt;&lt;span style="color: rgb(255, 255, 51);font-size:130%;" &gt;5 600 25 flight-dist&lt;/span&gt;&lt;span style="font-size:130%;"&gt; and get 3125 on the top of the stack.&lt;br /&gt;&lt;br /&gt;Try it with different values, including head winds (negative values).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;The Division Operators&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;The basic division in ColorForth (and traditional Forth as well) is &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;/&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  This is an interger operator which discards the remainder.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;22 5 /&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;This leaves 4 on the stack.  There are two other division operators, &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; and &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;/mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  By default they are in the macro wordset and only available during compilation.  However they can be compiled to the Forth wordset.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-r&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;mod ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt; returns the remainder&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;/mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-qr&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;/mod ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt; returns quotient and remainder&lt;br /&gt;&lt;br /&gt;Testing &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;/mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; interactively: &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;22 4 /mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;2 5&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;br /&gt;We can define a word quarters that takes a number of quarters and calculates the dollars and leftover quarters.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;126 load&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;q&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;quarters&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;ones&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ones&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;quarters&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;4 /mod .&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;q&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.s .&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;ones&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;go&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show blank text&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;22&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;quarters ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Test &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; interactively: &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;22 4 mod&lt;/span&gt;&lt;span style="font-size:130%;"&gt; leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;2&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Stack Manipulation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;Swap&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;As the name suggests, this word takes the top too numbers on the stack and swaps them.  Again this word is only in the macro wordlist.  To use it interactively:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;swap&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;swap ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Testing this interactively: &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;1 2 swap&lt;/span&gt;&lt;span style="font-size:130%;"&gt; leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;2 1&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;Dup&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Dup takes the top number on the stack and duplicates it.  &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;2 dup&lt;/span&gt;&lt;span style="font-size:130%;"&gt; leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;2 2&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;br /&gt;You can use dup to square a number.  &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;4 dup *&lt;/span&gt;&lt;span style="font-size:130%;"&gt; leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;16&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;Over&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Over is defined only in the macro wordlist.  To use it interactively define:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;over&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Over takes the second item on the stack and copies it to the top of the stack.&lt;br /&gt;&lt;br /&gt;Testing it interactively, &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;1 2 over&lt;/span&gt;&lt;span style="font-size:130%;"&gt; leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;1 2 1&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;br /&gt;Thus the expression&lt;br /&gt;&lt;br /&gt;a * (a + b)&lt;br /&gt;&lt;br /&gt;can be written as:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;over * +&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;Rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Rot is in traditional Forth but is not by default defined in ColorForth.  However defining it is simple.  It requires a the words &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push&lt;/span&gt;&lt;span style="font-size:130%;"&gt; and &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;pop&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  These words manipulate the second stack called the "return stack".  Starting Forth doesn't cover this until another chapter.  Basically &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push&lt;/span&gt;&lt;span style="font-size:130%;"&gt; takes the top number from the parameter stack and moves it to the return stack.  &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;pop&lt;/span&gt;&lt;span style="font-size:130%;"&gt; does the opposite.  Using them &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt; is defined as:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push swap pop swap ;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;Rot takes the 3rd item on the stack and rotates it to the top.&lt;br /&gt;&lt;br /&gt;Testing it interactively: &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;1 2 3 rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt; leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;2 3 1&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;br /&gt;Say if you wanted to evaluate the expression &lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;ab - bc&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  First factor out the b's.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;b*(a - c)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Now starting with &lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;c b a&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack we can use &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;rot - *&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;Drop&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Drop, as its name suggests, drops the top item on the stack.  Testing interactively: &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;1 2 drop &lt;/span&gt;&lt;span style="font-size:130%;"&gt;leaves &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;1&lt;/span&gt;&lt;span style="font-size:130%;"&gt; on the stack.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-size:130%;"&gt;Note: Look ma!  No .s.  Starting Forth mentions at this point that .s can be used to display the stack non destructively.  But ColorForth shows the stack in interactive mode at the bottom left of the screen.  Thus .s is not needed and not defined.  Hence I can use &lt;span style="color: rgb(51, 255, 51);"&gt;.s&lt;/span&gt; is ColorForth for printing strings.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Stack Manipulation and Math Definitions (Quizzie 2-c)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;1. Write a phrase which flips three items on the stack, leaving the middle number in the middle;          that is:&lt;br /&gt;&lt;br /&gt;a b c  ==&gt; c b a&lt;br /&gt;&lt;br /&gt;Answer: &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;swap rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;2. Write a phrase that does what &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over&lt;/span&gt;&lt;span style="font-size:130%;"&gt; does, without using &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;Answer: &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;swap dup rot rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;3. Write a definition called &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;-rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt;, which rotates the top three stack          items in the opposite direction from &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;rot&lt;/span&gt;&lt;span style="font-size:130%;"&gt;; that is:&lt;br /&gt;&lt;br /&gt;a b c ==&gt; c a b&lt;/span&gt;&lt;span style=";font-family:monospace;font-size:130%;"  &gt;&lt;br /&gt;&lt;br /&gt;Answer: &lt;span style="color: rgb(255, 0, 0);"&gt;-rot&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;rot rot ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Write definitions for the following:&lt;br /&gt;&lt;br /&gt;4. (n+1) / n&lt;br /&gt;&lt;br /&gt;Answer: &lt;span style="color: rgb(255, 0, 0);"&gt;2c4&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;dup 1 + swap / ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;5. x(7x + 5)&lt;br /&gt;&lt;br /&gt;Answer: &lt;span style="color: rgb(255, 0, 0);"&gt;2c5&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;dup 7 * 5 + * ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;6. &lt;/span&gt;&lt;span style="font-size:130%;"&gt;9a&lt;sup&gt;2&lt;/sup&gt; - ba&lt;br /&gt;&lt;br /&gt;a(9a - b)&lt;br /&gt;&lt;br /&gt;Answer: &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2c6&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over 9 * swap - * ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Playing Doubles&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Many early Forths ran on 16 bit computers.  As such "double" words, which allowed 32 bit math, were very important.  ColorForth was initially written for a 32 bit computer and thus does not implement double words.  However double stack manipulation words are not difficult to write.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2swap&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;abcd-cdab&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push rot rot pop rot rot ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2dup&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-abab&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over over ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2over&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;abcd-abcdab&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;push push 2dup pop pop 2swap ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;2drop&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;ab-&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;drop drop ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Problems -- Chapter 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;1. What's the difference between DUP DUP and 2DUP?&lt;br /&gt;&lt;br /&gt;2. Write a phrase which will reverse the order of the top four items on the stack; that is,&lt;br /&gt;&lt;br /&gt;       ( 1 2 3 4 -- 4 3 2 1 )&lt;br /&gt;&lt;br /&gt;Answer: &lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;reverse&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;swap 2swap swap ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;3. Write a definition called 3DUP which will duplicate the top three numbers on the stack; for example,&lt;br /&gt;&lt;br /&gt;Answer: &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;3dup&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;abc-abcabc&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;dup 2over rot ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;   Write definitions for the following infix equations, given the stack effects shown:&lt;br /&gt;4. a&lt;sup&gt;2&lt;/sup&gt; + ab + c ( c a b -- result )&lt;br /&gt;&lt;br /&gt;a(a + b) + c&lt;br /&gt;&lt;br /&gt;Answer: &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;prob4&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;over + * + ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;5. (a-b) / (a+b) ( a b -- result ) [answer]&lt;br /&gt;&lt;br /&gt;Answer: &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;prob5&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;2dup  - -rot + / ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;6. Write a set of words to compute prison sentences for hardened criminals such that the judge can enter:&lt;br /&gt;&lt;br /&gt;       CONVICTED-OF ARSON HOMICIDE TAX-EVASION ok&lt;br /&gt;       WILL-SERVE 35 years ok&lt;br /&gt;&lt;br /&gt;   or any series of crime beginning with the word CONVICTED-OF and ending with WILL-SERVE. Use these sentences&lt;br /&gt;&lt;br /&gt;       HOMICIDE    20 years&lt;br /&gt;       ARSON        10 years&lt;br /&gt;       BOOKMAKING     2 years&lt;br /&gt;       TAX-EVASION     5 years&lt;br /&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;126 load&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;years&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;years&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;convicted-of&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0 ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;homicide&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;20 + ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;arson&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;10 + ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;bookmaking&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;2 + ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;tax-evasion&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;5 + ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;will-serve&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;years&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show blank text convicted-of homicide arson tax-evasion will-serve ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;7. You're the inventory programmer at Maria's Egg Ranch. Define a word called EGG.CARTONS which expects on the stack the total number of eggs laid by the chickens today and prints out the number of cartons that can be filled with a dozen each, as well as the number of left-over eggs.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;126 load&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;cartons&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;cartons&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;eggs&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;eggs&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;egg.cartons&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(192, 192, 192);font-size:130%;" &gt;e-cr&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;12 /mod .&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;cartons&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.s .&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;eggs&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show blank text 55 egg.cartons ;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-9216163078876349609?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/9216163078876349609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=9216163078876349609' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/9216163078876349609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/9216163078876349609'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2009/06/primary-colorforth-chapter-2.html' title='Primary ColorForth Chapter 2'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-5765196369420858513</id><published>2009-06-14T01:46:00.000-07:00</published><updated>2009-06-14T13:54:34.544-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Fall through factoring</title><content type='html'>&lt;span style="font-size:130%;"&gt;The idea is that you can have multiple entry points to the same word.  Here's an example.  Say if you needed code for shifting right twice (4 *) and shifting right3 times (8 *).  You could code that without factoring as:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;4*&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;2* 2* ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;8*&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;2* 2* 2* ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You could also code it using traditional factoring as:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;4*&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;2* 2* ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;8*&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;2* 4* ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Using fall through factoring that becomes:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;8*&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;2*&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;4*&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;2* 2* ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;With fall through factoring &lt;span style="color: rgb(255, 0, 0);"&gt;8*&lt;/span&gt; doesn't have the overhead of having to call &lt;span style="color: rgb(51, 255, 51);"&gt;4*&lt;/span&gt;, but you still get the code density benefit of having &lt;span style="color: rgb(255, 0, 0);"&gt;4*&lt;/span&gt; factored out.  Fall through factoring can also be used to increase code readability without added overhead.  Consider the example from Starting Forth chapter 2.&lt;br /&gt;&lt;br /&gt;: YARDS 36 * ;&lt;br /&gt;: FEET 12 * ;&lt;br /&gt;: INCHES ;&lt;br /&gt;&lt;br /&gt;: YARD YARDS ;&lt;br /&gt;: FOOT FEET  ;&lt;br /&gt;: INCH INCHES ;&lt;br /&gt;&lt;br /&gt;The only reason for yard, foot and inch is readability.  Here is the same result using fall through factoring.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;yard&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;yards&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;36 * ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;foot&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;feet&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;12 * ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;inch&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;inches&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note that there is now no overhead for &lt;span style="color: rgb(255, 0, 0);"&gt;yard&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;foot&lt;/span&gt;, or &lt;span style="color: rgb(255, 0, 0);"&gt;inch&lt;/span&gt; being their own separate words.  Each word is a separate label for the same code address.  In traditional Forth the words yard, foot and inch all have the overhead of making a call to their plural versions.  Some traditional Forths have a word &lt;span style="font-style: italic;"&gt;alias&lt;/span&gt; that can give a similar result as this last example, but that's not standard.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-5765196369420858513?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/5765196369420858513/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=5765196369420858513' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/5765196369420858513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/5765196369420858513'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2009/06/fall-through-factoring.html' title='Fall through factoring'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-1235243949755899709</id><published>2009-06-13T09:22:00.000-07:00</published><updated>2009-06-16T19:38:29.536-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Typing ColorForth 4.1</title><content type='html'>&lt;span style="font-size:130%;"&gt;Well I thought I had done my last post on "typing ColorForth" at &lt;a href="http://primarycolorforth.blogspot.com/2009/05/typing-colorforthversions-31-and-40.html"&gt;version 4.0&lt;/a&gt;.  That version does everything I want.  However it doesn't quite do it the way I wanted it to.  I took code I &lt;a href="http://qualdan.com/colorforth/stype.html"&gt;found on the web&lt;/a&gt; that types comment text to the screen, modified it to use &lt;a href="http://primarycolorforth.blogspot.com/2009/05/colorforth-20-gotchawindows-version.html"&gt;yellow "immediate" mode for accessing variables&lt;/a&gt;, and then factored the word ".s" (stype in the original version) using inline macros.  At least I &lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;thought&lt;/span&gt;&lt;span style="font-size:130%;"&gt; I was using inline macros.  The reason is that I wanted to make it clear what .s does.  Again the code from the original stype.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;stype&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;1 + dup @ dup 15 and select stype ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Anyone who understands ColorForth's tail recursion feature can tell what &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;stype ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt; does.  And &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;select &lt;/span&gt;&lt;span style="font-size:130%;"&gt;is explained in the shadow block comments.  But what does &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;1 + dup @ dup 15&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;/span&gt; and&lt;/span&gt;&lt;span style="font-size:130%;"&gt; do?  Not obvious is it? &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt; 1 + dup @ dup&lt;/span&gt;&lt;span style="font-size:130%;"&gt; increments then retrieves from the string address.  &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;15 and&lt;/span&gt;&lt;span style="font-size:130%;"&gt; gets the tag value.  You can factor that out those two phrases as "&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;nextw&lt;/span&gt;&lt;span style="font-size:130%;"&gt;" and "&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;tag&lt;/span&gt;&lt;span style="font-size:130%;"&gt;", but that doesn't do anything for code density in this case because the words are only used once yet you still have the penalty (albeit small) of the extra call.&lt;br /&gt;&lt;br /&gt;So I thought about trying to inline it using &lt;/span&gt;&lt;span style="color: rgb(51, 204, 255);font-size:130%;" &gt;cyan&lt;/span&gt;&lt;span style="font-size:130%;"&gt; words.  My thought was that I could define the words inside the &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;macro&lt;/span&gt;&lt;span style="font-size:130%;"&gt; wordlist and then use them as cyan words in the normal &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;forth&lt;/span&gt;&lt;span style="font-size:130%;"&gt; wordlist and everything would be inlined.  I'd get the readability improvement from factoring without the overhead.&lt;br /&gt;&lt;br /&gt;On retrospect I believe my understanding of cyan words was not right.  &lt;/span&gt;&lt;span style="color: rgb(102, 204, 204);font-size:130%;" &gt;Cyan&lt;/span&gt;&lt;span style="font-size:130%;"&gt; should be used inside &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;macro&lt;/span&gt;&lt;span style="font-size:130%;"&gt; wordlist and not the forth wordlist.  I believe the result of using cyan for a word defined as a macro is that a call was inserted instead of inline code.&lt;br /&gt;&lt;br /&gt;Now I'm not sure if this is right either.  But there is a better way to get the results I want.  One of the key features of ColorForth is &lt;a href="http://primarycolorforth.blogspot.com/2009/06/fall-through-factoring.html"&gt;fall through factoring&lt;/a&gt;.  The idea is that you can have multiple entry points to the same word.  Using fall through factoring I can rewrite &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.s&lt;/span&gt;&lt;span style="font-size:130%;"&gt; as this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;jump rest done done done done done done done done norm cap caps done done done done ;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.s&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;nextw&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;1 + dup @ dup&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;tag&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(0, 153, 0);"&gt;f&lt;/span&gt; and select .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;I can now document nextw and tag in the corresponding shadow block.  Again, the entire code.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;space&lt;/span&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;fffffff0&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;and unpack &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; @ + emit&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;unpack if &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; @ + emit rest ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;done&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;drop drop pop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;norm&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;!&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;cap&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;caps&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;jump rest done done done done done done done done norm cap caps done done done done ;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;.S&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;nextw&lt;/span&gt; 1 + dup @ dup&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;tag&lt;/span&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;f&lt;/span&gt; and select .s ;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;And the shadow block:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;w&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;display one 32-bit word of text&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;w&lt;/span&gt; finish typing a word&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;done&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;aw&lt;/span&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;drop addr and word and return from stype&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;norm&lt;/span&gt; normal text&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;cap&lt;/span&gt; text starts with a capital&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;caps&lt;/span&gt; all caps&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;wt&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;handle word according to tag&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;.s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;a&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;display contiguous white text&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;nextw&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;a&lt;/span&gt; get next word and increment address&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;tag&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;n&lt;span style="color: rgb(204, 204, 204);"&gt; get tag field from word.  used by select.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;The usage remains the same.  "Hello World" in 2 lines of ColorForth.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;126 load&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;hello&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;Hello World, I speak ColorForth&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;show blank text&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;hello&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;.s ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note: This will probably be the last version of Typing ColorForth (at least I hope so).  It does (almost*) everything I want it to do as is as efficient and readable as I can make it.  To the critics (well meaning I'm sure) who don't understand why I was doing this, please look at the rest of the Primary ColorForth tutorial.  Doing all of the examples in Starting Forth by looking up codes and "emitting" them would be an unecessary pain in the butt.  And yes, I could just type in "Hello World" on a blank screen, but that would not be flexible enough for what I'm doing.&lt;br /&gt;&lt;br /&gt;(* There is one other thing I'd like to do.  The current version sticks in an extra space before typing anything.  Sometimes this throws the formatting off.  But I'm going to quibble about that...for now.)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-1235243949755899709?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/1235243949755899709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=1235243949755899709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/1235243949755899709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/1235243949755899709'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2009/06/typing-colorforth-41.html' title='Typing ColorForth 4.1'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-9012673496705593793</id><published>2009-06-03T04:21:00.000-07:00</published><updated>2009-06-14T04:29:16.748-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Primary ColorForth Chapter 1</title><content type='html'>&lt;span style="font-size:130%;"&gt;As mentioned in the intro, Primary ColorForth is loosely based on &lt;a href="http://home.iae.nl/users/mhx/sf1/sf1.html"&gt;Starting Forth&lt;/a&gt;.  You can follow along in it for this tutorial series either with a hardcopy version or online.&lt;br /&gt;&lt;br /&gt;Starting Forth chapter 11 starts by describing a way of organizing work by defining useful tasks and giving them a name, then grouping tasks together into larger tasks and naming them.&lt;br /&gt;&lt;br /&gt;It gives the example of an embedded washing machine program which we will explore.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Washing Machine Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Here is the top level washing machine program in ColorForth.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;washer&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;wash spin rinse spin ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;In ColorForth red words signify the start of a new definition.  So &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;washer&lt;/span&gt;&lt;span style="font-size:130%;"&gt; is the new procedure. The ";" represents the call return.  Green words are ones that have already been defined and are compiled into the new definition.  Note that unlike traditional Forth words cannot be defined from the command line.  All words must be defined in the &lt;a href="http://www.ultratechnology.com/editor/editor.htm"&gt;editor&lt;/a&gt;. Then the block containing the source text must be loaded. For example, to define new words in block 22 you would use &lt;/span&gt;&lt;span style="color: rgb(255, 255, 102);font-size:130%;" &gt;22 edit&lt;/span&gt;&lt;span style="font-size:130%;"&gt;, then to compile then you would use &lt;/span&gt;&lt;span style="color: rgb(255, 255, 102);font-size:130%;" &gt;22 load&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Let's look at the definition of &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;rinse&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;red style="color: rgb(255, 0, 0);"&gt;rinse&lt;/red&gt;&lt;green&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;fill agitate drain ;&lt;/span&gt;&lt;/green&gt;&lt;br /&gt;&lt;br /&gt;And now the definition of &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;fill&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;red style="color: rgb(255, 0, 0);"&gt;fill&lt;/red&gt;&lt;green&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;faucets open till-full faucets close ;&lt;/span&gt;&lt;/green&gt;&lt;br /&gt;&lt;br /&gt;The definition includes "things" (faucets) and verbs (open and close). The word "till-full" represents a delay loop. After the faucets "open" the word waits "till-full" before they "close".&lt;br /&gt;&lt;br /&gt;Every word must be defined before it can be compiled into a definition, so &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;fill&lt;/span&gt;&lt;span style="font-size:130%;"&gt; must be compiled before &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;rinse&lt;/span&gt;&lt;span style="font-size:130%;"&gt; and &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;rinse&lt;/span&gt;&lt;span style="font-size:130%;"&gt; must be compiled before &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;washer&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;red style="color: rgb(255, 0, 0);"&gt;fill&lt;/red&gt;&lt;green&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;faucets open till-full faucets close ;&lt;/span&gt;&lt;/green&gt;&lt;br /&gt;&lt;red style="color: rgb(255, 0, 0);"&gt;rinse&lt;/red&gt;&lt;green&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;fill agitate drain ;&lt;/span&gt;&lt;/green&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;washer&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;wash spin rinse spin ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;This system is just an example.  For a real system the definitions for open, close, faucets, till-full, agitate, drain and spin would all have to be defined.  At some point it would be direct machine code to activate stepper motors, read sensors etc.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-size:180%;"&gt;Putting On a Show&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Forth was originally designed around a TTY display model. But ColorForth uses a GUI display, albeit one that is MUCH simpler than MS Windows, X-Windows or MacIntosh. So getting things displayed on the screen is a bit tricker than traditional Forth, but simpler than raw programming of most GUI operating system. The ColorForth word &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show&lt;/span&gt;&lt;span style="font-size:130%;"&gt; creates a display task using the words following it.&lt;br /&gt;&lt;br /&gt;Consider this definition.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;show text 93 emit keyboard ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;This creates a new definition &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; that draws a "*" at the top left corner of the screen.  The word &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;text&lt;/span&gt;&lt;span style="font-size:130%;"&gt; moves the cursor to the top left of the screen and sets the drawing color to white. The word &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;emit&lt;/span&gt;&lt;span style="font-size:130%;"&gt; takes a number off the stack and draws the corresponding charecter. It's the same as emit in traditional Forth. Note that the character set is different from ASCII. You can look up the characters in a code map, or you can use the command &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;icons&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  The word &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;keyboard&lt;/span&gt;&lt;span style="font-size:130%;"&gt; redraws the keyboard and stack.&lt;br /&gt;&lt;br /&gt;Chapter 1 of Starting Forth builds up an example on how to draw the letter "F" as a large character using "ASCII art". Here is a walkthrough of that example using colorForth.&lt;br /&gt;&lt;br /&gt;First we need to define the word &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;spaces&lt;/span&gt;&lt;span style="font-size:130%;"&gt; which is built into traditional Forth.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;spaces&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;for space next ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Note ColorForth uses &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;for...next&lt;/span&gt;&lt;span style="font-size:130%;"&gt; for its counted loop structure.  Using &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;spaces&lt;/span&gt;&lt;span style="font-size:130%;"&gt; with what we learned earlier we can code the following:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;spaces&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;for space next ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show text 15 spaces 93 emit ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Notice when we run this,  the word &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;spaces&lt;/span&gt;&lt;span style="font-size:130%;"&gt; doesn't erase the text already on the screen, but just moves the star over.  That's another example of how graphical CF is different from TTY TF.&lt;br /&gt;&lt;br /&gt;Now let's define &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;star&lt;/span&gt;&lt;span style="font-size:130%;"&gt; as it's own word.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;spaces&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;for space next ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;star&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;93 emit ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;go&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show text 15 spaces star ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Moving sections of code into their own definitions is called factoring.  Factoring is used to increase readability and/or code density.&lt;br /&gt;&lt;br /&gt;The next words define the "F" using combinations of the above defined words. Note that "cr" stands for "carriage return". That simply moves the cursor to the next line.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;side &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;star spaces star ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;margin&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;cr 30 spaces ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;blip &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;margin star ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;bar &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;margin 5 stars ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;f&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;bar blip bar blip blip cr ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;show text f keyboard ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;After loading the block containing these words and typing &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; from the command line a large "F" will be displayed on the screen.&lt;br /&gt;&lt;span style="font-size:180%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;Hello World from ColorForth&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The next Starting Forth example is a variation on the venerable "Hello World" program.  This particular program has cause some needless controvery and confusion over the years.  Sure you &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;emit&lt;/span&gt;&lt;span style="font-size:130%;"&gt; each character one at a time, but that's not the most readable solution nor the most flexible.  ColorForth can type blocks of text just like traditional Forth.  And since ColorForth is extensible, just like traditional Forth is extensible, you extend it to where you can do a program like "Hello World" in just two lines.&lt;br /&gt;&lt;br /&gt;First you have to understand how text is stored in the ColorForth editor.  ColorForth doesn't store ASCII characters in bytes.  Instead it packs several characters in one 32 bit word using Shannon encoding, eabling it to store 5 to 7 characters plus a color token in one word.  ColorForth includes a word &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;unpack&lt;/span&gt;&lt;span style="font-size:130%;"&gt; for decompressing such words.  We have already discussed &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;red&lt;/span&gt;&lt;span style="font-size:130%;"&gt; and &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;green&lt;/span&gt; words.  ColorForth uses &lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;white&lt;/span&gt;&lt;span style="font-size:130%;"&gt; words for comments.  Comments can be as all lowercase, all upper case, or mixed case.  So one way to display a block of text is to store it as comments in a Forth block, put that address on the stack, and then unpack and properly display the words until a non comment word is reached.  &lt;a href="http://primarycolorforth.blogspot.com/2009/05/typing-colorforthversions-31-and-40.html"&gt;Here is the code&lt;/a&gt; to set this up:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;space&lt;/span&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;fffffff0&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;and unpack +first @ + emit&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;unpack if +rest @ + emit rest ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;done&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;drop drop pop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;norm&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;!&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;cap&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;caps&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;jump rest done done done done done done done done norm cap caps done done done don&lt;span style="font-family:Georgia,serif;"&gt;e ;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;.s&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;nextw&lt;/span&gt; 1 + dup @&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;tag&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup &lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;15 and select &lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;.s ;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;That may look like a lot, but realize that you can load this block whenever you need it or you can even have it load automatically when ColorForth boots.  Here is an example of its usage (assuming the code was stored in block 126).&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;126 load&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;s&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Hello world, I speak ColorForth&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show text&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;s&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Note that magenta words like &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;s&lt;/span&gt;&lt;span style="font-size:130%;"&gt; define variables.  Variables in ColorForth point to the blocks where they are defined as opposed to the dictionary.  So &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;s &lt;/span&gt;&lt;span style="font-size:130%;"&gt;is being used here to point to the comment block of text we want to type.&lt;br /&gt;&lt;span style="font-size:180%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-size:180%;"&gt;Run-time Versus Compile-time Versus Edit Time&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Starting Forth then goes into a discussion about "run time versus compile time".  This is a good time (no pun intended) to go into the other color states in ColorForth.  We've already gone over how &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;red&lt;/span&gt;&lt;span style="font-size:130%;"&gt; defines a new word and how &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;green&lt;/span&gt;&lt;span style="font-size:130%;"&gt; compiles a previously defined word into a new definition.  Green words are executed at run time.  There are also &lt;/span&gt;&lt;span style="color: rgb(255, 255, 102);font-size:130%;" &gt;yellow&lt;/span&gt;&lt;span style="font-size:130%;"&gt; words that are executed at compile time.  Consider the "hello world" example given earlier.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;126 load&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;s&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Hello world, I speak ColorForth&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show text&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;s&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;.s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Note the phrase &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;126 load&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.  This will load the text display code in block 126 as soon as the current block is loaded.  You don't have to wait until &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; is run.  Also note that the acess to the variable &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;s&lt;/span&gt;&lt;span style="font-size:130%;"&gt; is in yellow too.  A variable is really just a name for an address.  Why wait until run time to look up the address?  Why not look it up at compile time and compile the address directly into the code?  Accessing variables as &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;yellow&lt;/span&gt;&lt;span style="font-size:130%;"&gt; words instead of &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;green&lt;/span&gt;&lt;span style="font-size:130%;"&gt; ones accomplishes that.  In fact that is the &lt;a href="http://www.blogger.com/post-edit.g?blogID=2678811648497643881&amp;amp;postID=8366777699996688739"&gt;preferred way&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Another way to use yellow words are with constants.  When a constant is coded in yellow its value is compiled into the code on the yellow to green transition.  This is also true for calculations that are done in yellow.  Using the earlier "big F" exampe:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;side &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;star spaces star ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;margin&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;cr &lt;span style="color: rgb(255, 255, 0);"&gt;30&lt;/span&gt; spaces ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;blip &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;margin star ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;bar &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;margin &lt;span style="color: rgb(255, 255, 0);"&gt;5&lt;/span&gt; stars ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;f&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;bar blip bar blip blip cr ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;ok&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;show text f keyboard ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Yellow words can also be used to do calculations that can be determined at compile time such as calculations based on a constant.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(102, 204, 204);font-size:130%;" &gt;Cyan&lt;/span&gt;&lt;span style="font-size:130%;"&gt; words are used to create inline macros.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;The Dictionary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;ColorForth, like traditional Forth, stores definitions in a dictionary.  One difference is the way ColorForth handles numbers.  In traditional Forth the interpreter first looks in the dictionary find a word and if it's not found it checks to see if it is a number.  The ColorForth &lt;a href="http://www.ultratechnology.com/editor/editor.htm"&gt;editor&lt;/a&gt; handles numbers differently.  So the compiler never has to check to see if something is really a number.&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;The Stack: Forth's Worksite for Arithmetic&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you are already familiar with Forth (or with HP scientific calculators) you know you to use the stack.  If not here's a brief overview.  Everytime a number is entered it is pushed on the stack.  Forth arithmetic words will take numbers off the stack, do some operation with them, and return the results to the stack.  To do 3 + 4 you must first push the 3 and the 4 to the stack then execute the "+" word.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 51);font-size:130%;" &gt;3 4 +&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Note that the current state of the stack is shown on the bottom left of the screen.  If you use the dot command &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;.&lt;/span&gt;&lt;span style="font-size:130%;"&gt; by itself all you will notice is that one number drops off.  In traditional Forth &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;.&lt;/span&gt; displays the top number on the stack.&lt;span style="font-size:130%;"&gt;  If you use &lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;.&lt;/span&gt;&lt;span style="font-size:130%;"&gt; inside of a &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;show&lt;/span&gt;&lt;span style="font-size:130%;"&gt; word you get the traditional result.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;go&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;show 3 4 + . ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;Problems&lt;br /&gt;&lt;br /&gt;Problem 1-1: Define a word called gift that, when executed, will type out the name of some .gift, a word .giver that prints out a person's name, and a word .thanks that prints out something like this:&lt;br /&gt;&lt;br /&gt;Dear Stephanie, Thanks for the bookends.&lt;br /&gt;&lt;br /&gt;Solution:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;gift&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;bookends.&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;giver&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Stephanie,&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;dear&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Dear&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;thank&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Thanks for the&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.gift&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;gift&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.giver&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;giver&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.thank&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;thank&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.dear&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 102);"&gt;dear&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;thanks&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;show black screen text .dear .giver .thank .gift ;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;Alternatively:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;gift&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;bookends.&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;giver&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;Stephanie,&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;dear&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;Dear&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;thank&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;Thanks for the&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;thanks&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="background-color: rgb(0, 0, 0);"&gt;show black screen text &lt;span style="color: rgb(255, 255, 0);"&gt;dear&lt;/span&gt; .s &lt;span style="color: rgb(255, 255, 0);"&gt;giver&lt;/span&gt; .s &lt;span style="color: rgb(255, 255, 0);"&gt;thank&lt;/span&gt; .s &lt;span style="color: rgb(255, 255, 0);"&gt;gift&lt;/span&gt; .s ;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Problem 1-2: Define a word &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;tenless&lt;/span&gt;&lt;span style="font-size:130%;"&gt; that takes a number on the stack, substracts 10, and returns the answer on the stack.  (Hint: You can use &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;+&lt;/span&gt;&lt;span style="font-size:130%;"&gt;.) Be sure to include stack effects.&lt;br /&gt;&lt;br /&gt;Solution&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;tenless&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;n-n'&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);font-size:130%;" &gt;-10&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:130%;" &gt;+ ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Problem 1-3: After entering the words in Problems 1-1, enter a new definition for &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.giver&lt;/span&gt;&lt;span style="font-size:130%;"&gt; to print someone else's name, then without redefining &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;thanks&lt;/span&gt;&lt;span style="font-size:130%;"&gt;, execute &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;thanks&lt;/span&gt;&lt;span style="font-size:130%;"&gt; again.  Can you explain why &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;thanks&lt;/span&gt;&lt;span style="font-size:130%;"&gt; still prints out the first giver's name?&lt;br /&gt;&lt;br /&gt;Solution&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;gift&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;bookends.&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;giver&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Stephanie,&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);font-size:130%;" &gt;dear&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Dear&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);font-size:130%;" &gt;thank&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);font-size:130%;" &gt;Thanks for the&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.gift&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;gift&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.giver&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;giver&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.thank&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;thank&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;.dear&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 102);"&gt;dear&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);font-size:130%;" &gt;thanks&lt;/span&gt;&lt;span style="font-size:130%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;.dear .giver .thank .gift ; &lt;span style="color: rgb(204, 102, 204);"&gt;giver&lt;/span&gt; 0 &lt;span style="color: rgb(204, 204, 204);"&gt;Jill&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;.giver&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;giver&lt;/span&gt; .s ;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 0, 0);"&gt;go&lt;/span&gt; show black screen text thanks .giver ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Alternatively:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;gift&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;bookends.&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;giver&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;Stephanie,&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 102, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;dear&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;Dear&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;thank&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;0&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204); background-color: rgb(0, 0, 0);font-size:130%;" &gt;Thanks for the&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;thanks&lt;/span&gt;&lt;span style="background-color: rgb(0, 0, 0);font-size:130%;" &gt; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 102);"&gt;dear &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;.s &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;giver &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;.s &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;thank&lt;/span&gt; .s&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt; .&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt;&lt;span style="color: rgb(255, 255, 0);"&gt;gift&lt;/span&gt; .s&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0); background-color: rgb(0, 0, 0);font-size:130%;" &gt; ; &lt;span style="color: rgb(204, 102, 204);"&gt;giver&lt;/span&gt; 0 &lt;span style="color: rgb(204, 204, 204);"&gt;Jill&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;go&lt;/span&gt; show black screen text thanks &lt;span style="color: rgb(255, 255, 0);"&gt;giver&lt;/span&gt; .s ;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;Whenever a new word is compiled it is appended to the end of the dictionary.  The old definition isn't overwritten, but the interpreter starts at the newest definition and searches backwards so it doesn't find the older definition.  However words that were defined using the old definition still work the same.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-9012673496705593793?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/9012673496705593793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=9012673496705593793' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/9012673496705593793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/9012673496705593793'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2009/06/primary-colorforth-chapter-1.html' title='Primary ColorForth Chapter 1'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-5132139729105972819</id><published>2009-05-26T07:41:00.000-07:00</published><updated>2009-06-14T04:29:50.932-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Typing ColorForth...versions 3.1 and 4.0</title><content type='html'>Hello again.  Here's yet another update to my experiments with unpacking and displaying packed ColorForth text.  I know have it to the place where doing the examples from Starting Forth should be easy.  First a fix from version 3.0 based on the fact that ColorForth 2.0 enforces &lt;a href="http://primarycolorforth.blogspot.com/2009/05/colorforth-20-gotchawindows-version.html"&gt;Chuck's admonition for yellow variable calls&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;fffffff0 &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;and unpack if emit type ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ f and -9 + drop if drop then ; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ type space 1 +&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; print ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;greet&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text &lt;span style="color: rgb(255, 255, 0);"&gt;s&lt;/span&gt; 1 + print ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;However I found a &lt;a href="http://qualdan.com/colorforth/stype.html"&gt;much better version&lt;/a&gt;.  This version actually handles caps and mixed case.  But it also requires the yellow variable call fix.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;space&lt;/span&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;fffffff0&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;and unpack +first @ + emit&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;unpack if +rest @ + emit rest ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;done&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;drop drop pop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;norm&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;!&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;cap&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;caps&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;jump rest done done done done done done done done norm cap caps done done done done ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;stype&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;1 + dup @ dup 15 and select stype ;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's a slightly different version that uses macros to (IMO) improve readability and includes an example of usage.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;space&lt;/span&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;fffffff0&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;and unpack +first @ + emit&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;unpack if +rest @ + emit rest ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;done&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;drop drop pop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;norm&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;!&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;cap&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 0&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;caps&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+first&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! 48&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;+rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;! type ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;jump rest done done done done done done done done norm cap caps done done done done ; &lt;span style="color: rgb(255, 255, 0);"&gt;macro&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;tag&lt;/span&gt; 15 and ;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;nextw&lt;/span&gt; 1 + dup @ dup ; &lt;span style="color: rgb(255, 255, 0);"&gt;forth&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;stype&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;nextw tag&lt;/span&gt; select stype ;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's what this does and why I think it's better.  The words "nextw" and "tag" are put in the "macro" dictionary and then inlined because they as "&lt;span style="color: rgb(0, 204, 204);"&gt;cyan&lt;/span&gt;" words.  Cyan words allow you to inline.  Normally in ColorForth words are factored to save space.  Here no space is saved because "nextw" and "tag" are only used once.  But "stype" is more readable because it says exactly what it does.  Here's the documentation "shadow block".&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;String Display&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;w&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;display one 32-bit word of text&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;rest&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;w&lt;/span&gt; finish typing a word&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;done&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;aw&lt;/span&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;drop addr and word and return from stype&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;norm&lt;/span&gt; normal text&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;cap&lt;/span&gt; text starts with a capital&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;caps&lt;/span&gt; all caps&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;select&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;wt&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;handle word according to tag&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;nextw&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;a&lt;/span&gt; get next word and increment address&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;stype&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;a&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;display contiguous white text&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Using the above, here's the solution to problem 1-1 from Starting Forth.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;162 load&lt;/span&gt; salute&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;Dear&lt;/span&gt; &lt;span style="color: rgb(153, 51, 153);"&gt;friend&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;Stephanie,&lt;/span&gt; &lt;span style="color: rgb(153, 51, 153);"&gt;thank&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;thanks for the&lt;/span&gt; &lt;span style="color: rgb(153, 51, 153);"&gt;gift&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;bookends.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;thanks&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;salute&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;stype&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;friend&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;stype&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;thank&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;stype&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;gift&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;stype ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text blank white thanks keyboard ;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Note that "162 load" assumes that the "String Display" library is in block 162.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-5132139729105972819?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/5132139729105972819/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=5132139729105972819' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/5132139729105972819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/5132139729105972819'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2009/05/typing-colorforthversions-31-and-40.html' title='Typing ColorForth...versions 3.1 and 4.0'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-8366777699996688739</id><published>2009-05-26T05:48:00.000-07:00</published><updated>2009-06-14T04:31:03.613-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><category scheme='http://www.blogger.com/atom/ns#' term='windows'/><title type='text'>A ColorForth 2.0 "gotcha".(Windows version anyway)</title><content type='html'>Hello all.&lt;br /&gt;&lt;br /&gt;I pretty much use a Windows version of ColorForth all the time these days.  (Usually &lt;a href="http://forthworks.com/c4th/doku.php?id=2.0adownloadableversons"&gt;ColorForth 2.0&lt;/a&gt; from Chuck Moore in Windows mode, but some &lt;a href="http://www.geocities.com/eleks_76/"&gt;Roman Pavlyuk's version&lt;/a&gt;.).  The reason I'm prefacing my remarks is because I have never used the native version of ColorForth 2.0 and I don't know if this "gotcha" only happens under Windows.  There is an easily fixable bug that only happens in Roman's Windows version of ColorForth.  It uses absolute addressing from blocks as opposed to indirect addressing.  So the code:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;0 block @&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;causes it to crash.  The fix is easy.  Assume the following code in block 162.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;ofs&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;foo&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;block&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;ofs 162 block negate + -1 +&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;+ ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;block&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;foo ;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Thankfully ColorForth 2.0 for Windows doesn't have that problem.  It uses an offset to calculate blocks out of the box.  However there is another "gotcha" when using variables.  If you try to address a variable using a &lt;span style="color: rgb(51, 255, 51);"&gt;green&lt;/span&gt; word it doesn't work.  You may simply not get the results you want or it might crash.  Consider the following example taken from Starting Forth chapter 2.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;date&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;month&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;year&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;!date&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;date ! month ! year ! ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;5 26 2009 !date&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;That doesn't get the expected results.  But there's a reason I call this a "gotcha" instead of a bug.  Long ago Chuck documented that variables really should be used as yellow words (evaluated at compile time) instead of green words (evaluated at run time).  When you think about it, this makes sense.  A variable is really just an address and for the most part address are constants.  So why wait until run time to find the address of a variable?  Just find it at compile time and compile the address constant directly into the word.  With that in mind the above code becomes:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;date&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;month&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;year&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;!date&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;date&lt;/span&gt; ! &lt;span style="color: rgb(255, 255, 0);"&gt;month&lt;/span&gt; ! &lt;span style="color: rgb(255, 255, 0);"&gt;year&lt;/span&gt; ! ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;5 26 2009 !date&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;So if you have old ColorForth code that uses variables as green words you need to change them to yellow words.  Your code will be (slightly) faster and it will work on ColorForth 2.0 for Windows (again, I don't know if the native version even has this "gotcha").&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-8366777699996688739?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/8366777699996688739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=8366777699996688739' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/8366777699996688739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/8366777699996688739'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2009/05/colorforth-20-gotchawindows-version.html' title='A ColorForth 2.0 &quot;gotcha&quot;.(Windows version anyway)'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-5218902243284865094</id><published>2009-01-25T17:25:00.000-08:00</published><updated>2009-06-14T04:30:27.469-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ventureforth'/><title type='text'>SEAForth Matrix Multiplication Example update 1</title><content type='html'>It's been about 1 year since I posted my initial &lt;a href="http://primarycolorforth.blogspot.com/2008/01/seaforth-matrix-multiplication-example.html"&gt;SEAForth matrix multiplication example&lt;/a&gt;.  A lot has happened since then including changes to the VentureForth IDE/simulator as well as the commercial release of actual SEAForth chips.  That's the good news.  The bad news (for me at least) was that the changes were such that it broke my old code.  That wouldn't have been so bad if there had been "this has been deprecated" section in the docs, but then I suppose that would have made the transition too easy.  ;)  Seriously though, some of the changes actually make the code much cleaner.  Also I've made the code much more modular thanks to the judicious use of include files.&lt;br /&gt;&lt;br /&gt;First I'll go through the changes that I've noticed in the new system and then an overview the new matrix multiplication code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Change 1 : Node specification&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the original VentureForth you specified the node you were compiling to this way:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;12 node !&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now the compiling node is specified this way:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;12 {node&lt;br /&gt;...&lt;br /&gt;.../ some VentureForth code&lt;br /&gt;...&lt;br /&gt;node}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;It's a lot clearer where compiling to a node begins and ends.  This can also lead to a clean modular code pattern that will be discussed later.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Change 2 : Stream Specification&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Section 2.3.1 of the VentureForth manual explains streams.  Basically it's a way for code and data to be initially distributed to the correct nodes.  If you are just learning the SEAForth system as I am you probably aren't ready to create your own custom stream nodepath.  But you do need to make sure all of the nodes are initialized.  The following code will do that.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;19stream&lt;br /&gt;&lt;br /&gt;reset&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Change 3 : Literal Specification&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The original VentureForth compiler would compile literals automatically.  Now a "#" is required after every literal.  Note that port selection constants are really literals and require a "#" after them also.  So:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;'r--- b!&lt;br /&gt;7 for @p+ !b unext&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;becomes:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;'r--- # b!&lt;br /&gt;7 # for @p+ !b unext&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Toward More Modular Programs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I saw the following code pattern in the "blinktest" sample project:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;\ Main program.vf&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;19 {node 0 org here =p include module.vf node}&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;So I've followed a similar pattern for my code, breaking what was a single monolithic module into 6 smaller (and in my opinion easier to read) modules.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Main module : matrixmult.vf&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;( $Id: matrixmult.vf,v 1.0 2006-11-2 $ )&lt;br /&gt;\ Matrix multiplication example&lt;br /&gt;\ Parrallel multiplication of a 2 row matrix by a 2 column matrix&lt;br /&gt;\ 1) Data initially is in node 12&lt;br /&gt;\ 2) Row1 is passed to node 18&lt;br /&gt;\ 3) Row2 is passed to node 13&lt;br /&gt;\ 4) Column1 is passed to nodes 18 and 13 simultaneously&lt;br /&gt;\ 5) Multiplications R1*C1 and R2*C1 done simultaneously&lt;br /&gt;\ 6) Column2 is passed to nodes 18 and 13 simultaneously&lt;br /&gt;\ 7) Multiplications R1*C2 and R2*C2 done simultaneously&lt;br /&gt;\ 8) Results R1*C1, R1*C2, R2*C1, R2*C2 are returned to node 12&lt;br /&gt;&lt;br /&gt;v.VF +include" c7Dr03/romconfig.f"&lt;br /&gt;&lt;br /&gt;12 {node include node12.vf node}&lt;br /&gt;13 {node include node13.vf node}&lt;br /&gt;18 {node include node18.vf node}&lt;br /&gt;&lt;br /&gt;19stream&lt;br /&gt;&lt;br /&gt;reset&lt;br /&gt;&lt;br /&gt;cr&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Node 12 code : node12.vf&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Note: This is the taskmaster node.  It passes the data to nodes 13 and 18 to be processed and the collates the results.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;\ ******* node 12 ***************************************&lt;br /&gt;\ Pass row1 to node 13, row2 to node 18&lt;br /&gt;\ and columns 1 and 2 to nodes 13 and 18 simultaneously&lt;br /&gt;&lt;br /&gt;0 org here =p&lt;br /&gt;&lt;br /&gt;\ Stream R1 to node 13&lt;br /&gt;'r--- # b! \ point reg b to right node. (I/O node 13)&lt;br /&gt;7 # for @p+ !b unext&lt;br /&gt;1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,&lt;br /&gt;&lt;br /&gt;\ Stream R2 to node 18&lt;br /&gt;| '-d-- # b! . . \ point reg b to down node. (I/O node 18)&lt;br /&gt;7 # for @p+ !b . unext&lt;br /&gt;9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ,&lt;br /&gt;&lt;br /&gt;\ Stream C1 to nodes 13 and 18 simultaneously&lt;br /&gt;'rd-- # b! . . \ point reg b to right and down nodes. (I/O nodes 13 and 18)&lt;br /&gt;0 # !b . . \ dummy write for synch purposes&lt;br /&gt;15 # for @p+ !b . unext&lt;br /&gt;17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ,&lt;br /&gt;25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,&lt;br /&gt;&lt;br /&gt;59 # a! . . \ point A register to address 59&lt;br /&gt;'r--- # b! . . \ point reg b to right node. (I/O node 13)&lt;br /&gt;@b !a+ . . \ Get result R1*C1&lt;br /&gt;@b !a+ . . \ Get result R1*C2&lt;br /&gt;'-d-- # b! . . \ point reg b to down node. (I/O node 18)&lt;br /&gt;@b !a+ . . \ Get result R2*c1&lt;br /&gt;@b !a+ . . \ Get result R2*c2&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Nodes 13 and 18 basically do the same thing.  Get a row of data from node 12, then use that row to calculate a dot product of two columns of data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Node 13 code : node13.vf&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;\ ******* node 13 *********************************************&lt;br /&gt;\ Receive row1 then multiply it by columns 1 and 2&lt;br /&gt;\ and return results.&lt;br /&gt;&lt;br /&gt;0 org&lt;br /&gt;&lt;br /&gt;include 8bitmult.vf&lt;br /&gt;&lt;br /&gt;here =p&lt;br /&gt;'r--- # b! . . \ point reg b to right node&lt;br /&gt;&lt;br /&gt;include vectormult.vf&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Node 18 code : node18.vf&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;\ ******* node 18 *********************************************&lt;br /&gt;\ Receive row2 then multiply it by columns 1 and 2&lt;br /&gt;\ and return results.&lt;br /&gt;&lt;br /&gt;0 org&lt;br /&gt;&lt;br /&gt;include 8bitmult.vf&lt;br /&gt;&lt;br /&gt;here =p&lt;br /&gt;'-d-- # b! . . \ point reg b to down node&lt;br /&gt;&lt;br /&gt;include vectormult.vf&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;8 bit multiply : 8bitmult.vf&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;: 8*8 ( n1 n2 -- n1*n2 ) \ 16 bit output&lt;br /&gt;push 2* 2* . \ left shift n1 8 times&lt;br /&gt;2* 2* 2* .&lt;br /&gt;2* 2* 2* .&lt;br /&gt;pop +* +* +*&lt;br /&gt;+* +* +* +*&lt;br /&gt;+* push drop .&lt;br /&gt;pop ;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Vector multiply : vectormult.vf&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;\ ******* vector multiply *******************************&lt;br /&gt;\ Receive a row then multiply it by columns 1 and 2&lt;br /&gt;\ and return results.&lt;br /&gt;&lt;br /&gt;$20 # dup a! push \ point reg a to buffer - leave adr on return stack&lt;br /&gt;&lt;br /&gt;7 # for @b !a+ unext&lt;br /&gt;&lt;br /&gt;@b drop \ dummy read for synchronization purposes&lt;br /&gt;&lt;br /&gt;pop dup a! push \ reset a to start of buffer&lt;br /&gt;dup xor \ initilize TOS to 0&lt;br /&gt;7 # for&lt;br /&gt;@b @a+ 8*8&lt;br /&gt;+ next&lt;br /&gt;&lt;br /&gt;dup dup xor \ preserve result from vector mult - initialize TOS to 0&lt;br /&gt;&lt;br /&gt;pop a!&lt;br /&gt;7 # for&lt;br /&gt;@b @a+ 8*8&lt;br /&gt;+ next&lt;br /&gt;&lt;br /&gt;!b !b \ Send results back to right node&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-5218902243284865094?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/5218902243284865094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=5218902243284865094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/5218902243284865094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/5218902243284865094'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2009/01/seaforth-matrix-multiplication-example.html' title='SEAForth Matrix Multiplication Example update 1'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-3112901739914055368</id><published>2008-01-28T08:01:00.000-08:00</published><updated>2009-06-14T04:31:30.075-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ventureforth'/><title type='text'>SEAForth matrix multiplication example</title><content type='html'>&lt;em&gt;Disclaimer: I don't work for &lt;a href="http://www.intellasys.net/"&gt;IntellaSys&lt;/a&gt; and I consider myself a novice in NOSC programming in general and the SEAForth architecture in particular. But, by using documentation publicly at the &lt;a href="http://www.intellasys.net/"&gt;IntellaSys&lt;/a&gt; website I have figured out how to write working programs for it.&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I'm going to diverge from ColorForth for this particular blog entry to talk about SEAForth.  Hopefully the ColorForth version of the SEAForth compiler will be released soon, but for now the public SEAForth programming environment, VentureForth, is closer IMO to MachineForth.  (No color tokens.  You have to keep up with code slots etc.)  Still VentureForth does have a strong "fun factor" when it comes to programming.  Personally I think that when programming, rather than thinking about ALGOL like "algorithms" you should think about the hardware and how to directly map your problem across it.  Programming comes later.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;SEAForth Architecture&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The SEAForth architecture is the latest hardware design from Forth creator Chuck Moore.  Like previous designs it is a &lt;a href="http://www.strangegizmo.com/forth/NOSC/"&gt;NOSC&lt;/a&gt; or "no operand stack computer".  The history and documentation of Mr. Moore's early NOSC work is documented at Jeff Fox's &lt;a href="http://www.ultratechnology.com/"&gt;Ultratechnology&lt;/a&gt; website.   This means that all operations take their operands from the stack.  SEAForth goes a step further and has multiple cores (24 in the first implementation) on one chip.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is a diagram of a SEAForth chip.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;table&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;18&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;19&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;20&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;21&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;22&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;23&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;14&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;16&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;17&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;06&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;07&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;08&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;09&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;23&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;D&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;00&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;01&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;02&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;03&lt;/td&gt;&lt;td&gt;L&lt;/td&gt;&lt;td&gt;04&lt;/td&gt;&lt;td&gt;R&lt;/td&gt;&lt;td&gt;05&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;U&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;   &lt;/pre&gt;The numbers 0..23 represent the individual cores.  The letters U, D, L and R represent the ports.  &lt;a href="http://www.strangegizmo.com/forth/ColorForth/msg02296.html"&gt;Mr. Fox explained&lt;/a&gt; that these ports can point to other cores on chip or to off chip devices.  For example communication between ports 18 and 19 always use the "R" port regardless of whether its 18 sending the data or receiving it.  Also the U port for cores 18 and 23 goes to the A/D and D/A pins in some configurations.  Knowing how port communication works is essential for understanding the "crawler" application walkthrough that &lt;a href="http://www.intellasys.net/"&gt;IntellaSys&lt;/a&gt; has provided with their development kit.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Sample Application&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In trying to come up with a test program to explore SEAForth, I settled on an obvious parallel processing application that's easy to understand, matrix multiplication.  First lets look at the &lt;a href="http://mathworld.wolfram.com/MatrixMultiplication.html"&gt;mathematical definition&lt;/a&gt; of matrix multiplication.  The product of two matrices A and B results in a new matrix C where each element of C is the sum of the products of the rows in A and the columns in B.  Let's take the case of a 2 row matrix by a 2 column matrix.&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;Matrix A:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;9&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;14&lt;/td&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;16&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;Matrix B:&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;17&lt;/td&gt;&lt;td&gt;25&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;18&lt;/td&gt;&lt;td&gt;26&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;19&lt;/td&gt;&lt;td&gt;27&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;20&lt;/td&gt;&lt;td&gt;28&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;21&lt;/td&gt;&lt;td&gt;29&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;22&lt;/td&gt;&lt;td&gt;30&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;23&lt;/td&gt;&lt;td&gt;31&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;24&lt;/td&gt;&lt;td&gt;32&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;If we label the matrix A rows R1 and R2 and the matrix B columns C1 and C2 then the resulting matrix is:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;R1*C1&lt;/td&gt;&lt;td&gt;R1*C2&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;R2*C1&lt;/td&gt;&lt;td&gt;R2*C2&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style="font-size:130%;"&gt;Mapping of problem to SEAForth chip&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So this is how I mapped the problem to the SEAForth chip.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Data is initially in node 12&lt;/li&gt;&lt;li&gt;Row 1 is passed to node 18&lt;/li&gt;&lt;li&gt;Row 2 is passed to node 13&lt;/li&gt;&lt;li&gt;Column 1 is passed to nodes 18 and 13 simultaneously&lt;/li&gt;&lt;li&gt;Multiplications R1*C1 and R2*C1 are done simultaneously&lt;/li&gt;&lt;li&gt;Column 2 is passed to nodes 18 and 13 simultaneously&lt;/li&gt;&lt;li&gt;Multiplications R1*C2 and R2*C2 are done simultaneously&lt;/li&gt;&lt;li&gt;Results R1*C1, R1*C2 from node 18 are returned to node 12&lt;/li&gt;&lt;li&gt;Results R2*C1, R2*C2 from node 13  are returned to node 12&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size:130%;"&gt;Data streaming&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As you may have noticed, in this program node 12 is responsible for streaming data to other nodes and then collecting the results.  For this test program the data is stored in node 12's core memory.  For larger applications this could be streamed in from external memory.  Consider the following code snippet.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;\ Stream R1 to node 13&lt;/span&gt;&lt;br /&gt;'r--- b! . .   &lt;span style="font-style: italic;"&gt;\ point reg b to right node.  (I/O node 13)&lt;/span&gt;&lt;br /&gt;7 for @p+ !b . unext&lt;br /&gt;[ 1 ,  2 , 3 , 4 , 5 ,  6 ,  7 ,  8 , ]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This is a microloop.  The first line configures the b register to communicate with the "right" node to node 12.  The next line is a microloop.  The entire loop fits in one SEAForth word of memory.  The data (values 1...8) are stored in the words immediately following the loop.  The instruction @p+ copies a word from the program counter to the stack and the increments the program counter.  The instruction !b takes the word on the top of the stack and sends it to the node(s) pointed to by the b register.  You can write to more than one node at once as shown by this code.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;\ &lt;span style="font-style: italic;"&gt;Stream C1 to nodes 13 and 18 simultaneously&lt;/span&gt;&lt;br /&gt;'rd-- b! . .    \ &lt;span style="font-style: italic;"&gt;point reg b to right and down nodes.  (I/O nodes 13 and 18)&lt;/span&gt;&lt;br /&gt;0 !b . .        \ &lt;span style="font-style: italic;"&gt;dummy write for synch purposes&lt;/span&gt;&lt;br /&gt;15 for @p+ !b . unext&lt;br /&gt;[ 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ,&lt;br /&gt;25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , ]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The a register is used to write to internal core memory.  The last part of the code for node 12 reads 4 results (2 from node 13 and 2 from node 18) and stores them sequentially starting at hex address 32.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$32 a! . .    \ &lt;span style="font-style: italic;"&gt;point A register to address 32&lt;/span&gt;&lt;br /&gt;'r--- b! . . \ &lt;span style="font-style: italic;"&gt;point reg b to right node.  (I/O node 13)&lt;/span&gt;&lt;br /&gt;@b !a+ . .   \ &lt;span style="font-style: italic;"&gt;Get result R1*C1&lt;/span&gt;&lt;br /&gt;@b !a+ . .   \ &lt;span style="font-style: italic;"&gt;Get result R1*C2&lt;/span&gt;&lt;br /&gt;'-d-- b! . . \ &lt;span style="font-style: italic;"&gt;point reg b to down node.  (I/O node 18)&lt;/span&gt;&lt;br /&gt;@b !a+ . .   \ &lt;span style="font-style: italic;"&gt;Get result R2*c1&lt;/span&gt;&lt;br /&gt;@b !a+ . .   \ &lt;span style="font-style: italic;"&gt;Get result R2*c2&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Multiplication on SEAForth&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The SEAForth chip does not have a direct multiplication instruction.  Instead it has a &lt;a href="http://groups.google.com/group/comp.lang.forth/browse_thread/thread/2fd5f32bea33c0e9/0d4ad4ee2f6a1dd8?lnk=gst&amp;amp;q=+multiply+step+SEAForth#0d4ad4ee2f6a1dd8"&gt;multiply step&lt;/a&gt;.  All you really need to know is that if you want to multiply two n-bit numbers n1 and n2, put both on the stack, shift 1 number left n times, then execute the multiply step n times.  For 8 bit multiplication you can use the following code.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;: 8*8 ( n1 n2 -- n1*n2 )  \ 16 bit output&lt;br /&gt;push 2* 2* .  \ left shift n1 8 times&lt;br /&gt;2* 2* 2* .&lt;br /&gt;2* 2* 2* .&lt;br /&gt;pop +* +* +*&lt;br /&gt;+* +* +* +*&lt;br /&gt;+* push drop .&lt;br /&gt;pop ;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This creates a subroutine 8*8 which is used to do 8 bit multiplies.  That's all I need for this particular example.  Here is the rest of the code for node 13.  Node 18 uses the same code.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;-d--  b! . .       \ &lt;span style="font-style: italic;"&gt;point reg b to down node (I/O node 12)&lt;/span&gt;&lt;br /&gt;$20 dup a! push   \ &lt;span style="font-style: italic;"&gt;point reg a to buffer - leave adr on return stack&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;7 for  @b !a+ . unext \ &lt;span style="font-style: italic;"&gt;read row R1 from node 12 and store in buffer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;@b drop . .       \ &lt;span style="font-style: italic;"&gt;dummy read for synchronization purposes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;pop dup a! push    \ &lt;span style="font-style: italic;"&gt;reset a to start of buffer&lt;/span&gt;&lt;br /&gt;dup xor          \ &lt;span style="font-style: italic;"&gt;initialize TOS to 0&lt;/span&gt;&lt;br /&gt;7 for             \ &lt;span style="font-style: italic;"&gt;Loop to multiply elements from R1 and C1&lt;/span&gt;&lt;br /&gt;@b @a+ 8*8 .      \ &lt;span style="font-style: italic;"&gt;Get next R1 element from buffer and next C1 element from node 12&lt;/span&gt;&lt;br /&gt;+ next . .&lt;br /&gt;&lt;br /&gt;dup dup xor .     \ &lt;span style="font-style: italic;"&gt;preserve result from vector multiply - initialize TOS to 0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;pop a! . .       &lt;/code&gt;&lt;code&gt;\ &lt;span style="font-style: italic;"&gt;reset a to start of buffer&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;7 for            &lt;/code&gt;&lt;code&gt;\ &lt;span style="font-style: italic;"&gt;Loop to multiply elements from R1 and C2&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;  @b @a+ 8*8 .     &lt;/code&gt;&lt;code&gt;\ &lt;span style="font-style: italic;"&gt;Get next R1 element from buffer and next C2 element from node 12&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;  + next . .&lt;br /&gt;&lt;br /&gt;!b !b . .                \ &lt;span style="font-style: italic;"&gt;Send results back to node 12&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;Performance&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;First I need to point out that the goal isn't to show how fast I can do multiplication but rather how efficient the SEAForth architecture can be for exploiting parallelism.  On the simulator I have it was able to complete a single 8 bit multiplication in 50 cycles.  Considering that there are a total of 32 multiplications that 1,600 cycles for multiplication alone.  Using 3 cores the operation is completed in 945 cycles which represents a 41% speed up.  It should be intuitively obvious that even great speed ups can be achieved by mapping the problem over more cores.  I have a couple of ideas on that to test but I'll save that for another day.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-3112901739914055368?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/3112901739914055368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=3112901739914055368' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/3112901739914055368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/3112901739914055368'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2008/01/seaforth-matrix-multiplication-example.html' title='SEAForth matrix multiplication example'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-3907507844252895476</id><published>2006-12-27T20:32:00.000-08:00</published><updated>2009-06-14T04:32:02.088-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Typing ColorForth...version 3.0</title><content type='html'>&lt;span style="font-size:130%;"&gt;Cliche of the day: The third time's a charm&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I've now extended my ColorForth text display library to the place where it's as "non-tedious" to use as possible.  The first step was to be able to unpack and "type" a word rather than having to look up ColorForth charecter codes and emit them one at a time.  The second step was to be able to print multiple words at one shot.  That was in version 2.0.  But the problem there was that I either had to put the number of words on the stack, or store them in the string variable itself.  Now, after some brainstorming on the c4th IRC channel, I've come up with working code that figures out for itself how many words to type.  Here it is.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;fffffff0 &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;and unpack if emit type ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;nextw &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ type space 1 + ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;tag &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;f and ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;?ncom&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;tag -9 + drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;1 +&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ploop &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ ?ncom if drop ; then nextw ploop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;greet&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s print ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;A few notes here.  Due to the way "print" works I couldn't use the old "nxtw" definition.  So I modified it and changed the name.  Also note, for those obsessing over lines of code (despite the fact that just about everyone knows that's no longer a good measure of program size, complexity or "tediousness") the above can be "compressed" into less lines, though IMO at the cost of readability.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;fffffff0 &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;and unpack if emit type ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ f and -9 + drop if drop then ; &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ type space 1 +&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; print ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;greet&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s 1 + print ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;There you have it.  Four lines of ColorForth.  (Or 3 lines depending upon where  you put your variable.)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;fffffff0 &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;and unpack if emit type ; then drop drop ;&lt;/span&gt; &lt;span style="color: rgb(153, 51, 153);"&gt;s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ f and -9 + drop if drop then ; &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @ type space 1 +&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; print ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;greet&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s 1 + print ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;And for the "ultra minimalist" (who doesn't want to bother with the tedium of looking up ColorForth charecter codes) you can do a simple "hello world" in 2 lines.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 102, 0);"&gt;fffffff0 &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;and unpack if emit type ; then drop drop ;&lt;/span&gt; &lt;span style="color: rgb(153, 51, 153);"&gt;s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;hello world&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s dup push 1 + @ type 0 emit pop 2 + @ type ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But that code isn't very robust.  What happens when the string you want to type grows from 2 words to 6 as in "hello world, what a lovely day"?  Still, that beats the pants off of emitting each charecter one at a time.&lt;br /&gt;&lt;br /&gt;Anyway, this is the last I'm do anything with "hello world" programs for a while.  I've got enough now to finish all of the examples in Starting Forth (chapter 1 anyway) with a minimum of tedium.  This does remind me of how Chuck Moore answered the question of "hello world" programs on the ColorForth mailing list.&lt;br /&gt;&lt;pre style="font-style: italic;"&gt;I've noticed the interest people have in getting colorForth to say "Hello&lt;br /&gt;World".&lt;br /&gt;&lt;br /&gt;The facility for doing that is extremely simple. Find an empty block. Edit&lt;br /&gt;"Hello World" at the top.&lt;br /&gt;&lt;br /&gt;I know that's not quite what they have in mind. But it's the way I'd&lt;br /&gt;generate any sort of display. Format a block with the editor. Fill in&lt;br /&gt;whatever numbers or graphics are required.&lt;/pre&gt;Gotta love it!  "Hello world" in a single line and no need for tedious charecter code look ups and emits!  Honestly though, that's what got me (and others) thinking about the "unpack" method of displaying text.  The ColorForth to my understanding works by unpacking and displaying all of the 32 bit words in a block of code.  But it's smart enough to understand compile words, macros, comments, numbers ect and choose the correct color and font.  Right now the method I'm using only recognizes comments from non comments so it can't properly handle capitalization.  But it should be intuitively obvious to the casual observer how to fix that.  Perhaps I'll leave that as a "student exercise".  :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-3907507844252895476?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/3907507844252895476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=3907507844252895476' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/3907507844252895476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/3907507844252895476'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2006/12/typing-colorforthversion-30.html' title='Typing ColorForth...version 3.0'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-3814993346821286916</id><published>2006-12-27T11:45:00.000-08:00</published><updated>2009-06-14T04:32:23.522-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Typing ColorForth...ver 2.0</title><content type='html'>Hello folks. Back fresh from the forever flamewars at comp.lang.forth. :) It's funny how some people want to nitpick ColorForth while posting code that the ANS standard calls "dangerous".&lt;br /&gt;&lt;br /&gt;Anyway the current "nitpick" is over my stype code. Small confession. I'm not omniscient. ;) When I posted at c.l.f. I was replying to the usual nonsense while thinking about where I was going with PrimaryForth tutorial as opposed to just answering what's possible now. Once I get finished you will be able to do the following code:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 204);"&gt;s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;0&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s stype ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And get:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;hello, i speak forth&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;as output.  Right now you get:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;hello&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;as output. If you want to get the entire phrase you have to put the number of words you want to type on the stack use the "words" word. For example:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;show text s 5 words ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I really don't see that as a big deal.  You still don't have to do:&lt;br /&gt;&lt;span style="color:red;"&gt;&lt;span style="font-family:monospace;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;hw&lt;/span&gt; &lt;span style="color:green;"&gt;show blue screen text 230 350 at red&lt;/span&gt; &lt;span style="color:darkgreen;"&gt;2a 10 c 1 3&lt;/span&gt; &lt;span style="color:darkgreen;"&gt;3f 0 2e 3 c c 4 44&lt;/span&gt; &lt;span style="color:green;"&gt;13 for 2emit next ;&lt;/span&gt; &lt;span style="color:yellow;"&gt;hw&lt;/span&gt;&lt;span style="font-family:monospace;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;But don't tell the "haters*" that. :) They still want to believe what they want to believe. Still, I've found a way around this. By storing the number of words in the ColorForth string variable (the same as the way ANS Forth stores the number of charecters in the first byte of an ANS Forth string variable) the computer can put the number of words on the stack for you. For example:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;s&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;5 &lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;phrase &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;dup @&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;words&lt;span style="color: rgb(0, 153, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;for ntxtw next ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now with just one small line of ColorForth:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s phrase ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You get:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The next step will be to incorporate testing the token color. Comments use the "white" color. So phrase could be programmed to typing words until it hits a word that's not a comment. (Thanks to "tathi" on the c4th IRC channel for kicking this idea around.)&lt;br /&gt;&lt;br /&gt;* Note:  By "haters" I don't mean the person who actually wrote the ColorForth code I referenced.  I mean those who want to insist on using that as "proof" that it's difficult to do something as simple as "hello world" in ColorForth rather than seeing the obvious.  ColorForth, like any other Forth, is extensible.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-3814993346821286916?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/3814993346821286916/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=3814993346821286916' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/3814993346821286916'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/3814993346821286916'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2006/12/typing-colorforthver-20.html' title='Typing ColorForth...ver 2.0'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-337086522282007457</id><published>2006-12-27T08:03:00.000-08:00</published><updated>2006-12-27T08:24:08.760-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Typing ColorForth</title><content type='html'>I made the following extensions to ColorForth.&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="color: rgb(153, 51, 153);"&gt;&lt;br /&gt;s &lt;span style="color: rgb(51, 204, 0);"&gt;0 &lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;stype &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;1 + @&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;fffffff0&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;and unpack if emit type ; then drop drop ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The word "type" takes a packed word and displays it on the screen.  Right now it ignores all color tags and just emits charecters using the current foreground color.  Note that &lt;span style="color: rgb(153, 51, 153);"&gt;s&lt;/span&gt; is a string variable.  Actually it's just a regular variable, but I'm treating it like a string variable.  Variables in ColorForth really point directly to block memory.  So by adding 1 to the address of &lt;span style="color: rgb(153, 51, 153);"&gt;s&lt;/span&gt; I can get the address of the text for "hello".   The word "stype" adds 1 to the address on the stack and then returns data which is treated by "type" as a packed string.  So the code:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;greet&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s stype ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Will display "hello" on the screen.  Of course that's only part of the phrase.  I added a definition to get a word, display it, and add the address for the next word.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;nxtw &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;1 + dup @ type space ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The word "space" was defined in a &lt;a href="http://primarycolorforth.blogspot.com/2006/12/starting-forth-chapter-1-examples.html"&gt;previous posting&lt;/a&gt;.  I then added a word to unpack and display several words of text.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;words &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;for nxtw next ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So the code:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;greet&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text s 5 words ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Will display:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;hello , i speak forth&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I'm looking for better ways to do this.  All comments welcome.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-337086522282007457?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/337086522282007457/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=337086522282007457' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/337086522282007457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/337086522282007457'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2006/12/typing-colorforth.html' title='Typing ColorForth'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-123568583200003285</id><published>2006-12-21T12:04:00.000-08:00</published><updated>2009-06-14T04:32:49.802-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Starting Forth chapter 1 examples.</title><content type='html'>&lt;span style="font-size:130%;"&gt;Intro to &lt;a href="http://www.quartus.net/cgi-bin/twiki/view/Main/PrimaryColorForth"&gt;PrimaryColorForth&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The goal here is to simply reproduce all of the examples from chapter 1 of &lt;a href="http://home.iae.nl/users/mhx/sf1/sf1.html"&gt;Starting Forth&lt;/a&gt; in &lt;a href="http://www.quartus.net/cgi-bin/twiki/view/Main/ColorForth"&gt;ColorForth&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Washing Machine Example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;washer&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;wash spin rinse spin ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In ColorForth red words signify the start of a new definition.  So "&lt;span style="color: rgb(255, 0, 0);"&gt;washer&lt;/span&gt;" is the new procedure.  The ";" represents the call return.   The green words are procedures that have already been defined.  Let's look at the definition of rinse.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;rinse &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;faucets open till-full faucets close ;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The definition includes "things" (faucets) and verbs (open and close).  The word "till-full" represents a delay loop.  After the faucets "open" the word waits "till-full" before they "close".&lt;br /&gt;&lt;br /&gt;Note.  Unlike traditional Forth words cannot be defined from the command line.  All words must be defined in the &lt;a href="http://www.quartus.net/cgi-bin/twiki/view/Main/PrimaryColorForthEditor"&gt;editor&lt;/a&gt;.  Then the block containing the source text must be loaded.  For example if you defined some new words in block 22 you would type:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;22 load&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Putting on a show&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Forth was originally designed around a TTY display model.  But ColorForth uses a GUI display, albeit one that is MUCH simpler than MS Windows, X-Windows or MacIntosh.  So getting things displayed on the screen is a bit tricker than traditional Forth, but simpler than raw programming of most GUI operating system.  The ColorForth word "show" creates a display task using the words following it.&lt;br /&gt;&lt;br /&gt;Consider this definition.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;show text 45 emit keyboard ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This creates a new definition "ok" that draws a "*" at the top left corner of the screen.  The word "text" moves the cursor to the top left of the screen and sets the drawing color to white.  The word "emit" takes a number off the stack and draws the corresponding charecter.  It's the same as "emit" in traditional Forth.  Note that the charecter set is different from ASCII.  The word "keyboard" redraws the keyboard and stack.&lt;br /&gt;&lt;br /&gt;Chapter 1 of Starting Forth builds up an example on how to draw the letter "F" as a large charecter using "ASCII art".  Here is a walkthrough of that example using colorForth.&lt;br /&gt;&lt;br /&gt;The first word "space" draws a blank space on the screen.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;space &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;0 emit ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The next word "spaces" draws a certain number of spaces.  For instance "5 spaces" would draw 5 spaces.  Note that the "for..next" loop will be covered in detail later.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;spaces &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;for space next ; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The word "star" is similar to "space" but draws a star.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;star &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;45 emit ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The word "stars is similar to "spaces" but draws a number of stars.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;stars &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;for star next ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The next words define the "F" using combinations of the above defined words.  Note that "cr" stands for "carriage return".  That simply moves the cursor to the next line.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;side &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;star spaces star ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;margin&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;cr 30 spaces ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;blip &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;margin star ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;bar &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;margin 5 stars ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;f&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;bar blip bar blip blip cr ;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ok&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;show text f keyboard ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;After loading the block containing these words and typing "ok" from the command line a large "F" will be displayed on the screen.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-123568583200003285?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/123568583200003285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=123568583200003285' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/123568583200003285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/123568583200003285'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2006/12/starting-forth-chapter-1-examples.html' title='Starting Forth chapter 1 examples.'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2678811648497643881.post-7981581527977379717</id><published>2006-12-21T11:35:00.000-08:00</published><updated>2009-06-14T04:33:11.279-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='colorforth'/><title type='text'>Re-starting "Primary Colorforth"</title><content type='html'>Hello all.  Some months ago I announced that I was working on a tutorial for ColorForth called &lt;a href="http://www.quartus.net/cgi-bin/twiki/view/Main/PrimaryColorForth"&gt;Primary ColorForth&lt;/a&gt;.  It is a play on words for the Leo Brodie classic &lt;a href="http://home.iae.nl/users/mhx/sf.html"&gt;Starting Forth&lt;/a&gt;.  The plan was (and still is) to build a tutorial that follows the "spirit" of Starting Forth while departing from it when necessary to better fit the ColorForth model.  I made a little progress.  (Actually Jeff Fox made a bigger contribution than I did with his "&lt;a href="http://www.quartus.net/cgi-bin/twiki/view/Main/PrimaryColorForthEditor"&gt;Editor&lt;/a&gt;" chapter.)&lt;br /&gt;&lt;br /&gt;However the project got stalled.  Part of the problem is that I got waylaid by other projects.  But another bigger problem was the classic "chicken and egg" problem.  Some of the examples I wanted to do in the first chapter required advanced concepts that I didn't want to cover until other chapters.  I was really stuck.  Then, in a discussion with Jeff Fox in the USENET group comp.lang.forth about learning VentureForth I got an idea.  Jeff suggested that someone learning VentureForth should try to do the examples from Staring Forth in it.  I found then (and still find) that a daunting prospect.  But I knew I could many of them in ColorForth so I decided to try.  Then while reading the first chapter I noticed that Brodie put some advance code in an example and simply said &lt;span style="font-style: italic;"&gt;we'll explain how it works in a later chapter&lt;/span&gt;.  Now why did &lt;span style="font-style: italic;"&gt;I&lt;/span&gt; think of that?&lt;br /&gt;&lt;br /&gt;So I'm restarting my efforts.  Things that I need to explain later, I'll just note and explain later.  It's good to be back!&lt;br /&gt;&lt;br /&gt;I'm going to use the blog to track my progress.  While the tutorial will be built here, this won't be the final "polished" version.  That will be put at the &lt;a href="http://www.quartus.net/cgi-bin/twiki/view/Main/ColorForth"&gt;ColorForth Wiki&lt;/a&gt;.  I don't want to be slowed down by trying to be "perfect" the first time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2678811648497643881-7981581527977379717?l=primarycolorforth.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://primarycolorforth.blogspot.com/feeds/7981581527977379717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2678811648497643881&amp;postID=7981581527977379717' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/7981581527977379717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2678811648497643881/posts/default/7981581527977379717'/><link rel='alternate' type='text/html' href='http://primarycolorforth.blogspot.com/2006/12/re-starting-primary-colorforth.html' title='Re-starting &quot;Primary Colorforth&quot;'/><author><name>johnmdrake</name><uri>http://www.blogger.com/profile/08149380469759920889</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry></feed>
