Show Menu

SubScript Cheat Sheet by

programming     scala     subscript

Syntax

import subscript.language
import subscript.Predef._
Top-level imports required in all SubScript sources.
script a = expr
Script definition
script..
  a = expr
  b = expr
Shorthand script definition
runSc­rip­t(­scr­ipt­_na­me)
Run scripts like this
[ expr ]
Priori­tizing Parent­heses (like "­()" in "2 - (1 + 3)", just for scripts)
[** expr **]
Launch Anchor
[* expr *]
Launch
@a: b
Annotation
@{pri­ntl­n(t­here)}: a
Also annota­tion. There points to the annotated expression node
var x: Int = 3
Variable declar­ations are possible in scripts
let scala­_expr
Executes scal­a_e­xpr as a tiny code fragment.

Sequential Operators

a ; b
Executes next operator as soon as current one has success
a b
Same as above
a
b
Same as above

Parallel Operators

a && b
Non-­strict and-pa­ral­lel­ism. Succeeds iff all its operands do. On failure of one of the children terminates without success immedi­ately.
a & b
Strict and-pa­ral­lel­ism. Same as above, but if some of its children doesn't have success, it waits for the rest of the children to execute before termin­ating.
a || b
Non-­strict or-par­all­eli­sm. Succeeds iff at least one of its children does. After a children succeeds, it terminates immedi­ately with success.
a | b
Strict or-par­all­eli­sm. Same as above, but waits for the rest of the children after one succeeds. Has success immedi­ately after at least one child succeeds (termi­nation and success are not the same things).

Result Values

runScript(script_name).$
From Scala code, returns the result value of scri­pt_­name script, as Try[A­ny].
a^
From SubScript code, sets the result of the parent script to that of a. E.g. in script foo = a^ b c, script foo will have a result of a. b and c are still executed as usually.
a^^
The result of the parent script becomes a Seq[A­ny]. The result of a is recorded into that Seq at the index equal to a's current pass (that is, first pass in a loop will go to index 0, second - to 1 etc).
a^^i­nt_­lit­eral
The result of the parent script becomes a tuple. a's result is recorded at int_­lit­era­l-th position to the tuple. E.g. a^^1 b^^2 will result in a tuple with _1 set to a's result and _2 - to b's result.
^lit­eral
Sets the result of the parent script to lite­ral. E.g. ^5, ^"­Foo­", ^'x'.
^li­ter­al­^^
Sets the result to Seq[A­ny], records lite­ral under its pass's index.
^li­ter­al­^­^i­nt_­lit­eral
Sets the result to a tuple, places this lite­ral under int_­lit­era­l-th position in this tuple.
 

Scala Code Blocks

{! scala block !}
Normal code block. Activa­tion, Execution, Deacti­vation.
{: scala block :}
Tiny code block. Execution on Activa­tion.
{. scala block .}
Even­t-h­and­ling code block. Does not execute automa­tic­ally, need manual execution.
{* scala block *}
Thre­aded code block. Executes from a new thread (all the other blocks execute from Script Executor's thread).

Special Operands

[+]
Epsi­lon, or empty action. Has success immedi­ately after activa­tion.
[-]
Dela­ta, or deadlock. Terminates without success immedi­ately after activa­tion.
...
Loop. When used as an operand to a sequence, loops the sequence. E.g. a b ... executes in order "a b a b a b" etc as an infinite loop. a ... b and ... a b have same effect.
break
Break. Breaks activation of its parent operator.
break?
Optional break. Behaves like break, but resumes activation after an action happened in an operand activated before itself.
..?
Optional break loop. Mixes together break? and ... .

Altern­ative Operators

a + b
Choi­ce. Starts with a and b activated. When either starts executing, excludes another.
a / b
Disr­upt­ion. Executes a until b starts, then excludes (termi­nates) a and continues with b. If a gets terminated without b ever getting started, excludes b.

Condit­ional Operators

if scala_expr then expr else expr
Executes then part if scala­_expr is true, otherwise - else part.
do expr then expr else expr
Executes do part first. If it has success, executes then part, otherwise - else part.

Dataflow

a ~~(x: T)~~> b
Data­flow. Executes a, casts its result to type T, assigns it to x and executes b with x in scope.
a ~~(x: T)~~> b
+~/~(x: E)~~> c
Dataflow with an extra clause to handle except­ions. If a succeeds, the behaviour is as in the case above. Otherwise, an exception with which a failed is casted to E (which must be <: Throwa­ble) and handled by c. Like catch in try-c­atch.
a ~~(x: T)~~> b
+~~(y: A)~~> c
+~~(z: B)~~> d
Dataflow can arbitrary number of result­-ha­ndling clauses and except­ion­-ha­ndling clauses.
a ~~(x: T)~~^ scala_expr
+~~(x: A)~~^ scala_expr
Dataflow map. Similar to Dataflow, but runs the result of a through a given scal­a_e­xpr and sets the result of it as the result of the parent script.
a ~~^ f
Shorthand for a ~~(x: T)~~^ f(x).

Download the SubScript Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/anatoliykmetyuk_subscript.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readable.io is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Regular Expressions Cheat Sheet
          PHP Cheat Sheet