Skip to content
Turtle Kitty edited this page Jan 28, 2016 · 10 revisions

sys

This object is magic. It exists only at the top level of the program.

sys.stdin sys.stdout sys.stderr
Standard input, output, and error ports.

sys.read
Shorthand for sys.stdin.read.

sys.write
Shorthand for sys.stdout.write.

sys.print
Shorthand for sys.stdout.print.

sys.say
Shorthand for sys.stdout.say.

sys.carp
Shorthand for sys.stderr.say.

sys.test
Takes a name and an expression.
If the expression evaluates to true, it prints (name ok).
If false, it prints (name FAIL).

sys.time sys.ts
Time functions.

(sys.time)
    -> 1439167942

sys.ts
    -> 1439167942

(sys.srand n)

Seed the pseudorandom number generator with the value n.

(sys.srand 99999)
    -> null

(ndx 10 6)
    -> 31

(ndx 10 6)
    -> 41

(ndx 10 6)
    -> 34

(sys.srand 99999)
    -> null

(ndx 10 6)
    -> 31

(ndx 10 6)
    -> 41

(ndx 10 6)
    -> 34

sub-objects

sys contains sub-objects with specific purposes:

sys.env contains environment variables from outside the program.
sys.fs is the interface to the file system.
sys.proc controls processes.
sys.net allows network access.
sys.signal lets one send and receive *nix signals.

Note

All operating system interfaces are contained within sys - if an imported module wants to open files, fork processes, or print to stdout, it has to be passed this capability in the call to load by the top-level program. This gives Sexy some degree of object capability security; untrusted code can be run in a sandboxed environment.

; foo.sxy

#!/usr/bin/sexy run
(load "bar.sxy" sys.say sys.proc)

; bar.sxy

(lib (say proc)
    (fun f ()
        (fun go (n)
            (say n)
            (proc.sleep (ndx 2 6)))
        (go 1)
        (go 2)
        (go 3)
        (say "Gone!")
        (proc.exit))
    (each n (range 1 5)
        (proc.fork f))
    'null)

; command line

home> ./sexy run foo.sxy
1
1
1
1
1
2
2
2
2
2
3
Gone!
3
3
3
3
Gone!
Gone!
Gone!
Gone!
Clone this wiki locally