Programmatic values and expressions: module venture.value.dicts¶
Programmatically construct literal Venture values and unannotated Venture abstract syntax.
If you are writing a parser for a VentureScript sublanguage, see
venture.parser.ast
for annotating the abstract syntax tree with the
location information the parser expects.
The main elements of constructing bare abstract syntax are
symbol
orsym
for variablesapp
for combining forms, whose components are abstract syntax- the other functions (
number
,boolean
, etc) for literals
Shortcuts for quote
, quasiquote
, and unquote
are provided as
conveniences, since those forms occur often in programmatically
constructed expressions.
-
venture.value.dicts.
app
(*items)¶ Construct a Venture combining form.
Each item must be a Venture object, as constructed by functions in this module.
Note that the result will not be evaluated as an application if the first item is a symbol which is a macro name or special form.
-
venture.value.dicts.
array
(vs)¶ Construct a Venture array.
The
vs
argument must be a Python sequence of Venture objects (constructed with other functions from this module).Arrays are combining forms when evaluated. The meaning of the array depends on the first element—if it is the name of a macro or special form, it will be evaluated accordingly. Otherwise, an array is an application.
A array quoted with
quote
will evaluate to a Venture array object.
-
venture.value.dicts.
array_unboxed
(vs, subtype)¶ Construct an unboxed Venture array.
The
vs
argument must be a Python sequence of Python objects, suitable for interpretation as Venture objects as by callingval
with thesubtype
argument.An unboxed array is semantically equivalent to the boxed array that would be constructed by
array([val(subype, v) for v in vs])
but more efficient.Unquoted unboxed arrays are evaluated like arrays, which is usually not what is desired.
-
venture.value.dicts.
atom
(v)¶ Construct a Venture atom.
Venture atoms are self-evaluating.
-
venture.value.dicts.
basic_val_content
(obj)¶ Returns the raw content of the Venture object
obj
.
-
venture.value.dicts.
basic_val_of_type_content
(tp, obj)¶ Returns the raw content of the Venture object
obj
if it has typetp
, elseNone
.Types as in
val
.
-
venture.value.dicts.
basic_val_type
(obj)¶ Returns the type of the Venture object
obj
.Types are as in
val
.
-
venture.value.dicts.
blob
(v)¶ Construct a Venture blob.
The object
v
becomes the payload of the blob, which Venture will carry around without inspecting. This is useful in conjunction with foreign SPs that can interpret the payload.Venture blobs are self-evaluating.
-
venture.value.dicts.
boolean
(v)¶ Construct a Venture boolean.
Venture booleans are self-evaluating.
-
venture.value.dicts.
dict
(d)¶ Construct a Venture dictionary.
The argument
d
must be a Python dictionary whose keys and values are Venture objects (constructed with other functions from this module).Venture dictionaries are self-evaluating.
-
venture.value.dicts.
improper_list
(vs, tail)¶ Construct an improper Venture list.
An improper list is one whose last pair has something other than
nil
in itssecond
field. You only need this if you know you need it.Improper lists are combining forms if the tail is a list (making the full list proper after all) or an array.
It is an error to evaluate an improper list that is not a combining form.
-
venture.value.dicts.
integer
(v)¶ Construct a Venture integer.
Venture integers are self-evaluating.
-
venture.value.dicts.
is_basic_val
(obj)¶ Checks whether
obj
is a valid unannotated literal Venture object.Only checks the top level, not recursively.
-
venture.value.dicts.
is_basic_val_of_type
(tp, obj)¶ Checks whether
obj
is a valid unannotated literal Venture object of the given type.Only checks the top level, not recursively. Types as in
val
.
-
venture.value.dicts.
is_val
(obj)¶ Checks whether
obj
is a valid unannotated Venture syntax object.Only checks the top level, not recursively.
-
venture.value.dicts.
list
(vs)¶ Construct a Venture list.
The
vs
argument must be a Python sequence of Venture objects (constructed with other functions from this module).Lists are combining forms when evaluated. The meaning of the list depends on the first element—if it is the name of a macro or special form, it will be evaluated accordingly. Otherwise, a list is an application.
A list quoted with
quote
will evaluate to a Venture list object.
-
venture.value.dicts.
matrix
(vs)¶ Construct a Venture matrix.
The
vs
argument must be a Python data structure suitable for conversion to a two-dimensional array withnumpy.asarray
.Venture matrices are self-evaluating.
-
venture.value.dicts.
num
(v)¶ Construct a Venture (floating-point) number.
Venture numbers are self-evaluating.
-
venture.value.dicts.
number
(v)¶ Construct a Venture (floating-point) number.
Venture numbers are self-evaluating.
-
venture.value.dicts.
probability
(v)¶ Construct a Venture probability value.
Currently, these are represented as (floating-point) numbers, but something like log-odds space may prove appropriate in the future.
Venture probabilities are self-evaluating.
-
venture.value.dicts.
quasiquote
(v)¶ Construct a Venture quasiquotation form.
The item
v
must be a Venture object, as constructed by functions in this module.This is equivalent to constructing an application of the
quasiquote
macro.
-
venture.value.dicts.
quote
(v)¶ Construct a Venture quotation form.
The item
v
must be a Venture object, as constructed by functions in this module.The result will evaluate to a literal representation of
v
, even ifv
would otherwise be treated as a combining form.This is equivalent to constructing an application of the
quote
special form.
-
venture.value.dicts.
real
(v)¶ Construct a Venture (floating-point) number.
Venture numbers are self-evaluating.
-
venture.value.dicts.
simplex
(vs)¶ Construct a Venture simplex.
The
vs
argument must be a Python sequence of numbers between 0 and 1.Unquoted simplexes are evaluated like arrays, which is usually not what is desired.
-
venture.value.dicts.
sp
(v, aux=None)¶ Construct a Venture stochastic procedure.
Foreign SPs are usually installed with
venture.ripl.ripl.Ripl.bind_foreign_sp()
andventure.ripl.ripl.Ripl.bind_foreign_inference_sp()
rather than direct insertion into source code.The
v
argument must be an instance ofventure.lite.sp.SP
. Theaux
argument, if supplied, becomes the procedure’s auxiliary state (seeventure.lite.sp.SP
).Venture SPs are self-evaluating.
-
venture.value.dicts.
string
(s)¶ Construct a Venture string.
Venture strings are self-evaluating.
-
venture.value.dicts.
sym
(s)¶ Construct a Venture symbol.
A symbol represents a variable name, which is looked up in the lexical environment when the symbol is evaluated.
-
venture.value.dicts.
symbol
(s)¶ Construct a Venture symbol.
A symbol represents a variable name, which is looked up in the lexical environment when the symbol is evaluated.
-
venture.value.dicts.
symmetric_matrix
(vs)¶ Construct a Venture symmetric matrix.
The
vs
argument must be a Python data structure suitable for conversion to a two-dimensional array withnumpy.asarray
.Venture symmetric matrices are self-evaluating.
-
venture.value.dicts.
unquote
(v)¶ Construct a Venture unquotation form.
The item
v
must be a Venture object, as constructed by functions in this module.This is equivalent to constructing an application of the
unquote
macro. It only has meaning inside aquasiquote
, but note that many modeling forms (assume
,observe
, etc) implicitly quasiquote their expression arguments.
-
venture.value.dicts.
val
(t, v)¶ Construct a Venture value of type
t
, with contentv
.The valid user-given types are
- “number”
- “integer”
- “atom”
- “boolean”
- “symbol”
- “string”
- “blob”
- “array”
- “vector”
- “simplex”
- “list”
- “dict”
- “improper_list” (v must be a 2-tuple of the proper part and the tail)
- “matrix”
- “symmetric_matrix”
- “sp” (
aux
cannot be supplied)
The effect is the same as calling that function from this module.
-
venture.value.dicts.
vector
(vs)¶ Construct a Venture vector.
The
vs
argument must be a Python sequence of numbers.Unquoted vectors are evaluated like arrays, which is usually not what is desired.