-
Notifications
You must be signed in to change notification settings - Fork 6
Basic IO
All Pipefish scripts automatically import a library called world.pf
. This contains some commands and types that let you perform basic IO.
It does this in ways that are entirely extensible and customizable: you can use Pipefish to talk to whatever applications or devices your OS can talk to. We will discuss how to write libraries for such purposes in the section on Advanced Pipefish. For now, let's look at the contents of the built-in world
library.
get
commands perform input. They typically take the form get <variable name> from <source>
. Apart from the commands for handling SQL and microservices, the following commands are available:
-
get x from File(<string>)
setsx
equal to the contents of the given file. -
get x from File(<string>, <type>)
setsx
equal to the contents of the given file as a string if the type isstring
, and broken into a list of strings at the newlines of the file if the type islist
. -
get x from FileExists(<string>)
setsx
equal totrue
orfalse
depending on whether the file does in fact exist. -
get x from Input(<string>)
setsx
equal to the response we get when prompting the end-user with the given string. -
get x from Random(<integer>)
setsx
equal to a random integer less than the supplied integer. -
get x from Random(<list>)
setsx
equal to a random element of the list. -
get x from UnixClock(<TimeUnit>)
setsx
equal to the Unix epoch in the given unit, whereTimeUnit
is an enum with valuesSECONDS
,MILLISECONDS
, andNANOSECONDS
.
These commands are used to perform output. Their meanings are based on HTTP:
-
put
represents output which would have the same effect if you did it several times as if you did it once, such as writing a file to disc. -
post
represents output which has a distinct effect each time you do it, such as writing text to the terminal. -
delete
is always implemented so that if the thing to be deleted already doesn't exist, this is counted as a success rather than an error.
Apart from the commands for handling SQL and microservices, the following commands are available:
-
post (<tuple>) to Output()
posts the values given to the current output. -
post (<tuple>)
posts toOutput()
by default. -
post (<tuple>) to Terminal()
posts the values given to the terminal. For now you may see little difference between that andpost (<tuple>)
, but the difference will become apparent later. -
put (<int>) into RandomSeed()
seeds the random number generator. -
put (<string>) into File(<filename>)
puts the given string into the file, creating it if it doesn't exist. -
delete File (<filename>)
deletes the given file.
🧿 Pipefish is distributed under the MIT license. Please steal my code and ideas.