brundonsmith / rust_lisp

A Rust-embeddable Lisp, with support for interop with native Rust functions
234 stars 20 forks source link

Add support for native closure #25

Closed Qix- closed 1 year ago

Qix- commented 1 year ago

This adds support for NativeClosure functions that accept closures instead of 'naked' functions.

brundonsmith commented 1 year ago

I think this one is worth doing - it's unfortunate that env functions right now can't eg. mutate state in their Rust closure - but it gets pretty complicated/subtle with the lifetimes and traits involved, and I want to make extra sure it's done in the best way, so I'm going to give it a deeper look/research and comment here again after that

brundonsmith commented 1 year ago

I've implemented an alternate version of this which allows FnMut closures, enabling state mutation from within closures without the use of unsafe { }: https://github.com/brundonsmith/rust_lisp/commit/af8ba5ff05ad6f4476f384e23cc443eef9fc883e