I want to create a physics playground with Lisp/Scheme interactive scripting

I intend to build a physics playground - a small 2D particle physics engine - for education purposes. It should:

  • provide a robust scripting DSL to tinker with playground on-the-fly, for that Scheme immediately comes into my mind, and GNU Guile looks impressive for me.

  • available on the web as it's the easiest graphics display I can think of, but I don't want Javascript, so I consider WebAssembly and think I can use Rust to target it.

  • favor physical correctness over performance.

  • roll out in a reasonable timeframe. While I'm eager to explore Rust, this project does have a deadline. I've read much about Rust but never have a chance to actually use it. Can I learn and develop at the same time to finish a prototype in 3 months?

Does Rust binding for Guile exist and usable? Any Howtos or explanations I can refer to? Or are there other Lisp/Scheme that works.

Rust target WASM seems to be a hot topic. Is it actually easy? What if I bring along Guile integration?

How about drawing graphics on web - HTML5 canvas should be enough? Any guides?

Finally, is Rust really suitable for my usage? Other suggestions?

Sincerely thanks in advance.

1 Like

I'm no slouch in the learning department, but I can honestly say it took me over 6 months of daily programming to be comfortable enough with Rust to write anything of value in it. If you have a serious 3 month deadline, I would highly recommend that you do it in a language you already know and are comfortable with.

With that said, nothing here sounds impossible, assuming you have a sane C interface to your interpreter. I would wonder if these libraries are entirely accessible from within a browser, but that's more a statement of my ignorance of compiling to web targets. (I've tried it before, but some of my deps needed to build using a C compiler, so I couldn't compile them for WASM.) Aside from that, I just used cargo-web and it seemed pretty easy to use.

3 Likes

There are several frameworks out there for writing browser frontends purely in Rust (seed, yew, etc.).The web-sys crate also gives you access to all the browser APIs.

If you want something that users can run in the browser, you can't use any native libraries (e.g. guile) because native libraries are compiled for x86 and can't be used in a browser. That said, writing a lisp interpreter is a popular toy project, so I'm sure there are libraries on crates.io which are fully implemented in Rust that you'd be able to use.

Yes! As a language it's a serious candidate for tackling exactly these sorts of problems.

What you're trying to build sounds like a pretty decently sized application. I'm not trying to dissuade you at all, in fact I think it's an awesome idea and you should definitely do it, I just don't want to give you unreal expectations.

I'd estimate 5-15k lines of code as a ballpark figure, depending on how much you are able to use existing libraries. If you have a day job or are studying you'd probably only be able to commit 10 hours/week, that's approximately 120 hours of work over 3 months. I know that I (professional software engineer, been writing Rust for about 4 years) will write about 3-5k lines in a 40 hour work week when it's a topic I'm confident with (e.g. I've done lots of work with file formats and wrapping unsafe code) and am able to work for long periods of time without being disturbed. If you aren't able to sit down and work for several hours at a time (e.g. you're doing a couple hours after work or need to look after kids) that number drops to about 1-1.5k lines per 40 hour work week.

Using those back-of-the-napkin calculations I estimate I'd be able to write 4-15k in the 3 month period, so it's feasible to reach the 3 month deadline and come out with a fairly decent final product. Your numbers will probably be completely different, but that shows you the thought process I go through when answering "Is 3 months a reasonable amount of time?" Also, when I work on a project I tend to sacrifice initial development speed for long-term quality. If you're willing to cut on quality to just get a proof of concept out the door, that initial estimated project size could be massively reduced.

I would also recommend looking for a mentor or collaborator who can help you through the learning curve. Having someone help guide the way or review code can massively speed up the process.

3 Likes

Many thanks for your advices, Michael and skysch. I decided to first implement a dirty prototype in Javascript using biwascheme for scripting and a 2d graphics engine for rendering. A decent product made in Rust may come in the future, then I will share it here.

2 Likes