alda-lang / alda

A music programming language for musicians. :notes:
https://alda.io
Eclipse Public License 2.0
5.58k stars 282 forks source link

`pitch` behavior changed from Alda 1 to Alda 2 #483

Closed UlyssesZh closed 1 year ago

UlyssesZh commented 1 year ago

In Alda 1, we have to use (pitch :a :sharp), but in Alda 2, we have to use (pitch '(a sharp)). There seems to be no form of writing it that is compatible in both versions. Personally, I prefer the Alda 1 way because it has less parentheses.

daveyarwood commented 1 year ago

The context here is that Alda 1 was implemented in Clojure, and any Lisp expressions were literally evaluated as Clojure code. Clojure (as well as other Lisps) includes keywords like :a and :sharp, and it's more idiomatic to use keywords than symbols (e.g. 'a and 'sharp) so that's why it was the way it was in Alda 1.

Alda 2 was a rewrite in Go, so we lost the Clojure part and I had to implement a new Lisp. I chose to make it as deliberately simple as possible, using only the most basic Lisp primitives, like strings, and symbols. It's not uncommon to see something like '(a sharp) in Lisp languages, so although it looks weird and has more parentheses, I see it as the Lisp Way.

Clojure is not the only Lisp that has keywords. Common Lisp and Emacs Lisp also have them. In light of that, I'm not opposed to adding support for keywords to alda-lisp, and I don't think it would be difficult to do so.

However: supporting both ways -- (pitch :a :sharp) and (pitch '(a sharp)) would add complexity to the language, so I wouldn't want to do it just for the sake of doing it. I'm imagining having to document both ways of doing things, both for pitch and for key-signature, and Alda users needing to understand two different syntaxes for the same feature.

To make matters worse: even if we added keywords, we still couldn't support the Alda 1 way of expressing key signatures because we don't have maps, e.g. {:f [:sharp] :c [:sharp] :g [:sharp]}. I think it would be doubly confusing if we supported doing it the Alda 1 way for pitch, but NOT for key-signature. My perspective on this is that it's better to draw a line in the sand and say that the Lisp in Alda 2 is not Clojure, it's a new, way simpler Lisp.

Happy to hear other thoughts on this, of course. Is there a strong use case to be able to write a score that works in both Alda 1 and 2? (I hope the answer is no! My dream is to never need to support Alda 1 again :smile: )

UlyssesZh commented 1 year ago

What about implementing (pitch 'a 'sharp) as well as (pitch '(a sharp))? Pros: avoids extra parentheses, avoids uncommon Lisp expression like '(a sharp), and avoids having to implement keywords.

key-signature seems to be more complicated because it must accept a list/map whose length is not determined. I think we need to discuss more on that.

I am not familiar with Lisp and its variants. What does it actually mean by writing a "quoted list"? Is it different from a vector (maybe nested) of symbols?

There are some advantages of implementing vectors and maps. Using square brackets to denote vectors has an advantage of consistency when we have nested vectors (because we have '(f (sharp)) instead of '(f '(sharp)), which looks inconsistent). Also, not using maps to define a key signature can lead some input to become valid but strange (or ambiguous), like (key-sig '(f (sharp) f (flat))).

Is there a strong use case to be able to write a score that works in both Alda 1 and 2?

I am thinking of multiple people using different versions of Alda that may exchange the scores they wrote. It would be annoying (and maybe affecting the originality of music art if we consider the Alda codes to be the artwork itself) if I have to modify the work that others made to make it playable on my own machine. This is still definitely not a strong use case, though.

UlyssesZh commented 1 year ago

By the way, I realize that this is not a bug because it is intended. Could you please move this issue to "discussions" if that is necessary? Sorry for that.

daveyarwood commented 1 year ago

No problem! I was just thinking the same thing. Will move this to discussions.