-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation
Lakshay edited this page Nov 11, 2023
·
6 revisions
Expressions are the fundamental units in sock. They are of two types;
- Sym (Symbol):
xypi - Fun (Functions):
pair(a, b)swap(pair(a, b))
Rule describes the transformation of left expression to right expression
<rule_name:[a-z0-9A-Z]> := <left_expr:Expr> = <right_expr:Expr>
swapPair := swap(pair(a, b)) = pair(b, a)
limit := lim(x, a, f(x)) = f(a)
Shapes are the most important operations in sock. It transforms the expressions following the transformations mentioned in the provided rule(s). Modifiers can also be added which describes "how to transform?" or "which rule to use?" and so on.
<expr_name:[a-z0-9A-Z]> := <expr:Expr> {
<rule_name:[a-z0-9A-Z] | <expr_mod:Expr_Mod>;
...
} <mod:Mod>
expr := swap(pair(a, b)) {
swapPair | over;
} dump
_ := swap(pair(f(x), lim(h, y, f(h)))) {
limit | all ;
? | over;
} dump
-
_is a specialexpr_name. If you name your shape _, it will not store resulting expression. Meant for use-and-throw expressions which you don't want to preserve. -
?is a specialrule_name. If you name your rule ?, sock will apply every rule to the expression if it matches the pattern to that rule. It can only be used with theallexpression modifier.
-
all: It will apply the rule recursively to the expression and every subexpression if they matches the pattern. -
over: It will apply the rule to the expression if it matches the pattern.
-
void: Similar to Python's pass it does nothing but required to complete the syntax. -
dump: Dump the expression to stdout. -
$dump: Dump the value of expression to stdout.
Useful for making a shorthand for a big piece of code.
@<macro_name:[a-z0-9A-Z]> := <anything>
@add := {add | all; add0 | all;}
On of the use case for this is _ := add(@1, @2) @add $dump
@add Expands to {add | all; add0 | all;} at runtime.
# this is a comment
rule := a = a # this is an inline comment