(D) C-Library Extensions

Abstract

Inlab Scheme offers a group of expressions and procedures which interface directly to the Standard C-Library of the host operating system (Linux or macOS). In the case that you are missing a specific functionality in this area, just let us know.

C-Library Extension Procedures

argument-vector

(argument-vector) returns the current Unix argv[] of the interpreter invocation as a vector of strings.

[1] (argument-vector)
#("./scheme")
[2]

argv

(argv) returns the current Unix argv[] of the interpreter invocation as a list of strings.

argv is implemented as follows:

[1] (argv)
("./scheme")
[2] (pp argv)
(lambda () (vector->list (argument-vector)))
ok
[3]

rand

(rand) returns a pseudo random signed integer invoking rand().

Example:

[1] (rand)
727386614
[2]

sleep

(sleep <seconds>) interfaces the sleep() C-Library system call. Inlab Scheme suspends its execution the supplied number of seconds. The invocation (sleep 0) returns immediately, passing a negative value is not allowed.

[1] (sleep 2)
ok
[2] (sleep 0)
ok
[3] (sleep -1)

ERROR!
  message   : invalid negative value
  irritant  : #<primitive-procedure sleep>
  expression: -1
  continue  : possible, continue with value as value from primitive

Error (? for help) >>

system

(system <command>) invokes the system() call passing the string as a command to be executed by the sh command interpreter. The exit code of this execution is returned as an integer.

Example:

[1] (system "echo hello")
hello
0
[2] (system "notfound")
sh: notfound: command not found
127
[3] (system "exit 3")
3
[4]

usleep

(usleep <seconds>) interfaces the usleep() C-Library system call. Inlab Scheme suspends its execution the supplied number of microseconds. The invocation (usleep 0) returns immediately, passing a negative value is not allowed.

[1] (usleep 2000)
ok
[2] (usleep 2000000)
ok
[3]