Arguments and Return Types

From Compost Wiki
(Redirected from Compost4 Language Changes)
Jump to navigation Jump to search

Overview

This article covers the language extensions that have been added as part of Compost 4.

Arguments

Prog subs can now accept arguments and use them within it's own scope. These arguments behave in a similar manner to variables and flags but they can be set from existing number and boolean commands. Bot

Syntax

Defintion

 ProgSub[Num: SomeArgumentName, Bool: SomeOtherArgument]:
   IF GetArgument? ('SomeOtherArgument')
     Add# GetArgument# ('SomeArgumentName') EPX#
   END
 RETURN

Call

 ProgSub(EPY#, ToolChangeAtHome?)

Types

Both number and boolean arguments are supported using the Num and Bool identifiers.

Using Arguments

The commands boolean and number versions of GetArgument are used to access the arguments inside in the sub. The names of each argument most be unique with regards to the other arguments in the same ProgSub, but can be any string desired.

Return Values

Prog subs can now return values and be used in place of normal number and boolean commands.

Syntax

Defintion

 BoolFunction?[Num: Arg1, Num: Arg2]:
   ReturnBool GreaterThan? GetArgument# ('Arg1') GetArgument# ('Arg2')
 RETURN
 NumberFunction#[Num: Arg3, Bool: double]:
   IF GetArgument?('double')
      ReturnNum MUL# GetArgument# ('Arg3') Num#('2')
   ELSE
     ReturnNum GetArgument# ('Arg3')
   END
 RETURN

Calls

 IF BoolFunction?(EPX#, EPY#)
   'It returned true' EOL
 END
 SetVar# ('SomeVariable') NumberFunction#(EPX#, ToolChangeAtHome?)

Return Type

Using a ? or # in the name tells the compiler what type of value the prog sub returns. To set the return value a post must call the commands ReturnNum or ReturnBool with the desired value. These commands will accept the next math or boolean stack, resolve it and use it as the return value. If the post does not set the return value then a value of 0/FALSE will be used.

Infix Math

Local Variables and Flags