From b0196162a903819a807b89f2e9bc9e6d44b371ed Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Sat, 9 May 2015 10:39:02 -0700 Subject: [PATCH] Completed FORTH command line arg printing and added comments to document example better. --- forth/hello.fs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/forth/hello.fs b/forth/hello.fs index 3ce247e..e8408dc 100755 --- a/forth/hello.fs +++ b/forth/hello.fs @@ -3,15 +3,31 @@ \ Sample Hello World! Forth script... \ +\ Define "verinfo" : verinfo s" git describe --abbrev=7 --dirty --always --tags" system ; +\ Define "printargs" +: printargs + \ The argc variable contains the count of cmd line args + \ in gforth, so we put it's value (@) on the stack plus + \ the number one and test if the value is greater than one. + argc @ 1 > if + \ condition is true, so put the value of argc (@) + \ on the stack and the value one as the range of + \ our do loop - we don't pring arg 0 which is the + \ name of the program. + argc @ 1 do i arg type space loop cr + else + \ condition is false, so don't print anything + cr + then ; + + \ Obligatory Hello World with some version info .( Hello Forth World! Version: ) verinfo cr + \ Show list of command line arguments -: printargs - argc @ 0 do i arg type cr loop ; -.( Command line args: ) cr -printargs +.( Command line args: ) printargs bye