3 ms·
Can you elaborate? Smalltalk was certainly a pioneer in that area but in the past twenty years, plenty of languages have implemented closures in a way that's p
by hota_mazi 5y ago
Can you elaborate?
Smalltalk was certainly a pioneer in that area but in the past twenty years, plenty of languages have implemented closures in a way that's pretty much 100% identical to how Smalltalk did it, just with different syntaxes.
What's so different about Smalltalk's closures from the likes of Rust, C#, Kotlin, Swift, Groovy, etc...?
- pjmlp 5y agoThey are objects as well, you can get the metaclass of a Smalltalk code block and manipulate it at your pleasure.
- mpweiher 5y agoOne difference is that they are used for all control structures: a = b ifTrue:[ ... ] a = b ifFalse:[ ... ] a = b ifTrue:[ ...] ifFalse:[ ... ] [ a = b ] whileTrue: [ ... ] And "control structures" aren't actually control structures that are built into the language. They are just messages sent to blocks (closures). That includes iteration, so a for "loop" is: 1 to:10 do: [ :i | ... ] Which is just a shorthand for (1 to:10) do:[ :i | ... ] With (1 to:10) creating an Interval object, a virtual collection that understands the normal collection iteration protocol (do:, collect:, select:, reject:, inject: ). OO + Closures + keyword syntax. An elegant and powerful combination.
- afandian 5y agoIt's been a while but this looks very much like Ruby to me.
- projektfu 5y agoNot “part of the language” but definitely privileged in the implementation. #ifTrue:ifFalse: gets rewritten and inlined as a branch in just about every compiler. If you implemented your own, it would suffer in performance.