Expression

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=1]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/utilities/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; "abjad.system.AbjadValueObject.AbjadValueObject" [URL="../api/abjad/utilities/../system/AbjadValueObject.html#abjad.system.AbjadValueObject.AbjadValueObject", label="Abjad\nValue\nObject", target=_top]; "abjad.system.AbjadObject.AbjadObject" -> "abjad.system.AbjadValueObject.AbjadValueObject"; } subgraph "cluster_abjad.utilities" { graph [label="abjad.utilities"]; node [color=2]; "abjad.utilities.Expression.Expression" [URL="../api/abjad/utilities/Expression.html#abjad.utilities.Expression.Expression", color=black, fontcolor=white, label=Expression, target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } "abjad.system.AbjadValueObject.AbjadValueObject" -> "abjad.utilities.Expression.Expression"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; }

class abjad.utilities.Expression.Expression(argument_count=None, argument_values=None, callbacks=None, evaluation_template=None, force_return=None, has_parentheses=None, is_composite=None, is_initializer=None, is_postfix=None, keywords=None, lone=None, map_operand=None, markup_maker_callback=None, module_names=None, name=None, next_name=None, precedence=None, proxy_class=None, qualified_method_name=None, string_template=None, subclass_hook=None, subexpressions=None, template=None)

Expression.

Makes identity expression:

>>> expression = abjad.Expression()
>>> expression() is None
True
>>> expression(99)
99
>>> expression([99, 99.25])
[99, 99.25]

Makes integer initialization expression:

>>> expression = abjad.Expression(evaluation_template='int({})')
>>> expression()
0
>>> expression(99)
99
>>> expression(99.25)
99

Makes binary integer initialization expression:

>>> expression = abjad.Expression(evaluation_template='int({}, base=2)')
>>> expression('1')
1
>>> expression('11')
3
>>> expression('111')
7

Makes three-integer addition expression:

>>> expression = abjad.Expression(
...     argument_count=3,
...     evaluation_template='{} + {} + {}',
...     )
>>> expression(1, 2, 3)
6

Attributes Summary

__add__ Gets proxy method or adds expressions.
__call__ Calls expression on arguments with keywords.
__eq__ Is true when expression storage format equals argument storage format.
__format__ Formats expression.
__getattr__ Gets attribute name.
__getitem__ Gets proxy method.
__hash__ Hashes expression.
__iadd__ Gets proxy method.
__radd__ Gets proxy method.
__repr__ Gets interpreter representation.
__setitem__ Gets proxy method.
__str__ Gets string representation of expression.
append_callback Appends callback to expression.
argument_count Gets argument count.
argument_values Gets argument values.
callbacks Gets callbacks.
color Colors argument.
establish_equivalence Makes new expression with name.
evaluation_template Gets evaluation template.
force_return Is true when expression should return primary input argument.
get_markup Gets markup directly.
get_string Gets string.
has_parentheses Is true when expression has parentheses.
is_composite Is true when expression is composite.
is_initializer Is true when expression is initializer.
is_postfix Is true when expression is postfix.
is_selector Is true when expression is selector.
keywords Gets keywords.
label Makes label expression.
lone Is true when expression return a singular get-item.
make_callback Makes callback.
map_operand Gets expression to map.
markup_maker_callback Gets markup-maker callback.
module_names Gets module names.
name Gets name.
next_name Gets next name.
pitch_class_segment Makes pitch-class segment expression.
pitch_set Makes pitch set expression.
precedence Gets precedence.
print Prints argument.
proxy_class Gets proxy class.
qualified_method_name Gets qualified method name of expression.
select Makes select expression.
sequence Makes sequence expression.
string_template Gets string template.
subclass_hook Gets subclass hook.
subexpressions Gets subexpressions.
template Gets template.
wrap_in_list Makes expression to wrap argument in list.

Special methods

__add__(i)

Gets proxy method or adds expressions.

Adds expressions:

>>> expression_1 = abjad.Expression(
...     argument_count=3,
...     evaluation_template='{} + {} + {}',
...     )
>>> expression_2 = abjad.Expression(
...     argument_count=2,
...     evaluation_template='{} + {}',
...     )
>>> expression = expression_1 + expression_2
>>> abjad.f(expression)
abjad.Expression(
    argument_count=2,
    evaluation_template='{}.__add__({})',
    is_composite=True,
    markup_maker_callback='_make_add_expression_markup',
    qualified_method_name='abjad.Expression.__add__',
    string_template='{} + {}',
    subexpressions=(
        abjad.Expression(
            argument_count=3,
            evaluation_template='{} + {} + {}',
            ),
        abjad.Expression(
            argument_count=2,
            evaluation_template='{} + {}',
            ),
        ),
    )
>>> expression(1, 2, 3, 4, 5)
15
__call__(*arguments, **keywords)

Calls expression on arguments with keywords.

Calls identity expression:

>>> expression = abjad.Expression()
>>> expression() is None
True

Returns ouput of last callback.

(AbjadValueObject).__copy__(*arguments)

Copies Abjad value object.

Returns new Abjad value object.

__eq__(argument)

Is true when expression storage format equals argument storage format.

>>> expression_1 = abjad.Expression().sequence()
>>> expression_2 = abjad.Expression().sequence()
>>> expression_1 == expression_2
True
>>> expression_1 = abjad.Expression().sequence()
>>> expression_2 = abjad.new(expression_1)
>>> expression_1 == expression_2
True
>>> expression_1 = abjad.Expression().sequence()
>>> expression_2 = abjad.Expression().sequence().reverse()
>>> expression_1 == expression_2
False
>>> expression_1 = abjad.Expression().sequence()
>>> expression_1 == 'text'
False

Returns true or false.

__format__(format_specification='')

Formats expression.

Formats identity expression:

>>> expression = abjad.Expression()
>>> abjad.f(expression)
abjad.Expression()

Returns string.

__getattr__(name)

Gets attribute name.

Returns proxy method when proxy class is set.

Returns normally when proxy class is not set.

__getitem__(argument)

Gets proxy method.

__hash__()

Hashes expression.

Returns integer.

__iadd__(i)

Gets proxy method.

__radd__(i)

Gets proxy method.

__repr__()

Gets interpreter representation.

Gets interpreter representation of identity expression:

>>> expression = abjad.Expression()
>>> expression
Expression()

Returns string.

__setitem__(i, argument)

Gets proxy method.

__str__()

Gets string representation of expression.

Gets string representation of identity expression:

>>> expression = abjad.Expression()
>>> str(expression)
'Expression()'

Returns string.


Methods

append_callback(callback)

Appends callback to expression.

>>> expression = abjad.Expression()
>>> expression.callbacks is None
True
>>> callback = abjad.Expression(evaluation_template='int({})')
>>> expression = expression.append_callback(callback)
>>> for callback in expression.callbacks:
...     callback
... 
Expression(evaluation_template='int({})')
>>> callback = abjad.Expression(evaluation_template='{}**2')
>>> expression = expression.append_callback(callback)
>>> for expression in expression.callbacks:
...     expression
... 
Expression(evaluation_template='int({})')
Expression(evaluation_template='{}**2')

Returns new expression.

color(argument, colors=None)

Colors argument.

Returns none.

establish_equivalence(name)

Makes new expression with name.

>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.rotate(n=1)
>>> expression = expression.rotate(n=2)
>>> expression = expression.establish_equivalence(name='Q')
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([7, 10.5, 7, 10, 10.5, 6])
>>> expression.get_string()
'Q = r2(r1(J))'
>>> markup = expression.get_markup()
>>> abjad.show(markup) 

Returns new expression.

get_markup(direction=None, name=None)

Gets markup directly.

Avoids markup expressions.

Returns markup or none.

get_string(name=None)

Gets string.

Gets string for sequence expression:

Without name:

>>> expression = abjad.sequence()
>>> expression = expression.reverse()
>>> expression = expression.rotate(n=2)
>>> expression([1, 2, 3, 4, 5, 6])
Sequence([2, 1, 6, 5, 4, 3])
>>> abjad.Expression.get_string(expression, name='J')
'r2(R(J))'

With name:

>>> expression = abjad.Expression(name='J')
>>> expression = expression.sequence()
>>> expression = expression.reverse()
>>> expression = expression.rotate(n=2)
>>> expression([1, 2, 3, 4, 5, 6])
Sequence([2, 1, 6, 5, 4, 3])
>>> abjad.Expression.get_string(expression)
'r2(R(J))'

Overrides name:

>>> abjad.Expression.get_string(expression, name='K')
'r2(R(K))'

Gets string for segment expression:

Without name:

>>> expression = abjad.Expression()
>>> expression = expression.pitch_class_segment()
>>> expression = expression.invert()
>>> expression = expression.rotate(n=2)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([1.5, 5, 2, 1.5, 6, 5])
>>> abjad.Expression.get_string(expression, name='J')
'r2(I(J))'

With name:

>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.invert()
>>> expression = expression.rotate(n=2)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([1.5, 5, 2, 1.5, 6, 5])
>>> abjad.Expression.get_string(expression)
'r2(I(J))'

Overrides name:

>>> abjad.Expression.get_string(expression, name='K')
'r2(I(K))'

Returns string or none.

label(**keywords)

Makes label expression.

Makes expression to label logical tie durations:

>>> staff = abjad.Staff(r"c'4. d'8 ~ d'4. e'16 [ ef'16 ]")
>>> expression = abjad.Expression()
>>> expression = expression.label()
>>> expression = expression.with_durations()
>>> expression(staff)
>>> abjad.show(staff) 

Returns expression.

pitch_class_segment(**keywords)

Makes pitch-class segment expression.

Makes expression to transpose pitch-class segment:

>>> items = [-2, -1.5, 6, 7, -1.5, 7]
>>> J = abjad.PitchClassSegment(items=items)
>>> J
PitchClassSegment([10, 10.5, 6, 7, 10.5, 7])
>>> abjad.show(J) 
>>> expression = abjad.Expression(name='J')
>>> expression = expression.pitch_class_segment()
>>> expression = expression.transpose(n=13)
>>> expression([-2, -1.5, 6, 7, -1.5, 7])
PitchClassSegment([11, 11.5, 7, 8, 11.5, 8])
>>> segment = expression([-2, -1.5, 6, 7, -1.5, 7])
>>> markup = expression.get_markup()
>>> abjad.show(segment, figure_name=markup) 

Returns expression.

pitch_set(**keywords)

Makes pitch set expression.

Returns expression.

print(argument)

Prints argument.

Returns none.

select(**keywords)

Makes select expression.

Makes expression to select leaves:

>>> staff = abjad.Staff()
>>> staff.append(abjad.Measure((2, 8), "<c' bf'>8 <g' a'>8"))
>>> staff.append(abjad.Measure((2, 8), "af'8 r8"))
>>> staff.append(abjad.Measure((2, 8), "r8 gf'8"))
>>> abjad.show(staff) 
>>> expression = abjad.Expression()
>>> expression = expression.select()
>>> expression = expression.leaves()
>>> for leaf in expression(staff):
...     leaf
... 
Chord("<c' bf'>8")
Chord("<g' a'>8")
Note("af'8")
Rest('r8')
Rest('r8')
Note("gf'8")

Returns expression.

sequence(**keywords)

Makes sequence expression.

Makes expression to initialize, flatten and reverse sequence:

>>> expression = abjad.sequence()
>>> expression = expression.reverse()
>>> expression = expression.flatten(depth=-1)
>>> expression([1, 2, 3, [4, 5, [6]]])
Sequence([4, 5, 6, 3, 2, 1])

Returns expression.

wrap_in_list()

Makes expression to wrap argument in list.

>>> expression = abjad.Expression()
>>> expression = expression.wrap_in_list()
>>> expression(abjad.Markup('Allegro assai'))
[Markup(contents=['Allegro assai'])]
>>> abjad.f(expression)
abjad.Expression(
    callbacks=[
        abjad.Expression(
            evaluation_template='[{}]',
            ),
        ],
    )

Returns expression.


Class & static methods

static make_callback(argument_count=None, evaluation_template=None, force_return=None, has_parentheses=None, is_composite=None, is_initializer=None, is_postfix=None, keywords=None, map_operand=None, module_names=None, next_name=None, precedence=None, qualified_method_name=None, string_template=None)

Makes callback.

Returns expression.


Read-only properties

argument_count

Gets argument count.

Defaults to none.

Set to nonnegative integer or none.

Returns nonnegative integer or none.

argument_values

Gets argument values.

Defaults to none.

Set to dictionary or none.

Returns dictionary or none.

callbacks

Gets callbacks.

Defaults to none:

>>> expression = abjad.Expression()
>>> expression.callbacks is None
True

Set to callbacks or none.

evaluation_template

Gets evaluation template.

Defaults to none.

Set to string.

Returns string.

force_return

Is true when expression should return primary input argument.

Defaults to none.

Set to true, false or none.

Returns true, false or none.

has_parentheses

Is true when expression has parentheses.

Defaults to none.

Set to true, false or none.

Returns true, false or none.

is_composite

Is true when expression is composite.

Defaults to none.

Set to true, false or none.

Returns true, false or none.

is_initializer

Is true when expression is initializer.

Defaults to none.

Set to true, false or none.

Returns true, false or none.

is_postfix

Is true when expression is postfix.

Defaults to none.

Set to true, false or none.

Returns true, false or none.

is_selector

Is true when expression is selector.

>>> expression = abjad.select().leaf(0)
>>> expression.is_selector
True
>>> expression = abjad.sequence().rotate(n=-1)
>>> expression.is_selector
False
keywords

Gets keywords.

Defaults to none.

Set to dictionary or none.

Returns dictionary or none.

lone

Is true when expression return a singular get-item.

Defaults to none.

Set to true, false or none.

Returns true, false or none.

map_operand

Gets expression to map.

Defaults to none.

Set to expression or none.

Returns expression or none.

markup_maker_callback

Gets markup-maker callback.

Defaults to none.

Set to string or none.

Returns string or none.

module_names

Gets module names.

Defaults to none.

Set to strings or none.

Returns strings or none.

name

Gets name.

Preserves name after initializer callback:

>>> expression = abjad.Expression(name='J')
>>> expression.name
'J'
>>> expression = expression.sequence()
>>> expression.name
'J'

Defaults to none.

Set to string or none.

Returns string or none.

next_name

Gets next name.

Defaults to none.

Set to string or none.

Returns string or none.

precedence

Gets precedence.

Defaults to none.

Set to integer or none.

Returns integer or none.

proxy_class

Gets proxy class.

Defaults to none.

Set to class or none.

Returns class or none.

qualified_method_name

Gets qualified method name of expression.

Returns string or none.

string_template

Gets string template.

Defaults to none.

Set to string or none.

Returns string or none.

subclass_hook

Gets subclass hook.

Only to be set by expression subclasses.

Set to name of custom evaluation method.

Defaults to none.

Set to string or none.

Returns string or none.

subexpressions

Gets subexpressions.

Defaults to none.

Set to expressions or none.

Returns list of expressions or none.

template

Gets template.

Returns string or none.