Skip to content

Commit 8f2d327

Browse files
committed
update
1 parent a50ef4a commit 8f2d327

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,53 @@ The *switch()* function in RoyalScript facilitates pattern matching, its similar
785785

786786
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.
787787

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.
827+
828+
```
829+
>> =(add, @@(a, b, +(a, b)))
830+
undefined
831+
>> add(1, 2)
832+
3
833+
>> add(1, add(1, 3))
834+
5
788835
```
789836

790-
```
837+
Double parameter procs can also be nested.

0 commit comments

Comments
 (0)