Re: [Strasheela-devel] can't understand tutorial lesson: $ marks a return value
Status: Beta
Brought to you by:
t-anders
From: Torsten A. <tor...@gm...> - 2008-01-03 17:19:29
|
Dear Graham, On Dec 27, 2007, at 1:11 AM, Graham Percival wrote: > Procedures and Functions -> $ marks a return value > > Sorry, I can't figure out what this example is showing -- what > does it mean that "every procedure argument be a return value" ? > If this is covered in the Roy book, could I get a pointer to the > section? Check the index for `$ (nesting marker)', e.g., p. 83 (printed book), =20= and p. 85 (in pdf draft). I just copied this section here into the mail. * Nesting markers The nesting marker =93$=94 turns any statement into an expression. The =20= expression=92s value is what is at the position indicated by the nesting marker. For =20= example, the statement {P X1 X2 X3} can be written as {P X1 $ X3}, which is an =20 expression whose value is X2. This makes the source code more concise, since it =20 avoids having to declare and use the identifier X2. The variable corresponding to =20 X2 is hidden from the source code. Nesting markers can make source code more readable to a proficient =20 program- mer, while making it harder for a beginner to see how the code =20 translates to the kernel language. We will use them only when they greatly increase =20 readability. For example, instead of writing: local X in {Obj get(X)} {Browse X} end we will instead write {Browse {Obj get($)}}. Once you get used to =20 nesting markers, they are both concise and clear. Note that the syntax of =20 procedure values as explained in Section 2.3.3 is consistent with the nesting =20 marker syntax. > > In other words, why does this example use > X =3D {Max $ 3 Result} > instead of > {Max X 3 Result} These two lines are equivalent. This is just a toy-example, we should =20= find something more convincing. Primarily, I introduce the nesting marker in the tutorial, because I =20 use it all the time to return values from methods like {MyNote getPitch($)} However, once the reader understands what $ actually does, then also =20 the definition of anonymous procedures, functions, classes etc. make =20 sense, e.g. fun {$ X} X*X end Best Torsten > ? > > Cheers, > - Graham > > > /* Every procedure argument can be a return value. The $ (dollar > * sign) > always marks a return value. This example is not yet very > convincing, > but procedures will encapsulate constraints in later examples... > TODO: what's happening here? -gp > TODO: I think this belongs somewhere in Basics-2, or even in the > CSP stuff. > */ > > local > proc {Max X Y Z} > if X >=3D Y then Z =3D X else Z =3D Y end > end > X =3D 4 > Result > in > %% Note the $ > X =3D {Max $ 3 Result} > {Browse Result} > end > > > > ----------------------------------------------------------------------=20= > --- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Strasheela-devel mailing list > Str...@li... > https://lists.sourceforge.net/lists/listinfo/strasheela-devel -- Torsten Anders Interdisciplinary Centre for Computer Music Research University of Plymouth Office: +44-1752-233667 Private: +44-1752-558917 http://strasheela.sourceforge.net http://www.torsten-anders.de |