7 ms·
> ... in a way that an imperative language could not Perhaps a nitpick, but sometimes nomenclature is important. Clojure (like all Lisps) is an imperative prog
by pron 12y ago
> ... in a way that an imperative language could not
Perhaps a nitpick, but sometimes nomenclature is important. Clojure (like all Lisps) is an imperative programming language. "Imperative" languages are contrasted with "declarative" languages[1]. Where does functional fit in and what is the name for "non-functional"? Well, that's not clear, as "functional" (in the PL sense) doesn't even have an agreed upon definition. Is Clojure "functional", then? Well, it's certainly not pure like Haskell is (and it has explicit loops etc.), but it does encourage more uses of function composition than, say, Java, it's more declarative, and it also isn't object-oriented, but that doesn't make it not imperative. Actually, I think even Haskell still qualifies as imperative.
But Clojure can certainly be contrasted with OO and procedural languages (even though at least one of its core abstractions -- protocols -- is borrowed from OO).
[1]: http://en.wikipedia.org/wiki/Imperative_programming http://en.wikipedia.org/wiki/Imperative_programming
- andreasvc 12y agoI think declarative should be contrasted with procedural, not imperative. Also, your reference/footnote [1] is missing.
- wtetzner 12y agoActually, I would say that protocols are more influenced by Haskell type classes than OO interfaces.
- eru 12y ago> Actually, I think even Haskell still qualifies as imperative. How so?
- LesZedCB 12y agoTechnically, if a language can produce side effects, it's considered imperative. However, nobody really is going to say that Haskell is imperative.
- Tyr42 12y agoThough there are some claiming that Haskell is the best imperative language because of having to state upfront what effects each bit of code can have. Since evaluation order is not very straight forward in Haskell, effectful code has to be explicitly ordered, which makes is very clear.
- innguest 12y agoThe language called Haskell cannot produce side-effects. You see the side-effects when you execute a program. That is, you cannot create side-effects within the language (except for escape hatches for FFI purposes). This is different from other languages in that saying "what to print" is an actual command (hence, imperative) and not a value, as it is in Haskell (things that "will be commands when the program is run" are values in Haskell, as numbers and strings are).
- theseoafs 12y ago> The language called Haskell cannot produce side-effects. You see the side-effects when you execute a program. This is a rather meaningless distinction -- indeed, you can say the same thing about any other language on the planet. Programs written in C, Python, Ruby, ML, R, and Brainfuck only have side effects when you execute them. Obviously a C program just sitting on your hard drive unexecuted doesn't have any side effects.
- innguest 12y agoNo. It's a very meaningful distinction, actually. Compare: Ruby: will_print = puts "hello world" # it already print to the screen! and will_print does not have any meaningful value -- indeed it's nil Haskell (demonstrated on the repl, which runs inside the IO monad): let willPrint = putStrLn "hello world" -- nothing gets printed! willPrint -- now the string gets printed (only because the repl is inside the IO monad which promises to execute action values) Haskell (not in the repl): willPrint = putStrLn "hello world" -- nothing gets printed! willPrint -- this returns the same that 'putStrLn "hello world"' returns - an action value that, when run inside the IO monad, will execute its actions - so this still doesn't print anything, and we can pass willPrint around without side-effects, and compose values with willPrint main = willPrint -- now the compiler will make good on its promise to execute any action value that is named 'main', and "hello world" will be printed to the screen. The point of this is that you cannot print inside the Haskell language (nor do any other side-effect) - when you try to print you get this "action value" thing that you as a programmer cannot execute. Only the compiler can. So you can pass Ruby's equivalent of "puts 'hello world'" around, which you can't in Ruby. So the distinction is quite clear. > Programs written in C, Python, Ruby, ML, R, and Brainfuck only have side effects when you execute them. They clearly don't. That's why when I write in Ruby: puts "hello world" Then the next line of code will be executed in a world where 'hello world' has already been printed to the screen. Likewise, when in Ruby I write: a = 5 a += 1 Then the next line of code will be executed in a world where a is 6. So every line of code you write depends on the side-effects that came before it. Therefore, Ruby and most other languages have side-effects before code is executed. This is not the case in Haskell. Hence, no side-effects.
- LesZedCB 12y ago>Clojure (like all Lisps) is an imperative programming language. "Imperative" languages are contrasted with "declarative" languages. Wikipedia, and probably everybody, defines truly functional programming languages (which includes Clojure and the other Lisps) to be declarative, not imperative. [1] [1] http://en.wikipedia.org/wiki/Declarative_programming http://en.wikipedia.org/wiki/Declarative_programming
- mrottenkolber 12y ago> truly functional programming languages (which includes Clojure and the other Lisps) This is wrong. I don't know how to say this... Lisps do usually support functional programming paradigms, but most Lisps are indeed anything but functional (in the ML sense).
- dragonwriter 12y agoLisp was considered a functional programming language before ML existed. Lisps generally don't have as strong and exclusive support for the functional paradigm as some newer languages (and pretty much anything else still in use is newer than lisp), but then C++ is known as an OOPL despite having less strong and exclusive support for the OO paradigm than many older languages, so there's that.
- AnimalMuppet 12y agoLisp is a multi-paradigm language. It can be functional, but it doesn't have to be. It can be OO, but it doesn't have to be. Classifying it as "being" any of these is asking for argument, unless you have very clearly defined (and agreed-upon) definitions of what it means to be a member of one of those categories. In particular, does membership mean that you require programming in that style, or only that you allow it?
- bitwize 12y agoLisp was considered a functional programming language before ML existed. That was then and this is now. Today, functional programming means side-effect-free with a strong type system, and efficient use of higher-order abstractions over functions, including things like typeclasses to define entire morphisms given a few functions which establish relationships between objects. Lisp doesn't really support this effectively. Arguably, with concepts C++14 is more functional than Lisp.
- bjourne 12y agoTaken to the extreme like you are doing, no language could ever be considered "functional" because in the end, they all need to perform io and ordered execution to be of any use. Instead, the commonly understood meaning of the word "functional" is that the language's design emphasizes and encourages use of immutable data and Clojure fits that meaning.
- wcummings 12y ago>Instead, the commonly understood meaning of the word "functional" is that the language's design emphasizes and encourages use of immutable data and Clojure fits that meaning. I would say a language which relies on functional composition as its primary abstraction is "functional." Immutable data is a side effect of that.
- bad_user 12y agoI would say that immutable data is a prerequisite for doing functional composition and languages that don't have immutable data-structures in their standard libraries are not used as FP languages.
- innguest 12y ago"They all need to perform IO" - why does a programming language need to perform IO? Haskell does not have a function that performs IO. For instance, `putStrLn "hello world"` returns an IO action, but it does not print anything to the screen. In order to "perform IO" you have to name an IO action 'main'. Then the compiler understands that you want that action to take place in the Real World. But Haskell does not know about the Real World and so it cannot do IO. This difference is important, otherwise there is a misunderstanding that Haskell is just "minimizing IO". It's not - there's no IO.
- s-phi-nl 12y agoIt is meaningless to nitpick about whether a language is declarative or not since the term "declarative" lacks a good definition. Robert Harper, a programming languages researcher, lists 6 separate definitions and concludes, "It seems to me that none of them have a clear meaning or distinguish a well-defined class of languages. " [1] [1] http://existentialtype.wordpress.com/2013/07/18/what-if-anything-is-a-declarative-language/ http://existentialtype.wordpress.com/2013/07/18/what-if-anyt...