GOO    SHORTHANDS

The added shorthands are simple conveniences (syntactic sugar) whose main purpose is to avoid having to enter long identifiers multiple times. Goo does simple transformations of the source lines to accomplish this. The translations never add or subtract lines, so Euphoria errors report line numbers that are correct for the .GOO file.

There are several categories of shorthands:







Inline Initializations (IIN)

The '$=' operator allows initializations without repeating the id. Multiple comma separated items are allowed. In addition, an alternate syntax is provided. If the type is postfixed with a '$' then the '=' operator can be used for initialization. NOTE: if initializations are used for local variables, the end of the locals must be marked for the translator with '$$'.

Example:

integer  x $= 3

=>

integer x   x=3 A simple initialization.
integer  x $= 3,  y $= 2

=>

integer x, y   x=3 y = 2 Multiple inits are allowed on a line.
sequence  s $= "test",

=>

sequence s   s="test" Multiple lines ok if ended with comma.
                t $= "another"

=>

sequence t   t="another"  
integer$  x=3, y = 4

=>

integer x, y   x=3 y = 4 Alternate syntax for initialiers.
procedure xx ()

=>

procedure xx () The start of a procedure
    integer$ z = 2

=>

    integer z Local initializer
    $$

=>

     z=2 User must mark end of locals for translator.



Define function or procedure (DEF)

The new keyword 'def' and its matching 'end def' may be used to define either a function or procedure. The choice is made based on the presence of a return statement which is followed by further (non-comment) text

Example:

def foo()

=>

function foo() A simple function.
      return 3

=>

     return 3  
end def

=>

end function  



Sequence Slicing (SSH)

The end of a slice may be implied.

Example:

seq[1..]

=>

seq[1..length(seq)] Missing end index replaced with length.
str[3..-2]

=>

str[3..length(str)-2] Can also be 'back indexed'.


Block Comments (COM)

Block comments are implemented with the '--{' and '--}' pair. All lines between the pair are prefixed with '--'

Example:

--{ this is the start of a

=>

--{ this is the start of a  
    block comment that ends

=>

--    block comment that ends  
--} AFTER this line

=>

--}AFTER this line  


Pseudo-Reference Parameter (PRM)

A reference parameter is simulated. Only one may be used on a line. The translator simply extracts the identifier and places 'identifier = ' at the start of the line.

Example:

append (a, $b)

=>

b = append (a, b) 'b' is specified as both a parameter and the return value.
$array[3..]

=>

array = array[3..length(array)] Another useful idiom.
3 + foo ($a)

=>

a = 3 + foo(a) Some odd things are possible.


Trinary Expression (TRN)

A line-oriented and somewhat fragile implementation of the C-style trinary expression.

Example:

a=0? foo()

=>

if a=0 then foo() end if  
a=0? foo() exit

=>

if a=0 then foo() exit end if Multiple statements ok if on 1 line
a=3? foo(): zot()

=>

if a=3 then foo() else zot() end if  
a=3 ?a foo()

=>

a=3 ?a foo() ERROR -- No space after '?' is Euphoria debug operator!
a = 1? foo()::

=>

if a= 1 then foo() The double colon indicates an elsif clause on next line.
a = 2? zot() : err()

=>

elsif a=2 then zot() else err() end if  .. which must also have a '?' operator


Post-Increment/Decrement (PID)

C-style post-increment and post-decrement operators

Example:

x = y$+

=>

x = y   y += 1 Increment instruction placed at end of line.
x&+ = y$+

=>

x = y   x += 1 y+=1 Multiples are stacked at end of line.