5 ms·
As a sort of beginner to functional programming, could you explain to me why you chose a functional language to do this sort of thing? Just for fun? I love it b
by prezjordan 14y ago
As a sort of beginner to functional programming, could you explain to me why you chose a functional language to do this sort of thing? Just for fun? I love it but I can't see the benefits of functional programming.
- pavpanchekha 14y agoIt's not a functional programming language. It isn't Haskell or Coq. It's Racket, a derivative of Scheme, which happily supports mutable or immutable state, monads or continuations, imperative, procedural, functional, object-oriented, or logical programming.
- jgn 14y agoIt's not a PURE functional language, but it's certainly functional.
- mahmud 14y agoRacket also has an Algol mode :-P
- Locke1689 14y agoIt also has a dataflow language, a typed language, a lazy language, etc. Racket is not one language, it's a language family platform (or language laboratory). Matthias summarized this pretty well[1]. [1] http://www.ccs.neu.edu/home/matthias/Thoughts/Racket_is____.html http://www.ccs.neu.edu/home/matthias/Thoughts/Racket_is____....
- mahmud 14y agoI found that essay most enjoyable. Thank you for the link, mate! :-)
- dsrguru 14y agoThat just becomes a debate about the definition of a functional language. The point is that unlike Haskell, SML, and OCaml (the last two aren't "pure" in the sense of syntactically enforcing referential transparency like Haskell, but they strongly encourage a functional design), Racket is first and foremost a LISP. You can use it to write and make use of a lot of functional abstractions, and it certainly is better suited to that style of programming than C or Java is, but Python and Ruby are just about equally suited for that style of programming, and they even have equivalents of map, filter, fold, lambda, etc. Racket code doesn't look like Haskell, the MLs, or even dynamically typed "functional" languages (like Erlang). It looks like LISP. What drives your coding is not functional abstractions or object-oriented data structures (which it can do equally well) or anything like that. What drives your coding is the fact that syntax itself is a first-class data structure. You have access to the reader. You can write macros that adapt the language to anything you want. You can write a DSL in a few hundred lines that might save you tens of thousands of lines. Now, Racket is certainly good for functional programming. In fact, some Racket developers prefer the Scheme-style tail recursion method of iteration (via the named let or letrec) to the looping constructs provided in the library, even when for loops would be just as effective. In the same way, not all Common Lisp programmers like the loop macro, and some (e.g. pg) actually use Common Lisp in a style that resembles functional programming. However, don't think of Racket as a functional language. That's as misleading as calling C++ a procedural one, even though you could write all your code C-style without ever using objects. Racket is a LISP, which means it can be adapted to fit virtually any paradigm. Racket is far closer to Common Lisp and Clojure than it is to literally any non-LISP.
- Locke1689 14y agoAside from the fact that I still don't think that "a Lisp" is a thing, Racket is not bound to s-expr syntax. The racklog/prolog #langs make that very clear.
- dsrguru 14y agoI'm talking about the racket #lang, not the collection of all languages that the distribution can interpret. R5RS, for example, is included in the distribution, but the R5RS found in the Racket distribution is identical to that of any other Scheme interpreter or compiler, so discussion about its features has nothing to do with discussions specific to Racket. There are also experimental variations of the main racket language like typed racket and lazy racket, but I don't have enough familiarity with them to discuss their classification. I'd assume lazy racket is mainly used in a functional style. But anyway, the main Racket language is very much an s-expression based language (the typed and lazy varieties are as well). What do you mean by not believing in LISP as a classification of languages? Are you saying you don't think s-expression based languages are at least as similar to each other as, say, OOP languages or logic languages are too each other?
- gcr 14y agoBelive it or not, this library grew out of a direct need of mine. :) One thing that I've been using Racket for is to make research posters for conferences. Racket has an excellent library for functional picture/slideshow composition; you can read about that here (which doubles as a great intro to racket in general): http://docs.racket-lang.org/quick/index.html http://docs.racket-lang.org/quick/index.html It's sort of like a "LaTeX for pictures"; where you can say (vc-append (square 10) (circle 10)) to have a 10px square sitting on top of a 10px circle (vertical, centered). Once you build your poster this way, you can save it as a PDF. This is geat for having perfectly aligned blocks of text sitting in perfectly spaced colums, for example. It's much better than fiddling with the layout manually in powerpoint. However, in designing my poster, I have to include PDF figures. Racket didn't include a way of rendering PDFs, so in my last poster, I had to use 600DPI bitmaps of my figures, which was slow and made the file terribly huge. This library binds to libpoppler, which is great because Racket's native pictures are Cairo-backed anyway, and Racket's FFI is top notch (once you can figure it out). Now I can use the usual functional composition to add these PDF figures to the rest of my poster.
- zem 14y agoparsing is absolutely the sort of problem for which functional programming excels. if you think about it, there is no time dependence, no need to respond to external inputs, no concurrent access to mutable data, none of the things that would make pure functional programming a constraint rather than a help. all your are doing is writing one conceptual function of the form output = f(input), and that transformation is in turn made up of smaller transformations that can be written and tested independently, and then composed together to build up the solution. now it might still be a little harder to do this sort of thing in haskell, which is aggressively pure, simply because some algorithms are pure from the outside but have internal steps that involve mutating data for efficiency. but racket is not a pure functional language; if you need to, say, transform an array in place rather than take an array and return a new one, it will not stand in your way. the difference between racket and, say, java, is not that it enforces functional over imperative programming, but that it makes functional programming a lot easier, and fp has a lot of powerful tools in its toolbox for tackling this class of problem.
- Peaker 14y agoDid you try reading Why Functional Programming Matters [1] ? [1] http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pd...
- prezjordan 14y agoThanks for this!