Create a BASIC Computer
Arguments
- registers
A list of registers
- functions
A list of functions. Registers can be referred to with
self[[register_name]]
. They must have two arguments,x
andy
, even if only one is used. The index is iterated withprivate$.inc(j)
wherej
is the number of places to "jump." Example:\(x, y) private$.inc(self[[x]])
will incrementself$index
byself[[x]]
.- increment
(Default:
1
) The number of places to increment by default.- regex
(Default:
"[, \\+]+"
) The pattern to use for stringr::str_split
Value
A new R6 object with registers
and functions
as the fields and
methods, respectively. Along with the functions detailed in the details
section.
Details
try_numeric(x)
: Takes input and tries to cast it as numeric. If that fails, it returns the
original object.
val_or_index(x)
: If x
is numeric, return x
, otherwise return self[[x]]
.
call(f, x, y)
: Calls one of functions
using x
and y
as arguments.
There are two ways the function can be used:
f
is not length one andx
andy
are null, thenf[1](f[2], f[3])
f
is length one, andx
andy
are not null, thenf(x, y)
run(x, target, until, pattern)
: Tries to run the instructions provided by x
. If x
is a character
vector, it will try to split the instructions into a segments for
call(f, x, y)
.
x
: A character vector of instructions asc("f x y")
or a list of character vectors in the formatlist(c("f", "x", "y"))
target
: (Default:NULL
) Theregister
to print as the final result. IfNULL
,self
will be printed.pattern
: See theregex
argument for more details.
.inc(increment)
: A private function used to increment self$index
by increment
.