Tuesday, May 5, 2020

Manuscript Essay Example For Students

Manuscript Essay Jonathan FinnManuScript is a simple, music-based programming language developed to write plug-ins for the Sibelius music processor. It is based on Simkin, an embedded scripting language developed by Simon Whiteside (www.larts.co Personal Narrative - Being Fully Human perso EssayA variable can contain an integer (whole number), a string (text) or an object (e.g. a note) ? more about objects in a moment. Unlike most languages, in ManuScript a variable can contain any type of data ? you don?t have to declare what type you want. Thus you can store a number in a variable, then store some text instead, then an object. Try this:x = 56;x = x+1;Sibelius.MessageBox(x);// prints ?57? in a dialog boxx = now this is text;// the number it held is lostSibelius.MessageBox(x);// prints ?now this is text? in a dialogx = Sibelius.ActiveScore;// now it contains a scoreSibelius.MessageBox(x);// prints nothing in a dialogConverting between numbers, text and objectsNotice that the method MessageBox is expecting to be sent some text to display. If you give it a number instead (as in the first call to MessageBox above) the number is conv erted to text. If you give it an object (such as a score), no text is produced. Similarly, if a calculation is expecting a number but is given some text, the text will be converted to a number:x = 1 + 1;// the + means numbers are expectedSibelius.MessageBox(x);// displays ?2?If the text doesn?t start with a number (or if the variable contains an object instead of text), it is treated as 0:x = 1 + fred;Sibelius.MessageBox(x);// displays ?1?The while loopManuScript has a while loop which is does the same duties as while, do and for loops in other languages. Create a new plug-in called Potato. This is going to amuse one and all by writing the words of the well-known song ?1 potato, 2 potato, 3 potato, 4?. Type in the following for the Run method of the new plug-in (if you?re lazy and you?re reading this as a Word document, you could just copy and paste the code):x = 1;while (x5)text = x potato,;Sibelius.MessageBox(text);x = x+1;}Run it. It should display ?1 potato?, ?2 potato?, ?3 potato?, ?4 potato?, which is a start, though annoyingly you have to click OK after each message. The while statement is followed by a condition in ( ) parentheses, then a block of statements in } braces (you don?t need a semicolon after the final } brace). While the condition is true, the block is executed. Unlike some other languages, the braces are compulsory (you can?t omit them if they only contain one statement). We did say that ManuScript was a simple language. In this example you can see that testing the value of x at the start of the loop, and increasing the value at the end, gives the same effect as for loops in other languages. You can use other simple techniques (such as if statements) to simulate the do loops and break/continue statements you thought you couldn?t do without. Notice the use of to add strings. Because a string is expected on either side, the value of x is turned into a string. Notice also that I?ve typed the Tab key to indent the statements inside the loop. This is a good habit to get into as it makes the structure clearer. If you have loops inside loops you should indent the inner loops even more. The if statementNow we can add an if statement so that the last phrase is just ?4?, not ?4 potato?:x = 1;while (x5)if(x=4)text = x .;}elsetext = x potato,;}Sibelius.MessageBox(text);x = x+1;}The rule for if takes the form if (condition) statements }. You can also optionally add else statements } which is executed if the condition is false. As with while, the parentheses and braces are compulsory, though you can make the program shorter by putting braces on the same line as other statements:x = 1;while (x5)if(x=4) text = x .;} else text = x potato,;}Sibelius.MessageBox(text);x = x+1;}The position of braces is entirely a matter of taste. Condition operatorsYou can put any expressions in parentheses after an if or while statement, but typically they will contain conditions such as = and . The available conditions are very simple:a = bequals (for numbers, text or objects)a bless than (for numbers)a bgreater than (for numbers)c and dboth are truec or deither are truenot cinverts a condition, e.g. not(x=4)Note that you use = to compare for equality, not the barbaric == found in C/C++ and Java. Instead of != or in other languages, use not(a=b). Instead of a = b, use not(a b). Or you could try (ab or a=b). Instead of a = b, use not(a b). Or you could try (ab or a=b). Now let?s make this plug-in really cool. We can build up the four messages in a variable called text, and only display it at the end, saving valuable wear on your mouse button. We can also switch round the if and else blocks to show off the use of not:x = 1;text = ;// start with no textwhile (x5)if (not(x=4)) text = text x potato, ;// add some text} else text = text x .;// add no. 4}x = x+1;}Sibelius.MessageBox(text);// finally display itArithmeticWe?ve been using + without comment, so here?s a complete list of the available arithmetic operators:a + badda ? bsubtracta * bmultiplya / bdividea % bremainder-anegateevaluate firstThe normal precedence for these operators applies; in other words, 2+3*4 is 14, not 20, because * is evaluated before +. To make this clearer you could write 2+(3*4). To get the answer 20, you?d have to write (2+3)*4.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.