Double-U is a command-based language. Code is interpreted rather than compiled, meaning that an error will not cause the code preceding it to fail.
Unlike most programming language, most Double-u functions are non-deterministic.
For example, select!
will return a random element from the given array.
The main data structure of Double-U is the array, which can be specified as for
example, [ 1 2 4 ]
. The various built-in functions are able to manipulate
arrays to produce interesting results.
let <name> = <value>
- assigns value to name, where value can be an array or int.
print <var>
- outputs the value of var to standard out.
define <cmd> = <fn>! ... <fn>!
- creates a new function cmd with the specified behaviour.
merge! <var1> <var2>
- combines the values of var1 and var2 into a new array.
<fn>! <arr>
- calls the list function fn! with arr as the parameter (see below)
See example.doubleu for concrete examples of these functions and their uses.
remove! <arr>
- removes an element, chosen at random, from the array
select! <arr>
- chooses a random element of the array
mode! <arr>
- chooses one of the most frequently occuring elements of the array
average! <arr>
- randomly returns either the mean, median, or mode of the array
std! <arr>
- calculates the standard deviation of the array
trim! <arr>
- calls remove! [arr]
a number of times proportional to std! [arr]
normalize! <arr>
- calculates and returns the standard score of each element in the array
wrap! <n>
- creates an array of n elements, each chosen at random from the range [0,1000]
twist! <n>
- returns a number in the range [n, 1000] or if n > 1000, the range [0, n]
chain! <n>
- chains together a random selection of n commands
Run the REPL using ruby doubleu.rb
from the command line. Type the command help!
to see the full list of available commands. You can use _
in an expression to substitute the value of the previous command executed. ^C
will clear the current line and stop any commands currently running. ^D
will exit the REPL.
Using the -s
or --string
option will replace string occurences by an array of ints everywhere in the program. For example, "doubleu"
would become [100, 111, 117, 98, 108, 101, 117]
. This option also works in the REPL.
Using the -p
or --print
option will output all arrays as strings. -s
and -p
can be combined to allow string manipulation in Double-U.
Using the -r
or --restrict
option will ensure that arrays built by build!
or wrap!
will only contain ints in the range [32-126] (printable ascii).
Arguments can be passed to a Double-U script like this: ruby doubleu.rb <script>.doubleu <arg1> <arg2>...
. Arguments can be accessed in a Double-U script using the special variables _1
, _2
, etc. Be careful though, as these special variables can be overwritten; in a sense they are just like any other variable.