Returns the contents of the file named name as a string. Note that name may be an expression returning a string.
Returns the contents of the file named name as a binary string.
> Read("mystery.c");
#include <stdio.h>
main(argc, argv)
int argc;
char **argv;
{
int n, i;
n = atoi(argv[1]);
for (i = 1; i <= n; i++)
printf("%d\n", i * i);
return 0;
}
> System("cc mystery.c -o mystery");
> mysteryMagma := function(n)
> System("./mystery " cat IntegerToString(n) cat " >outfile");
> output := Read("outfile");
> return StringToIntegerSequence(output);
> end function;
> mysteryMagma(5);
[ 1, 4, 9, 16, 25 ]
The intrinsics in this section are not currently available on Windows platforms. This will be addressed in a future release.
Given a shell command cmd and an input string input, run cmd in a new process with input as its input and return the output of this command as a string. Note that for many commands, input should finish with a new line character if it consists of only one line.
Given a sequence of shell commands cmds and a sequence of input strings inputs, run each command in cmds in a new process with the corresponding element of inputs as its input. Returns the sequence of outputs (as strings) of the commands.
> mysteryMagma := function(n)
> cmd := Sprintf("./mystery %o", n);
> output := Pipe(cmd, "");
> return StringToIntegerSequence(output);
> end function;
> mysteryMagma(5);
[ 1, 4, 9, 16, 25 ]
> letters := "abcdefghijklmnopqrstuvwxyz";
> shiftcmd := func<n | Sprintf("tr 'a-z' '%o-za-%o'", letters[n+1], letters[n])>;
Then we form the commands for shifting by amounts from 1 to 13 and apply
them to some well-chosen inputs.
> cmds := [ shiftcmd(n) : n in [1..13] ]; > inputs := > [ > "steeds", "pyic", "dolt", "pecan", "fizzy", "fusion", "inkier", "talk", > "sleep", "cubed", "spots", "road", "nowhere" > ]; > Pipe(cmds, inputs); [ tuffet, rake, grow, tiger, kneed, layout, purply, bits, bunny, melon, dazed, damp, abjurer ]
This statement will cause Magma to assign to the given identifier the string of characters appearing (at run-time) on the following line. This allows the user to provide an input string at run-time. If the optional prompt is given (a string), that is printed first.
This statement will cause Magma to assign to the given identifier the literal integer appearing (at run-time) on the following line. This allows the user to specify integer input at run-time. If the optional prompt is given (a string), that is printed first.