Skip to content

Example 2 inline python

H.C. Chen edited this page Sep 3, 2017 · 9 revisions

peforth like eforth attempts to use very basic words to build the entire forth system. Actually, peforth is started with only two words 'code' and 'end-code'.

To define a code word, we press Ctrl-D to make the Windows DOS box environment to accept multiple lines at once as the input then type in the example and at the end another Ctrl-D to terminate the multiple line input.

OK ^D
code hello
    print('hello world!\n')
end-code
^D
OK hello
hello world!

OK see hello
{
    "__class__": "Word",
    "__module__": "peforth.projectk",
    "name": "hello",
    "xt": {
        "__class__": "function",
        "__module__": "peforth.projectk",
        "name": "hello"
    },
    "immediate": false,
    "help": "",
    "comment": "",
    "vid": "forth",
    "wid": 243,
    "type": "code"
}
------------ Source code ------------
def xt(_me=None): ### hello ###
    print('hello world!\n')

-------------------------------------
OK

Where _me refers to the forth word object itself if you need to access its own attributes.

Clone this wiki locally