From 74ef7c040ffdd81608c0cc6d52a53dabf6bd8ccd Mon Sep 17 00:00:00 2001 From: crc Date: Tue, 7 May 2019 20:45:03 +0000 Subject: [PATCH] use pipe> in atua-gophermap.forth FossilOrigin-Name: c026ff5dfaddd71f8652fd7cb747e4b245dbb5e32232ec4e98222145101b6f95 --- example/atua-gophermap.forth | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/example/atua-gophermap.forth b/example/atua-gophermap.forth index 22d98d1..8144730 100755 --- a/example/atua-gophermap.forth +++ b/example/atua-gophermap.forth @@ -23,15 +23,20 @@ examination or manipulation. # The Code -I begin by creating a word to return the number of files in -the current directory. This makes use of a Unix pipe to run +I begin by defining a word for dealing with pipes. + +~~~ +:pipe> (s-s) file:R unix:popen [ file:read-line ] [ unix:pclose ] bi ; +~~~ + +I then create a word to return the number of files in the +current directory. This makes use of a Unix pipe to run `ls -l | wc -l` and capture the result. I trim off any whitespace and convert to a number. ~~~ :unix:count-files (-n) - 'ls_-1_|_wc_-l file:R unix:popen - [ file:read-line s:trim s:to-number ] [ unix:pclose ] bi ; + 'ls_-1_|_wc_-l pipe> s:trim s:to-number ; ~~~ Next, a word to identify the current working directory. This @@ -39,8 +44,7 @@ also uses a pipe to `pwd`. ~~~ :unix:get-cwd (-s) - 'pwd file:R unix:popen - [ file:read-line s:trim ] [ unix:pclose ] bi '/ s:append ; + 'pwd pipe> s:trim '/ s:append ; ~~~ The program accepts a single command line argument: the