Hacker News new | past | comments | ask | show | jobs | submit login

>locally scoped, mutation-heavy, imperative code is fine as long as you can wrap it in a deterministic, immutable interface for general use.

Yes! Clojure supports this via transients. What's even better is that you can write the loop using immutable data, make sure it works. Then just

1. add a call to transient in the initializations,

2. add a call to persistent! in the end and

3. add a ! to each function that modifies the transient, e.g. conj becomes conj!

The benefit in doing it this way is that the language will catch and flag as errors any "mixed" usage - calling a pure function with a mutable argument or vice-versa.

https://clojure.org/reference/transients

http://www.hypirion.com/musings/understanding-clojure-transi...




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: