Skip to content

Commit

Permalink
HOF docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vic1707 committed Nov 28, 2023
1 parent 312ff4c commit 7019050
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,23 @@ fn main() {

## Higher order functions

TODO: Coming soon
You can define functions in a context based on a previously parsed expression.

```rust
use xprs::{xprs_fn, Context, Parser, Xprs};

fn main() {
let xprs_hof = Xprs::try_from("2x + y").unwrap();
let fn_hof = xprs_hof.bind2("x", "y").unwrap();
let hof = xprs_fn!("hof", dyn fn_hof, 2);
let ctx = Context::default().with_fn(hof);
let parser = Parser::new_with_ctx(ctx);

let xprs = parser.parse("hof(2, 3)").unwrap();

println!("hof(2, 3) = {}", xprs.eval_no_vars().unwrap());
}
```

These examples and others can be found in the [examples](./examples) directory.

Expand Down

0 comments on commit 7019050

Please sign in to comment.