Scheme

class schemetools.Scheme(*args, **kwargs)

Abjad model of Scheme code.

Example 1. A Scheme boolean value:

>>> scheme = schemetools.Scheme(True)
>>> print(format(scheme))
##t

Example 2. A nested Scheme expession:

>>> scheme = schemetools.Scheme(
...     ('left', (1, 2, False)),
...     ('right', (1, 2, 3.3))
...     )
>>> print(format(scheme))
#((left (1 2 #f)) (right (1 2 3.3)))

Example 3. A variable-length argument:

>>> scheme_1 = schemetools.Scheme(1, 2, 3)
>>> scheme_2 = schemetools.Scheme((1, 2, 3))
>>> format(scheme_1) == format(scheme_2)
True

Scheme wraps nested variable-length arguments in a tuple.

Example 4. A quoted Scheme expression:

>>> scheme = schemetools.Scheme((1, 2, 3), quoting="'#")
>>> print(format(scheme))
#'#(1 2 3)

Use the quoting keyword to prepend Scheme’s various quote, unquote, unquote-splicing characters to formatted output.

Example 5. A Scheme expression with forced quotes:

>>> scheme = schemetools.Scheme('nospaces', force_quotes=True)
>>> print(format(scheme))
#"nospaces"

Use this in certain override situations when LilyPond’s Scheme interpreter treats unquoted strings as symbols instead of strings. The string must contain no whitespace for this to work.

Example 6. A Scheme expression of LilyPond functions:

>>> function_1 = 'tuplet-number::append-note-wrapper'
>>> function_2 = 'tuplet-number::calc-denominator-text'
>>> string = schemetools.Scheme('4', force_quotes=True)
>>> scheme = schemetools.Scheme(
...     function_1,
...     function_2,
...     string,
...     )
>>> scheme
Scheme('tuplet-number::append-note-wrapper', 'tuplet-number::calc-denominator-text', Scheme('4', force_quotes=True))
>>> print(format(scheme))
#(tuplet-number::append-note-wrapper tuplet-number::calc-denominator-text "4")

Example 7. A Scheme lambda expression of LilyPond function that takes a markup with a quoted string argument. Setting verbatim to true causes the expression to format exactly as-is without modifying quotes or whitespace:

>>> string = '(lambda (grob) (grob-interpret-markup grob'
>>> string += r' #{ \markup \musicglyph #"noteheads.s0harmonic" #}))'
>>> scheme = schemetools.Scheme(string, verbatim=True)
>>> scheme
Scheme('(lambda (grob) (grob-interpret-markup grob #{ \\markup \\musicglyph #"noteheads.s0harmonic" #}))')
>>> print(format(scheme))
#(lambda (grob) (grob-interpret-markup grob #{ \markup \musicglyph #"noteheads.s0harmonic" #}))

Scheme objects are immutable.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" [color=1, group=0, label=AbjadValueObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.AbjadValueObject.AbjadValueObject"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_schemetools { graph [label=schemetools]; "abjad.tools.schemetools.Scheme.Scheme" [color=black, fontcolor=white, group=2, label=<<B>Scheme</B>>, shape=box, style="filled, rounded"]; "abjad.tools.schemetools.SchemeAssociativeList.SchemeAssociativeList" [color=3, group=2, label=SchemeAssociativeList, shape=box]; "abjad.tools.schemetools.SchemeColor.SchemeColor" [color=3, group=2, label=SchemeColor, shape=box]; "abjad.tools.schemetools.SchemeMoment.SchemeMoment" [color=3, group=2, label=SchemeMoment, shape=box]; "abjad.tools.schemetools.SchemePair.SchemePair" [color=3, group=2, label=SchemePair, shape=box]; "abjad.tools.schemetools.SchemeSymbol.SchemeSymbol" [color=3, group=2, label=SchemeSymbol, shape=box]; "abjad.tools.schemetools.SchemeVector.SchemeVector" [color=3, group=2, label=SchemeVector, shape=box]; "abjad.tools.schemetools.SchemeVectorConstant.SchemeVectorConstant" [color=3, group=2, label=SchemeVectorConstant, shape=box]; "abjad.tools.schemetools.Scheme.Scheme" -> "abjad.tools.schemetools.SchemeAssociativeList.SchemeAssociativeList"; "abjad.tools.schemetools.Scheme.Scheme" -> "abjad.tools.schemetools.SchemeColor.SchemeColor"; "abjad.tools.schemetools.Scheme.Scheme" -> "abjad.tools.schemetools.SchemeMoment.SchemeMoment"; "abjad.tools.schemetools.Scheme.Scheme" -> "abjad.tools.schemetools.SchemePair.SchemePair"; "abjad.tools.schemetools.Scheme.Scheme" -> "abjad.tools.schemetools.SchemeSymbol.SchemeSymbol"; "abjad.tools.schemetools.Scheme.Scheme" -> "abjad.tools.schemetools.SchemeVector.SchemeVector"; "abjad.tools.schemetools.Scheme.Scheme" -> "abjad.tools.schemetools.SchemeVectorConstant.SchemeVectorConstant"; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadValueObject.AbjadValueObject" -> "abjad.tools.schemetools.Scheme.Scheme"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

force_quotes Is true when quotes should be forced in output.
format_embedded_scheme_value(value[, ...]) Formats value as an embedded Scheme value.
format_scheme_value(value[, force_quotes, ...]) Formats value as Scheme would.
quoting Gets Scheme quoting string.
verbatim Is true when formatting should format value absolutely verbatim.
__copy__(\*args) Copies Abjad value object.
__eq__(expr) Is true when all initialization values of Abjad value object equal the initialization values of expr.
__format__([format_specification]) Formats scheme.
__hash__() Hashes Abjad value object.
__ne__(expr) Is true when Abjad object does not equal expr.
__repr__() Gets interpreter representation of Abjad object.
__str__() String representation of scheme object.

Read-only properties

Scheme.force_quotes

Is true when quotes should be forced in output. Otherwise false.

Returns true or false.

Scheme.quoting

Gets Scheme quoting string.

Returns string.

Scheme.verbatim

Is true when formatting should format value absolutely verbatim. Whitespace, quotes, and all other parts of value are left intact.

Defaults to false.

Set to true or false.

Returns true or false.

Class & static methods

static Scheme.format_embedded_scheme_value(value, force_quotes=False)

Formats value as an embedded Scheme value.

static Scheme.format_scheme_value(value, force_quotes=False, verbatim=False)

Formats value as Scheme would.

Example 1. Some basic values:

>>> schemetools.Scheme.format_scheme_value(1)
'1'
>>> schemetools.Scheme.format_scheme_value('foo')
'foo'
>>> schemetools.Scheme.format_scheme_value('bar baz')
'"bar baz"'
>>> schemetools.Scheme.format_scheme_value([1.5, True, False])
'(1.5 #t #f)'

Example 2. Strings without whitespace can be forcibly quoted via the force_quotes keyword:

>>> schemetools.Scheme.format_scheme_value(
...     'foo',
...     force_quotes=True,
...     )
'"foo"'

Example 3. Set verbatim to true to format value exactly (with only hash preprended):

>>> string = '(lambda (grob) (grob-interpret-markup grob'
>>> string += r' #{ \markup \musicglyph #"noteheads.s0harmonic" #}))'
>>> schemetools.Scheme.format_scheme_value(string, verbatim=True)
'(lambda (grob) (grob-interpret-markup grob #{ \\markup \\musicglyph #"noteheads.s0harmonic" #}))'

Example 4. Hash symbols in strings will result in quoted output unless verbatim is True, in order to prevent LilyPond parsing errors:

>>> string = '#1-finger'
>>> schemetools.Scheme.format_scheme_value(string)
'"#1-finger"'
>>> schemetools.Scheme.format_scheme_value(string, verbatim=True)
'#1-finger'

Returns string.

Special methods

(AbjadValueObject).__copy__(*args)

Copies Abjad value object.

Returns new Abjad value object.

(AbjadValueObject).__eq__(expr)

Is true when all initialization values of Abjad value object equal the initialization values of expr.

Returns true or false.

Scheme.__format__(format_specification='')

Formats scheme.

Set format_specification to ‘’‘, ‘lilypond’ or 'storage'. Interprets ‘’ equal to ‘lilypond’.

Example 1. Scheme LilyPond format:

>>> scheme = schemetools.Scheme('foo')
>>> format(scheme)
'#foo'

Example 2. Scheme storage format:

>>> print(format(scheme, 'storage'))
schemetools.Scheme(
    'foo'
    )

Returns string.

(AbjadValueObject).__hash__()

Hashes Abjad value object.

Returns integer.

(AbjadObject).__ne__(expr)

Is true when Abjad object does not equal expr. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.

Scheme.__str__()

String representation of scheme object.

Returns string.