SpencerPark / MellowD

Programmable music! A compiler and high level language.
https://spencerpark.github.io/mellowd-site/editor.html
12 stars 3 forks source link

Function call syntax #22

Open SpencerPark opened 7 years ago

SpencerPark commented 7 years ago

The function call syntax is very nice to read

{ arg1, arg2 } => funcName
save { arg1, arg2 } => funcName

but is not realistic for using return values in expressions.

Return default

Similar to javascript's export construct, MellowD could specify a default return value that is stored in the root of the saved object.

def function func => {
    return.val -> [a, b, c]
    return.default -> [a, b, c]
}

that is called like this

Block {
    save { } => func
    func*<e> //which is equivalent to
    func.val*<e>
}

It could also just support assigning a value to return since blocks of memory and values are actually stored separately. For example the above would be return -> [a, b, c] instead of return.default -> [a, b, c].

Possible call improvements

<1, 3 => func> //return.defualt casted to an rhythm
(1, 3 => func) //cast to chord
[1, 3 => func] //melody

What do we do for numbers, beats, notes? A generic

{1, 3 => func}
SpencerPark commented 5 years ago

With namespace changes in 3.0, return can be a value and a namespace. This implementation makes return -> value a great candidate for return values. Auxiliary values could potentially be put into a return namespace which (with the save keyword) would be included in the calling scope?

Also implemented is the explicit casting for calls inside melodies/chords/rhythms.