Skip to content
TurtleKitty edited this page May 18, 2019 · 3 revisions

sys

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

sys.opt This contains a table of command line options prefixed by - or --.

sys.rest This contains a list of command line options not prefixed by dashes.

; cli.vaq
#!/usr/local/bin/vaquero run
(say (list sys.opt sys.rest))

; command line

home> ./cli.vaq foo bar baz -x 2 -y 3 --foonballardy 42
(#(table x 2 y 3 foonballardy 42) (foo bar baz))

sys.time sys.ts
Time functions.

(sys.time)  ; 1558137209
sys.ts      ; 1558137210

(sys.srand )

Seed the pseudorandom number generator with the bytes from <text>.

(def seed (uuid)) ; "d9acd603-62fa-4ecf-315b-2f7c6926792e"

(sys.srand seed)  ; null

(ndx 2 6) ; 7
(ndx 2 6) ; 10
(ndx 2 6) ; 11
(ndx 2 6) ; 10
(ndx 2 6) ; 9
(ndx 2 6) ; 8
(ndx 2 6) ; 7
(ndx 2 6) ; 9
(ndx 2 6) ; 8
(ndx 2 6) ; 6
(ndx 2 6) ; 6

(sys.srand seed)  ; null

(ndx 2 6) ; 7
(ndx 2 6) ; 10
(ndx 2 6) ; 11
(ndx 2 6) ; 10
(ndx 2 6) ; 9
(ndx 2 6) ; 8
(ndx 2 6) ; 7
(ndx 2 6) ; 9
(ndx 2 6) ; 8
(ndx 2 6) ; 6
(ndx 2 6) ; 6

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 unix signals.

Note

Aside from stdout, stdin, and stderr, all operating system interfaces are contained within sys. If an imported module wants to open files, fork processes, or talk to the network, it has to be passed this capability from the top-level program. This gives Vaquero some degree of object capability security; untrusted code can be run in a sandboxed environment.

#!/usr/local/bin/vaquero run

; foo.vaq

(use bar "bar.vaq")

(def my-bar (bar.create sys.proc))

(my-bar)
; bar.vaq

(export create)

(proc create (sys-proc)
   (proc ()
      (proc f ()
         (proc go (n)
            (say n)
            (sys-proc.sleep (ndx 2 6)))
         (go 1)
         (go 2)
         (go 3)
         (say "Gone!")
         (sys-proc.exit))
      (each n (range 1 5)
         (sys-proc.fork f))
      null))
; command line

home> ./foo.vaq 
1
1
1
1
1
home> 2
3
2
2
Gone!
2
2
3
3
3
Gone!
3
Gone!
Gone!
Gone!
Clone this wiki locally