Last active
August 16, 2019 22:59
-
-
Save wspeirs/dcb77bb4c216bf307a95a196f0728fe1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const x:num = 123.456; // this is a constant that never changes | |
const y:str = "hello world"; // constant string literal | |
var a:str = "hello"; // create a string variable, and assign to string literal | |
var b:num = 23.4; // create a number variable, and assign number | |
var c:str[] = ["hello", "world"]; // create an array variable, assign literal | |
CWD = "/path/to/current/directory"; // CWD is a special variable that can be set or read, and represents the current working directory | |
print(ARG[0]); // ARG is a spcecial variable that can only be read; it is a str[]. The first argument (zero index) is the first argument passed to the script. | |
// the main point of the language is executing other programs and managing STDOUT and STDERR and the return codes | |
// all programs are executed via the built-in run command | |
run("/path/to/program"); | |
// the built-in run function returns a named tuple so that you can get the exit code, STDOUT, and STDERR | |
var (exit_code:num, stdout:pipe, stderr:pipe) = run("/path/to/program"); | |
// you can get any of the items from the tuple via their name if you don't need them all | |
var exit_code = run("/path/to/program").exit_code | |
// pipes are special variable types, they cannot be created directly, only from running commands | |
// they are used to control the input and output of a command, and can be chained together in interesting ways: | |
// - + using the plus sign, will read line-by-line a pipe until EOF is read, then read the next one | |
// - zip will interleave line-by-line two pipes, continuing to read whichever pipe is longer | |
// you can use the .run method on any pipe to send it as input to another program | |
var out_a:pipe = run("/path/to/program_a").stdout; | |
var out_b:pipe = run("/path/to/program_b").stdout; | |
(out_a + out_b).run("/path/to/program_c").exit_code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment