use pipe> in atua-gophermap.forth

FossilOrigin-Name: c026ff5dfaddd71f8652fd7cb747e4b245dbb5e32232ec4e98222145101b6f95
This commit is contained in:
crc 2019-05-07 20:45:03 +00:00
parent 62217a5bb0
commit 74ef7c040f

View file

@ -23,15 +23,20 @@ examination or manipulation.
# The Code # The Code
I begin by creating a word to return the number of files in I begin by defining a word for dealing with pipes.
the current directory. This makes use of a Unix pipe to run
~~~
: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 `ls -l | wc -l` and capture the result. I trim off any
whitespace and convert to a number. whitespace and convert to a number.
~~~ ~~~
:unix:count-files (-n) :unix:count-files (-n)
'ls_-1_|_wc_-l file:R unix:popen 'ls_-1_|_wc_-l pipe> s:trim s:to-number ;
[ file:read-line s:trim s:to-number ] [ unix:pclose ] bi ;
~~~ ~~~
Next, a word to identify the current working directory. This Next, a word to identify the current working directory. This
@ -39,8 +44,7 @@ also uses a pipe to `pwd`.
~~~ ~~~
:unix:get-cwd (-s) :unix:get-cwd (-s)
'pwd file:R unix:popen 'pwd pipe> s:trim '/ s:append ;
[ file:read-line s:trim ] [ unix:pclose ] bi '/ s:append ;
~~~ ~~~
The program accepts a single command line argument: the The program accepts a single command line argument: the