-
Notifications
You must be signed in to change notification settings - Fork 4
Basic IO
tim-hardcastle edited this page Aug 29, 2023
·
17 revisions
All Charm scripts automatically import a library called world.ch. 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 Charm 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 Charm. For now, let's look at the contents of the built-in world library.
get commands typically take the form get <variable name> from <source>.
-
get x from File(<string>)setsxequal to the contents of the given file. -
get x from File(<string>, <type>)setsxequal 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>)setsxequal totrueorfalsedepending on whether the file does in fact exist. -
get x from Input(<string>)setsxequal to the response we get when prompting the end-user with the given string. -
get x from Random(<integer>)setsxequal to a random integer less than the supplied integer. -
get x from Random(<list>)setsxequal to a random element of the list. -
get x from UnixClock(<TimeUnit>) setsxequal to the Unix epoch in the given unit, whereTimeUnitis an enum with valuesSECONDS,MILLISECONDS, andNANOSECONDS`.
🧿 Pipefish is distributed under the MIT license. Please steal my code and ideas.
- Getting started
- Language basics
- The type system and built-in functions
- Functional Pipefish
- Encapsulation
- Imperative Pipefish
-
Imports and libraries
- The crypto/aes library
- The crypto/bcrypt library
- The crypto/rand library
- The crypto/rsa library
- The crypto/sha_256 library
- The crypto/sha_512 library
- The database/sql library
- The encoding/base_32 library
- The encoding/base_64 library
- The encoding/csv library
- The encoding/json library
- The files library
- The fmt library
- The html library
- The image library
- The image/bmp library
- The image/color library
- The image/jpeg library
- The image/png library
- The lists library
- The markdown library
- The math library
- The math/big library
- The math/cmplx library
- The math/rand library
- The net/http library
- The net/mail library
- The net/smtp library
- The net/url library
- The os/exec library
- The path library
- The path/filepath library
- The reflect library
- The regexp library
- The strconv library
- The strings library
- The terminal library
- The time library
- The unicode library
- Advanced Pipefish
- Developing in Pipefish
- Deployment
- Appendices