Piccola / Forms / Basic Index

Basic

Standard Bindings

The Basic form provides the following standard bindings:

returnsservicedescription
StringasString(aForm) Returns a string representation of aForm. This representation is determined in the following way:
  1. by calling aForm.myAsString(), if the binding myAsString exists in aForm.
  2. by calling Host.meta(aForm).asString()
BooleanfalseThe boolean value false.
Formif(aBoolean)(cases)If aBoolean is true, then cases.then() is called and it's result is returned. If aBoolean is false, cases.else() is called and it's result is returned.
BooleanisEmpty(aForm)Returns true if aForm is empty, otherwise returns false.
BooleanisService(aForm)Returns true if aForm is a closure, otherwise returns false.
Empty / Labellabel(aForm)Returns a first class label representing a label of aForm, if aForm is not empty. If aForm is empty, the empty form is returned.
Formload(anURL)(aForm)Loads a Piccola script from anURL and executes it in the context specified by aForm. Returns the value of the script.
FormloadCore(aString)(aForm)
FormloadRelative(aString)(aForm)
BlackboardnewBlackboard()Returns a new blackboard.
LabelnewLabel(aString)Returns a new first class label representing the label specified with aString.
VariablenewVar(aForm)Returns a new variable having aForm as it's current value.
Emptyprint(aForm)Prints asString(aForm) to a console.
Emptyprintln(aForm)Prints asString(aForm) followed by a newline to a console.
MetaFormprotect(aForm)Returns a meta-form representing aForm.
BooleantrueThe boolean value true.

JPiccola

In JPiccola, the Basic form additionally provides the following bindings:

FormexecNative(cases)(aForm)Calls cases.java(aForm) and returns the resulting value.
Formloop(args)As long as args.while() evaluates to true, args.do() is called.

Examples

abs aNumber: if (aNumber > 0)
    then: aNumber
    else: -aNumber

abs 2               # returns 2
abs -2              # returns 2

sum = newVar 0
i = newVar 1
loop
    while: *i <= 10
    do: sum <- *sum + *i, i <- *i + 1

*sum                # returns 55 (sum of 1 to 10)