Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ Functions can be applied:
}
```

Infix notation can be used to apply binary functions (those which look like
`b => a => …`). For example, the expression `x f y` desugars to `:f(y)(x)`.
Here's another example:

```
{
cons: b => a => { :a, :b }
list: 1 cons (2 cons 3) // evaluates to `{ 1, { 2, 3 } }`
}
```

The standard library contains symbolically-named functions for arithmetic and
other familiar binary operations. For example, `1 + 2 - 3` is `0`. Also included
in the standard library are the functions`|>` (pipe) and `>>` (flow):

```
{
// `>>` composes functions
append_bc: :atom.append(b) >> :atom.append(c)
// `|>` pipes an argument into a function
abc: a |> :append_bc
}
```

All binary operations are currently left-associative and there is no operator
precedence. Use of parentheses is encouraged.

#### Keywords

The functions and lookups shown above are syntax sugar for _keyword
Expand Down Expand Up @@ -197,7 +225,7 @@ possible. For example, this program compiles to the literal value `2` (no
computation will occur at runtime):

```
:integer.add(1)(1)
1 + 1
```

There's currently no module system and all Please programs are single files, but
Expand Down
33 changes: 16 additions & 17 deletions examples/fibonacci.plz
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
{
fibonacci: n => {
@if, :integer.less_than(2)(:n)
@if
condition: :n < 2
then: :n
else: :integer.add(
:fibonacci(:integer.subtract(2)(:n))
)(
:fibonacci(:integer.subtract(1)(:n))
)
else: :fibonacci(:n - 1) + :fibonacci(:n - 2)
}

input: { @runtime, context => :context.arguments.lookup(input) }
input: {
@runtime
context => :context.arguments.lookup(input)
}

output: :apply(:input)(
:match({
none: _ => "missing input argument"
some: input => {
@if, :natural_number.is(:input)
then: :fibonacci(:input)
else: "input must be a natural number"
}
})
)
output: :input match {
none: _ => "missing input argument"
some: input => {
@if
condition: :natural_number.is(:input)
then: :fibonacci(:input)
else: "input must be a natural number"
}
}
}.output
2 changes: 1 addition & 1 deletion examples/kitchen-sink.plz
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
bar: :foo
sky_is_blue: :boolean.not(false)
colors: { red, green, blue }
two: :integer.add(1)(1)
two: 1 + 1
add_one: :integer.add(1)
three: :add_one(:two)
function: x => { value: :x }
Expand Down
28 changes: 13 additions & 15 deletions examples/lookup-environment-variable.plz
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{@runtime, context =>
:flow(
:match({
/**
* Given CLI arguments like `--variable=FOO`, looks up the environment
* variable named `FOO`.
*/
{
@runtime
context =>
:context.arguments.lookup(variable) match {
none: {}
some: :flow(
:match({
none: {}
some: :identity
})
)(
:context.environment.lookup
)
})
)(
:context.arguments.lookup
)(variable)
some: :context.environment.lookup >> :match({
none: {}
some: :identity
})
}
}
Loading