In article <87brt5wz83.fsfethereal.dyndns.org>,
Nolan J. Darilek <nolan_dbigfoot.com> wrote:>I've begun working on a music-related ruby project, and recently I've
>been pondering the idea of a music composition environment somewhat
>similar to cm, clm and friends for lisp, but in ruby instead.
>Today I was thinking about how ruby blocks make constructing
>domain-specific languages a snap. I've been reading Lisp as a Second
>Language at [url]http://www.ircam.fr/equipes/repmus/LispSecondLanguage/[/url], a
>Lisp tutorial for musicians, and was considering using a list-based
>structure for storing music. I sorta envisioned the language as
>looking something like:
> measure("4/4") do
> c d e f g a b c
> chord do
> c e g
>In this example, a-g are methods returning note objects.
>What I'd like is to have that return a list like so:
>["c", "d", "e", "f", "g", "a", "b", "c", ["c", "e", "g"]]
I played with this problem for a few minutes and this is what I came up
list << "a"
list << "b"
list << "c"
list << "d"
list << "e"
list << "f"
list << "g"
puts "...In Clef..."
puts "...In Measure..."
puts "...In Chord..."
notes << chord_notes
notes = 
class MySong < Song
c; d; e; f; g; a; b; c;
chord do |chrd|
c(chrd); d(chrd); g(chrd);
mysong = MySong.new
Of course, the ugly bit is the part in the chord block: you have to
pass in 'chrd' to all of the a-g methods to get those notes to be added to
the correct list (chord_list) which then gets appended to the notes
list. So it's still not quite what you want (I understand that you want
people to see very little of the 'wizard behind the curtain' [Ruby] and
having to pass 'chrd' sort of negates that). Hopefully, someone else
will offer a suggestion for getting rid of that requirement.
....you may not like the Song class bit I added either...