Specify the (not so) new piano-based musical model

Registered by João Paulo Pizani Flor

During the Utrecht Summer School 2011, Justin has suggested a new - and very interesting, BTW :] - musical model for Presto! programs. Presto! scores would be something like piano scores, with left and right hands. Right-hand musical content would be "normal" stack elements, like numbers and functions. The left hand would have more of a "control" role. With the help of left-hand musical contents (such as chords or progressions) we would be able to indicate the END of a parameter entry, to change the "mode of input" and so on, allowing for more flexibility and beauty in the compositions...

The implementation of this model might change radically the current ideas about an execution backend for Presto - we currently have a stack machine as backend. Even so, I believe that we must always think top-down here, and do things as flexible and beautiful as possible, leaving implementation details for later. The message is: try to keep things simple and beautiful, but because you want, not because some backend forces you to.

Our next step is now to specify this model, and I think Justin and me could start... :) We need to define what would be the allowed functions, how we can input arguments to functions, what the left hand will do, etc.

Blueprint information

Status:
Not started
Approver:
João Paulo Pizani Flor
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
Justin Paston-Cooper
Definition:
Drafting
Series goal:
None
Implementation:
Unknown
Milestone target:
milestone icon hello-world

Related branches

Sprints

Whiteboard

As a first step, I think we should start specifying which fundamental operations will be possible to perform using Presto. I intended Presto to be a fully-fledged (Turing-complete) programming language, but we don't need to get there immediately. What we definitely need NOW, however, is some basic arithmetic and input/output.

So these are some of the instructions that I think should be on Presto's "instruction set". I've put haskell-ish type signatures on them to help understanding. The underlying model is a stack machine, so arguments are taken from the stack and the result of all operations is also pushed onto the stack.

FUNDAMENTAL OPERATIONS
=========================

Arithmetic:

1) ADD :: Int -> Int -> Int
2) SUB :: Int -> Int -> Int
3) MUL :: Int -> Int -> Int (wrap-around semantics, if the operands are too big the result just wraps around)
4) DIV :: Int -> Int -> Int (Integer division)
5) MOD :: Int -> Int -> Int (remainder of integer division)

String <-> Number conversions:

6) TONUM :: Int -> [Char] -> Maybe Int
This one deserves an explanation. This is basically Java's String.valueOf() or C's atoi(). But we can't just take an arbitrarily-long string (we could, but I think it's too complicated), so the first parameter is the string's length. This function interprets the chars and returns Just a number on success and Nothing on failure.

7) FROMNUM :: Int -> [Char]
This does the exact inverse as 6, taken a number it returns a list of stack items (a list of chars) representing this number. This is useful, for instance, for printing a number to the screen.

Basic Input/Output

8) PRINTLN :: Int -> [Char] -> IO ()
Prints a string to the screen. The need for the first (int) parameter was already explained is 6.

9) READLN :: IO [Char]
Reads a newline-terminated string from the user. The actual string pushed onto the stack has no newline character.

That's it for now guys. I ran out of ideas, so please contribute! :) I'm specially unsure about IO and if we need any other operations, or if we can take any out. What do you think?

GENERALITIES
=============

A Presto! score will be a piano composition, and will consist of two simultaneous staffs (played at the same time), one for the left hand and one for the right hand.

Presto! has ONLY ONE datatype, called "Atom". Atoms are machine-word sized and have two basic "interpretations". They can be seen as an integer number or as a character.

The execution backend of Presto! will be a stack machine, and the defined fundamental operations of Presto! take parameters from the stack and push its results also onto the stack.

MODES OF OPERATION AND THE ROLE OF LEFT AND RIGHT HANDS
=========================================================

Presto! will have some "modes" of operation and data input. Changing between modes, as well as defining the "borders" between consecutive elements being input, is the role of the musical content in the left hand.

The musical content of the right hand, both melodic and harmonic (chords), will serve as input of data and operations.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.