5 ms·
Racket is "mostly functional" which means that very few "impure" data structures (mcons, for example) and operations are marked explicitly (by convention).
by dschiptsov 12y ago
Racket is "mostly functional" which means that very few "impure" data structures (mcons, for example) and operations are marked explicitly (by convention).
- taeric 12y agoThat does nothing to talk about imperative versus not, though. Does it? The entire for* and let* class of bindings are imperative, in that the order matters. Same with (begin and friends.
- dschiptsov 12y agolet* is nothing but nested lets, which, in turn, are nested lamdas. (let* ((a 1) (b a)) (+ a b)) is an abbreviation for (let ((a 1)) (let ((b a)) (+ a b)))) which, in turn, is a syntactic sugar for ((lambda (a) ((lambda (b) (+ a b)) a)) 1) There is no "assignment", only lexicaly scooped bindings, which are "stateless" and "declarative". Looping constructs in Racket are just syntactic sugar - layered macros, based on what they call "contracts", I suppose. In CL looping constructs are micro-DSLs.
- taeric 12y agoYeah, I chose a somewhat poor example. My main point was that order matters, you have to do A before B. You can not do them at the same time, or something different happens. (Contrasted with a language like VHDL where everything typically happens at the same time.) Simply put, functional is not necessarily the opposite of imperative. I took to googling to see if someone had made my point better already. The best I found quickly is this[1]. It is a good read. As it points out that we are most likely both stuck on different numbers in the "opposite of imperative" definition world. I will say that throwing out mutability with the bathwater is perhaps the single most frustrating thing with most functional advocacy. [1] https://existentialtype.wordpress.com/2013/07/18/what-if-anything-is-a-declarative-language/ https://existentialtype.wordpress.com/2013/07/18/what-if-any...
- tel 12y agoImperative requires order but they are not identical. Imperative tends to mean "sequence of instructions which operate on an exterior set of mutable state cells" versus functional which often means "set of expressions which reduce into values". Each can model the other, but let is clearly functional in this model since its meaning derives entirely from a reduction semantics.
- taeric 12y agoSee my link down thread. I think this really comes down to the murkiness in definitions of declarative and imperative. I did find a later definition that points out that these are no longer duals of each other. I was actively avoiding the obviously imperative functions, though. Not sure why. That is, I could have simply said that the existence of all of the functions that end in exclamation points shows the language is imperative.
- tel 12y agoThe imperativeness of Racket really doesn't come so much from the *! functions, but instead things like `begin` which explicitly sequence program statements in such a way that only allows them to interact via external mutable state.
- taeric 12y agoI have a feeling we are on yet different definitions of imperative and such. (define x 3) (display x) (set! x (add1 x)) (display x) is about as imperative as they come, by my definition. And not a begin in site.
- tel 12y agoYeah, there's sort of an implicit begin around the whole thing, though.