stopachka / risp

Playing with Rust. Let's create a Lisp!
MIT License
64 stars 8 forks source link

any thoughts on how to interface to more complex values? #4

Open nicferrier opened 2 years ago

nicferrier commented 2 years ago

I love that you did this and I think it's a pretty useful... I added String handling to it for a laugh.

Then I got to thinking... could I add more complex functionality? Say, an http request mechanism.

So I added an httpget implementation to the base environment, using Reqwest.

But that set me wondering further... my implementation of httpget is very blocking. But could the httpget return a function which would provide async access to the response?

(def r (httpget "https://google.com"))
(r "headers")

would produce the headers as a list or something, and:

(r "json")

would attempt to download the body (and cache it) and convert to json... etc...

This returning closures from Risp functions would be cool but I started to fall over my Rust knowledge... I know how to do this in C but I can't see how to return a function from here that would close a non-cloneable value like a reqwest response.

This is going to be the case with a lot of systems programming like things... file descriptors etc... are all non-clonable.

If you don't mind me asking, how would you do this?

stopachka commented 2 years ago

Hey @nicferrier, I thought I had responded, but realized just today I didn't. Apologies!

To be honest, I am not sure. I haven't done a project in Rust since Risp. If you end up writing a solution, would be curious to see it!