Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Native functions and a standard library #65

Merged
merged 23 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"parse",
"value",
"eval",
"stdlib",
"rimu",
"repl",
"cli",
Expand Down Expand Up @@ -40,6 +41,10 @@ path = "parse"
version = "0.1.0"
path = "value"

[workspace.dependencies.rimu-stdlib]
version = "0.1.0"
path = "stdlib"

[workspace.dependencies.rimu-eval]
version = "0.1.0"
path = "eval"
Expand Down
6 changes: 4 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{

use clap::Parser;
use clio::*;
use rimu::{evaluate, parse, Environment, ErrorReport, SourceId, Value};
use rimu::{evaluate, parse, Environment, ErrorReport, SerdeValue, SourceId, Value};

#[derive(Debug, Clone, Copy)]
enum Format {
Expand Down Expand Up @@ -57,7 +57,7 @@ fn main() -> std::result::Result<ExitCode, Box<dyn Error>> {
let env = if let Some(mut env_arg) = args.env {
let mut env_string = String::new();
env_arg.read_to_string(&mut env_string)?;
let env_value: Value = env_string.into();
let env_value: SerdeValue = env_string.into();
Environment::from_value(&env_value, None)?
} else {
Environment::new()
Expand Down Expand Up @@ -89,6 +89,8 @@ fn main() -> std::result::Result<ExitCode, Box<dyn Error>> {
return Ok(ExitCode::FAILURE);
}
};
let value: Value = value.into_inner();
let value: SerdeValue = value.into();

let output: String = match args.format {
Format::Yaml => serde_yaml::to_string(&value)?,
Expand Down
13 changes: 13 additions & 0 deletions docs/pages/lang/blocks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ TODO

## Operations

### Function call

```rimu
length
- ["a", "b", "c"]
```

A block function call receives a block as input.

If the input block is a list, is assumed to be a list of arguments.

Otherwise, the input block is assumed to be the first and only argument.

### `if`

```rimu
Expand Down
25 changes: 24 additions & 1 deletion docs/pages/lang/stdlib.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# Standard Library

TODO
## length

```rimu
let
list: ["a", "b", "c"]
in
length(list)
```

## map

```rimu
map
list: range({ start: 5, end: 10 })
each: (item) => item * item
```

## range

```rimu
range
start: 0
end: 10
```
5 changes: 4 additions & 1 deletion docs/pages/roadmap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

- Operations

- [x] Call Function: [pull#58](https://github.com/ahdinosaur/rimu/pull/58)
- [x] `let`: [pull#8](https://github.com/ahdinosaur/rimu/pull/8)
- [x] `if`: [pull#7](https://github.com/ahdinosaur/rimu/pull/7)
- [ ] `switch`: [issue#47](https://github.com/ahdinosaur/rimu/issues/47)
Expand All @@ -78,7 +79,9 @@

- Standard Library

- [ ] `map`: [issue#49](https://github.com/ahdinosaur/rimu/issues/49)
- [x] `length`: [pull#65](https://github.com/ahdinosaur/rimu/pull/65)
- [x] `range`: [pull#65](https://github.com/ahdinosaur/rimu/pull/65)
- [x] `map`: [issue#49](https://github.com/ahdinosaur/rimu/issues/49) -> [pull#65](https://github.com/ahdinosaur/rimu/pull/65)
- [ ] `mapValues`: [issue#50](https://github.com/ahdinosaur/rimu/issues/50)
- [ ] `filter`: [issue#51](https://github.com/ahdinosaur/rimu/issues/51)
- [ ] `flatten`
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/tutorial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ If we wanted to [make a star](https://www.turtleacademy.com/programs/40499):
- forward: 50

- map
list: range(5)
each:
list: range({ end: 5 })
each: () =>
- right: 144
- forward: 50
- left: 72
Expand Down Expand Up @@ -89,8 +89,8 @@ Now to describe our star:
forward: 50

- map
list: range(5)
each:
list: range({ end: 5 })
each: () =>
- action: "rotate"
right: 144
- action: "move"
Expand Down
Loading