ubolonton / emacs-module-rs

Rust binding and tools for Emacs's dynamic modules
336 stars 22 forks source link

Better way to call Lisp functions #15

Closed ubolonton closed 5 years ago

ubolonton commented 5 years ago

Currently Lisp functions are called using Env::call. This has 2 drawbacks:

These can be solved by a macro. A basic version already exists as an internal macro: call_lisp!.

sebastiencs commented 5 years ago

How about an Env::call like that:

fn call(&self, name: &str, args: &[impl IntoLisp]) -> Result<Value<'_>>

Maybe with a trait similar to IntoLisp that doesn't take the ownership of the values ?

ubolonton commented 5 years ago

That would only work when all arguments have the same type.

// Would work.
env.call("list", &[1, 2])

// Wouldn't work.
env.call("list", &[1, "2"])

Besides, it wouldn't solve the heap allocation issue, since slices are dynamic sized.

ubolonton commented 5 years ago

Maybe we could use tuples instead of slices.

env.call("list", (1, "2"))

That would probably be a new trait with implementations for tuples, arrays and slices.

call(&self, name: &str, args: impl IntoLispArgs) -> Result<Value>