Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Native function definitions #13

Open
foxfriends opened this issue Nov 15, 2020 · 0 comments
Open

Native function definitions #13

foxfriends opened this issue Nov 15, 2020 · 0 comments
Projects

Comments

@foxfriends
Copy link
Owner

foxfriends commented Nov 15, 2020

Native functions are kind of a pain to implement. It would be good to create a proper proc macro for this, and implement type checking and value conversion automatically. It would be really cool if this also somehow made nondeterminism and arbitrary outputs easy:

#[lumber]
fn add(a: Int, b: Int, c: Int) {
  c = a + b;
}

No idea how this will work nicely, as Rust and Lumber are fundamentally very different languages. The above example will not work. Maybe something using structs and impl blocks will be necessary (though very verbose, and I'm making up some generator syntax).

#[lumber("add/3")]
struct Add(Int, Int, Int);

impl Add {
  #[lumber(add(A!, B!, C)]
  fn add_c(a: Int, b: Int, c: Option<Int>) -> () 
  yields () -> Self {
    match c {
      Some(c) if (a + b == c) => yield Add(a, b, c),
      Some(..) => {},
      None => yield Add(a, b, a + b),
    }
  }

  #[lumber(add(A!, B, C!)]
  fn add_b(a: Int, b: Option<Int>, c: Int) -> () 
  yields () -> Self {
    match b {
      Some(b) if (a + b == c) => yield Add(a, b, c),
      Some(..) => {},
      None => yield Add(a, c - a, c),
    }
  }

  #[lumber(add(A, B!, C!)]
  fn add_b(a: Option<Int>, b: Int, c: Int) -> () 
  yields () -> Self {
    match a {
      Some(a) if (a + b == c) => yield Add(a, b, c),
      Some(..) => {},
      None => yield Add(c - b, b, c),
    }
  }
}
@foxfriends foxfriends added this to RFC in Features via automation Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant