-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# i Expressions | ||
|
||
i expressions allow you to evaluate cat expression inside cat expression. This gives us the power to do recursion. | ||
|
||
The fibonacci function can be defined as: | ||
|
||
```meow | ||
fib(x) { | ||
if( | ||
eq(x, zero()), | ||
zero(), | ||
!(if( | ||
leq(x, num("2")), | ||
spack(num("1")), | ||
`add fib pred x fib pred pred x` | ||
)) | ||
) | ||
} | ||
``` | ||
|
||
The `!` operator is used to evaluate the expression inside. | ||
|
||
You can try it in repl: | ||
|
||
``` | ||
> ! `"23"` | ||
23 | ||
> ! `cat "12" "22"` | ||
1222 | ||
``` | ||
|
||
Note that `cat "12" "22"` itself is a string literal rather than many tokens. |