{"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

\r\n: HELLO-WORLD ( -- ) ." Hello World!" ;\r\n<\/pre>\n

And you run it by typing its name, like so:<\/p>\n

\r\nHELLO-WORLD\r\n<\/pre>\n

But what does it do behind the scenes?
\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

Of course we can:<\/p>\n

\r\n: HELLO-WORLD ( -- ) S" Hello World!" TYPE ;\r\n<\/pre>\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.
\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

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

\r\n: ." ( -- )  \r\n     POSTPONE S" POSTPONE TYPE ; IMMEDIATE\r\n<\/pre>\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 →<\/span><\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[7],"_links":{"self":[{"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/posts\/57"}],"collection":[{"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":0,"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"wp:attachment":[{"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/forth.teleonomix.com\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}