From 3dc602a32e499c052bff366b93bd53effdf2ec38 Mon Sep 17 00:00:00 2001 From: Jason Self Date: Sun, 2 Jun 2019 08:41:06 -0700 Subject: [PATCH] Add Routines --- informqr/informqr.md | 59 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/informqr/informqr.md b/informqr/informqr.md index eea256b..e12df8e 100644 --- a/informqr/informqr.md +++ b/informqr/informqr.md @@ -302,4 +302,61 @@ A common statement is the assignment: There are two forms of multiple assignment: variable = variable = ... = expr ; - variable = expr, variable = expr, ... ; \ No newline at end of file + variable = expr, variable = expr, ... ; + +Routines +-------- + +A routine can have up to 15 local variables: word values which are +private to the routine and which by default are set to zero on each +call. Recursion is permitted. + +A **standalone** routine: + +- has a name, by which it is called using `routine();` can also be + called indirectly using + + indirect(routine,a1,a2, ... a7) + +- can take arguments, using `routine(a1,a2, ... a7)`, whose values + initialise the equivalent local variables + +- returns true at the final "]" + + [ routine + local_var local_var ... local_var ; + statement; + statement; + ... + statement; + ] + +A routine **embedded** as the value of an object property: + +- has no name, and is called when the property is invoked; can also + be called explicitly using object.property() + +- accepts arguments only when called explicitly + +- returns false at the final "]" + + property [ + local_var local_var ... local_var; + statement; + statement; + ... + statement; + ] + +Routines return a single value, when execution reaches the final "\]" +or an explicit return statement: + + return expr; + return; + rtrue; + rfalse; + +To define a dummy standalone routine with N local variables (unless it +already exists): + + Stub routine N; \ No newline at end of file -- 2.31.1