Add functions and lists
This commit is contained in:
36
README.md
36
README.md
@@ -19,7 +19,7 @@ Pipple's interpreter provides a REPL for fast prototyping. Try it out by running
|
||||
|
||||
```
|
||||
$ ./build/pipple
|
||||
pipple>
|
||||
pipple>
|
||||
```
|
||||
|
||||
Pipple code you write will be run now. Try something like `(print "Hello, World!")`. See what happens!
|
||||
@@ -65,6 +65,8 @@ Remember: Polish notation is the key!
|
||||
|
||||
### Conditionals
|
||||
|
||||
In Pipple, `nil` is the only non-truthy value. Every non-`nil` value is truthy.
|
||||
|
||||
```
|
||||
(let x 0)
|
||||
(if (== x 0)
|
||||
@@ -85,4 +87,34 @@ Remember: Polish notation is the key!
|
||||
```
|
||||
(let x (input))
|
||||
(print "You said" x)
|
||||
```
|
||||
```
|
||||
|
||||
### Lists
|
||||
|
||||
```
|
||||
(list item1 item2 item3)
|
||||
(list "hi there" 32 nil)
|
||||
```
|
||||
|
||||
### Functions
|
||||
|
||||
Pipple functions require type annotations. They are also first class.
|
||||
|
||||
Functions are defined with the following syntax:
|
||||
|
||||
`(function returntype [argtype argname argtype argname] (code) (morecode))`
|
||||
|
||||
```
|
||||
(let x (function int [int x]
|
||||
(return (* x 5))
|
||||
))
|
||||
|
||||
(print (x 3))
|
||||
```
|
||||
|
||||
Valid types in Pipple are:
|
||||
|
||||
* int
|
||||
* double
|
||||
* string
|
||||
* list
|
||||
|
||||
Reference in New Issue
Block a user