You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-1Lines changed: 48 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -785,6 +785,53 @@ The *switch()* function in RoyalScript facilitates pattern matching, its similar
785
785
786
786
The switch statements do not fall through between each case pair, meaning the first case that matches will executes, terminating the progression to further cases. There is also no default block for RoyalScript switch statements.
787
787
788
+
```
789
+
>> =(e, `foobar`)
790
+
undefined
791
+
>> switch(e,
792
+
.. 0, `good`,
793
+
.. `bar`, 5,
794
+
.. `foobar`, list(1, 2, 3),
795
+
.. 1, `r`
796
+
.. )
797
+
[1,2,3]
798
+
799
+
```
800
+
801
+
##Procs(1 or 2 argument functions)
802
+
803
+
RoyalScript has both general, full length functions that can be defined, but it also has smaller, anonymously created functions called Procs. They are similar to lambdas in other languages.
804
+
805
+
###@(parameter, call\_exp)
806
+
807
+
The *@()* function creates and evaluates to an unnamed, one argument function with only a single execution statement. These are very useful for loops and quick, small areas you need to update values and compute values.
808
+
809
+
```
810
+
>> =(e, @(first, +(first, 3)))
811
+
undefined
812
+
>> e(3)
813
+
6
814
+
>> e(8)
815
+
11
816
+
>> =(e, @(first, +(first, 3), -(first, 3)))
817
+
Argument Error: Got improper arguments but expected 2.
818
+
```
819
+
820
+
Procs made with *@()* always return their statement, so you do not need to specify a *return()* function.
821
+
822
+
Because there first statement is returned, you cannot extend them with *do()*.
823
+
824
+
###@@(param1, param2, call\_exp)
825
+
826
+
The *@@()* works identically to the *@()* except that it evaluates to a proc the has two parameters and returns its only execution statement.
0 commit comments