Hello,I would wonder what is community thinking towards immutability compile flags or at least have Object#freeze lke Ruby?
--
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/30b2f553-6a76-4ea1-b263-cbd0cfe7e519%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Crystal" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/crystal-lang/_GCDcmHvEck/unsubscribe.
To unsubscribe from this group and all its topics, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CA%2BdJ3wShNUT6n%3D1qoSc%2B1XrmDeb3fLX0iGKNAywwr8zsUpihpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CAFGdg2V67VMn29Hkv-g1jOaDRwOmROiwB%2BeumRnVf3zYRGF38w%40mail.gmail.com.
Adding to the discussion about immutability, although Crystal does not enforce strict immutability (a good decision, in my opinion) it provides all the facilities to implement efficient immutable data structures. I recently authored a shard providing immutable maps and vectors with structural sharing:
https://github.com/lucaong/immutable
--
You received this message because you are subscribed to a topic in the Google Groups "Crystal" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/crystal-lang/_GCDcmHvEck/unsubscribe.
To unsubscribe from this group and all its topics, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/1a73c6e9-df9f-4583-b16c-242c81671725%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/dd5722a7-af78-49d6-ae74-85445292af2e%40googlegroups.com.
While a tool that asserts that certain classes have no setters is very easy to implement, ensuring full immutability would be very hard as far as I see. One would have to assert that no method apart from the constructor writes any state, and no mutable object is exposed. This while still allowing for memoization, returning defensive copies of mutable objects, and other forms of "allowed" mutability.
Other languages enforce immutability from the ground up by having everything immutable apart from a few well defined mechanisms (e.g. Clojure). But doing this in Crystal would mean creating a totally different language. While being a big fan of functional programming and immutability, I personally think that it's an advantage for Crystal to let the programmer decide. It enables use cases like game programming where in-place mutability is desirable.
One thing that I personally think would be nice in a future is to have solid implementations of fundamental immutable data structures in the core (immutable map, vector, set, etc.). They would come very handy when doing concurrent programming.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CAFGdg2UJeQceVpLSPmPO61SQpi4EL3uY4erAK92x3zimfAm0Xw%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CANub5_ggCaY4qTZX54XJkK2z2GFPNNt5zg-hD3Pk1X%3DvoWexNA%40mail.gmail.com.
Nope theu are not, but recirds are ...please read Ary ansewer on that
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CAJJJDy%2BuLQd0sUYyARLYsa%2Br7XfmmxSjdzAQSYbnpGm3L-Lm1w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CANub5_ggCaY4qTZX54XJkK2z2GFPNNt5zg-hD3Pk1X%3DvoWexNA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
- Joseph Method
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/CACm%3Dc66A-%3DmUmQOTwbcWFTTaYLZZ0XYBNGxyN3bg6AR%2BLKDX7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Regarding how structs work:1. They are allocated in the stack and passed by value