Utility Keywords
NOTE: All of these Utility functions are temporarily deactivated as of v0.27.3 (August 3, 2021). The grammar is getting reworked to reduce inconsistent behavior and be more user friendly. All of these features will be readded into the grammar slowly, as applicable.
Print Functions
XCS provides a flexible keyword for sending text to standard I/O.
Standard print
functionality is provided for each of XCS's primitive types (see Literal Values).
print "Hello World!";;
print 1 + 2 / 3;;
Overriding for Custom Types
To implement the print for a user-defined data type (e.g. using type
keyword), use the following syntax:
let (print) coordinates = print ("x: " ++ (String coordinates.x) ++ ", y: " ++ (String coordinates.y));;
Random Number Generator
Random Numbers can be produced on demand:
(rand);;
(rand seed);;
As of now, random numbers are restricted to 32-bit integer values.
Timers
The duration of an expression can be measured by using Timers; these return the result/duration.
let timed_addition = timer (rand + 1 + rand + 2 + rand);;
The result and duration of the expression can then be returned as such:
timed_addition.{0};; (* Resulting Value *)
timed_addition.{1};; (* Duration of Execution (milliseconds) *)
Delay Execution
XCS provides a keyword for delaying a period of time before executing an expression:
delay 3000 timed_addition.{0};; -- Wait 3 seconds, then perform 'timed_addition'