JGrok/QL syntax guideunder constructionThe essentialsStatements and expressions. A QL program consists of a sequence of statements and/or expressions. Statements are executed for their side effects, typically changing the value of a variable, printing something to the screen, etc. Expressions typically produce no side effects; instead, they are evaluated and the results of evaluation are printed to standard output (which is typically the screen, unless the output has been redirected). It is acceptable, although not always necessary, to place semicolons at the end of every statement and expression. In most cases, QL can determine where one statement ends and a different one begins. In cases where there is ambiguity, semicolons are required. For example: foo = {1,2,3} X {4} + {4} X {5,6}; bar = {"hello"} X {"world"}; foo+ barThis piece of code defines two relations and then appears to print the transitive closure of foo, followed by bar. This is not the case, however. Because the expressions on the last two lines are not separated, they will be treated as one expression, and this code will instead print the union of foo and bar. To print transitive closure of foo first and bar second, a semicolon must be placed at the end of the third line. For clarity reasons, and to avoid potential confusion, it is recommended that you place semicolons at the end of every expression or statement. Compound statements. A sequence of statements and expressions can be treated as a single compound statement when surrounded by curly braces. Variables and types. There is no need to declare variables in QL. A variable is automatically created when it is first assigned to. All variables have a type, which is automatically determined based on the value assigned to a variable; the type of a variable may change throughout its life, based on the values assigned to it. Parameters. QL scripts can take command-line parameters. The parameters can be accessed through the variables $0, $1, $2, and so on. $0 holds the name of the QL script being executed, $1 holds the first parameter, $2 holds the second parameter, and so on. Flow control statementsIf statement. The if statement in QL has the general form of:
For statement. The for loop in QL looks as follows: |