-
Notifications
You must be signed in to change notification settings - Fork 4
Example 1 Hello world!
All peforth words have their help message.
: hi ( -- ) // The hello world! command
." Hello World!!" cr ;
/// if help message is not enough then use /// leading lines to add comments.
/// Both // and /// leading messages go to the last word.
The first stack diagram ( -- ) and the // leading comment line become help messages. The stack diagram indicates that the hi command does not use any operand from the data stack before its execution and also does not push back anything when it finished its job. When stack diagrams appear at places other than right after a colon definition like this example they are comments.
OK hi
Hello World!!
OK help hi
( -- ) The hello world! command
if help message is not enough then use one or more /// leading lines to add comments.
Both // and /// leading messages go to the last word.
'see' command to see a word's source code and other details.
OK see hi
{
"__class__": "Word",
"__module__": "peforth.projectk",
"name": "hi",
"xt": {
"__class__": "function",
"__module__": "peforth.projectk"
},
"immediate": false,
"help": "( -- ) The hello world! command",
"comment": "\tif help message is not enough then use one or more /// leading lines to add comments.\n\tBoth // and /// leading messages goes to the last word.\n",
"vid": "forth",
"wid": 242,
"type": "colon",
"private": false,
"cfa": 717
}
------------ Definition in dictionary ------------
00717: Literal: Hello World!! <class 'str'>
00718: . ( x -- ) Print the TOS __str__ (<class 'peforth.projectk.Word'>)
00719: cr ( -- ) print a carriage return __str__ (<class 'peforth.projectk.Word'>)
00720: RET (<class 'NoneType'>)
------------ End of the difinition ---------------
OK
'words' command lists all recent words.
OK words
code end-code \ // <selftest> </selftest> bye /// immediate stop compyle trim indent -indent
<py> </py> </pyV> words . cr help interpret-only compile-only literal reveal privacy (create)
: ; ( BL CR word ' , [compile] py: py> py:~ py>~ 0branch here! here swap ! @ ? >r r> r@ drop
dup over 0< + * - / 1+ 2+ 1- 2- compile if then compiling char last version execute cls
private nonprivate (space) exit ret rescan-word-hash (') branch bool and or not (forget) AND
OR NOT XOR true false "" [] {} none >> << 0= 0> 0<> 0<= 0>= = == > < != >= <= abs max min
doVar doNext depth pick roll space [ ] colon-word create (marker) marker next abort alias <>
public nip rot -rot 2drop 2dup invert negate within ['] allot for begin until again ahead
never repeat aft else while ?stop ?dup variable +! chars spaces .( ." .' s" s' s` does> count
accept accept2 <accept> nop </accept> refill [else] [if] [then] (::) (:>) :: :> ::~ :>~
"msg"abort abort" "msg"?abort ?abort" '<text> (<text>) <text> </text> <comment> </comment>
(constant) constant value to tib. >t t@ t> [begin] [again] [until] [for] [next] modules int
float drops dropall char>ASCII ASCII>char ASCII .s (*debug*) *debug* readTextFile
writeTextFile tib.insert sinclude include type obj>keys obj2dict stringify toString .literal
.function (dump) dump dump2ret d (see) .members .source see dos cd slice win32com.client
WshShell description expected_rstack expected_stack test-result [all-pass] *** all-pass [r r]
[d d] [p p] inport OK dir keys screen-buffer display-off display-on ---
OK
'help ' command to view any word's help message, as mentioned above.
OK help +
( a b -- a+b) Add two numbers or concatenate two strings.
OK
or only 'help' to list them all.
OK help
code ( <name> -- ) Start composing a code word.
end-code ( -- ) Wrap up the new code word.
\ ( <comment> -- ) Comment out the rest of the line
// ( <comment> -- ) Give help message to the last word
<selftest> ( <statements> -- ) \ Collect self-test statements. interpret-only
</selftest> ( "selftest" -- ) Save the self-test statements to <selftest>.buffer. interpret-only
bye ( ERRORLEVEL -- ) Exit to shell with TOS as the ERRORLEVEL.
/// ( <comment> -- ) Add comment to the new word, it appears in 'see'.
immediate ( -- ) Make the last new word an immediate.
stop ( -- ) Stop the TIB loop
compyle ( "source" -- function ) Compile source code to a python function
The given one line or multiple lines function body with NO argument
will be converted to an annoymous function left on TOS. Intent problem
is moderated.
Usage: "...python code..." compyle execute
... snip ...
Supplement to Know the FORTH programming language in one page this probably is enough to know about the basics of FORTH, at least peforth, for your debugging use. Let me know about your questions, by open issues to this GitHub project, to let me know where to improve the introductions. Thank you in advance!
H.C.Chen @ FigTaiwan
hcchen5600@gmail.com
Just undo it!