{"id":57,"date":"2014-04-24T16:35:01","date_gmt":"2014-04-24T20:35:01","guid":{"rendered":"\/?p=57"},"modified":"2014-04-24T16:35:01","modified_gmt":"2014-04-24T20:35:01","slug":"what-is-in-a-hello-world-program","status":"publish","type":"post","link":"\/2014\/04\/24\/what-is-in-a-hello-world-program\/","title":{"rendered":"What is in a Hello World Program"},"content":{"rendered":"
The simplest Hello World<\/strong> program in Forth is probably this:<\/p>\n And you run it by typing its name, like so:<\/p>\n But what does it do behind the scenes? Of course we can:<\/p>\n In fact the Embeddable Forth Command Interpreter published on this website generates the same code for these two — but most systems actually don’t. Needless to say that the Forth standard defines S"<\/span> as part of the CORE<\/strong> words while SLITERAL<\/span> is defined in the optional STRING <\/strong>words. Talk about cart before the horse<\/em>…<\/p>\n Using these, here is a usable definition for ."<\/span> :<\/p>\n Note: This really only works with the version of S"<\/span> in the CORE<\/strong> words, later on it is redefined in the FILE ACCESS<\/strong> words to have a different execution semantics and the standard declares it non-standard use to apply POSTPONE<\/span> to S"<\/span> thereby making everyone’s life a lot harder than it needs to be.<\/p>\n","protected":false},"excerpt":{"rendered":" The simplest Hello World program in Forth is probably this: And you run it by typing its name, like so: But what does it do behind the scenes? The word is really just a programmer convenience even though it has … Continue reading \r\n: HELLO-WORLD ( -- ) ." Hello World!" ;\r\n<\/pre>\n
\r\nHELLO-WORLD\r\n<\/pre>\n
\nThe word ."<\/span> is really just a programmer convenience even though it has been around almost as long as Forth has. But could we write the a Hello World<\/strong> program without it? <\/p>\n\r\n: HELLO-WORLD ( -- ) S" Hello World!" TYPE ;\r\n<\/pre>\n
\nAnd to show how Forth words are being created by extending Forth, here is a definition of the word S"<\/span> (the version defined in CORE<\/strong> words) using other words in the standard:<\/p>\n\r\n: S" ( -- ) ( R: -- caddr count ) \r\n [CHAR] " PARSE POSTPONE SLITERAL ; IMMEDIATE\r\n<\/pre>\n
\r\n: ." ( -- ) \r\n POSTPONE S" POSTPONE TYPE ; IMMEDIATE\r\n<\/pre>\n