class Alda::InlineLisp
An inline lisp event. An Alda::EventContainer containing an Alda::InlineLisp can be derived using event list sugar (see Alda::EventList#method_missing) or by using Alda::EventList#l.
Sometimes you need help from Alda::LispIdentifier.
It serves as attributes in alda codes.
Alda::Score.new do tempo! 108 quant! 200 piano_ c e g violin_ g2 e4 end
Here, tempo! 108 and quant! 200 are inline lisp events and serves for alda attributes.
It can participate in the sequence sugar if it is at the end of the sequence.
Alda::Score.new do piano_ c d e quant 200 g o! c o? c2 end
You can operate a score by purely using inline lisp events. The following example only works in Alda 1 due to breaking changes in Alda 2 (alda-lang/alda#483, alda-lang/alda#484).
Alda::Score.new do part 'piano' key_sig [:d, :major] note pitch :d note pitch :e note pitch(:f), duration(note_length 2) end
When using event list sugar to create inline lisp events, note that it is not previously defined as a variable. See Alda::SetVariable and Alda::GetVariable.
Alda::Score.new do piano_ p barline.event.class # => Alda::InlineLisp barline__ c d e f p barline.event.class # => Alda::GetVariable end
Whether it is an Alda::SetVariable, Alda::InlineLisp, or Alda::GetVariable is intelligently determined.
Alda::Score.new do piano_ p((tempo 108).event.class) # => Alda::InlineLisp p tempo { c d }.event.class # => Alda::SetVariable p tempo.event.class # => Alda::GetVariable p((tempo 60).event.class) # => Alda::InlineLisp p to_s # => "piano: (tempo 108) tempo = [c d]\n tempo (tempo 60)" end
If you want, you can generate lisp codes using ruby.
Alda.generation = :v1 Alda::Score.new do println reduce _into_, {}, [{dog: 'food'}, {cat: 'chow'}] end.save 'temp.clj' `clojure temp.clj` # => "{:dog food, :cat chow}\n"
Attributes
The arguments passed to the lisp function.
Its elements can be any object that responds to to_alda_code and detach_from_parent.
The function name of the lisp function
Public Class Methods
Creates a new Alda::InlineLisp.
The underlines “_” in head will be converted to hyphens “-”.
# File lib/alda-rb/event.rb, line 431 def initialize head, *args super() @head = Alda::Utils.snake_to_slug head @args = args end
Public Instance Methods
Overrides Alda::Event#==. Returns true if other is an Alda::InlineLisp and has the same head and args as inline_lisp (using ==).
Alda::Event#==
# File lib/alda-rb/event.rb, line 460 def == other super || other.is_a?(Alda::InlineLisp) && @head == other.head && @args == other.args end
Alda::Event#on_contained
# File lib/alda-rb/event.rb, line 448 def on_contained super @args.detach_from_parent end
Overrides Alda::Event#to_alda_code.
# File lib/alda-rb/event.rb, line 442 def to_alda_code "(#{head} #{args.map(&:to_alda_code).join ' '})" end