As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I read in the book: "Masterminds of programming" , the the interview with Guido Van Rossum says:
The more fundamental property Python shares with Lisp ( not a functional language either! ) is that functionas are first-class objects...
So, Lisp is not a functional programming language?
Is Guido wrong? What is it then?
Pretty much every Lisp I know of can be used to program in a functional style (all you really need are first-class functions, after all!)
However, Lisps are more like multi-language toolkits: you can do functional programming, OOP, logic programming, define your own DSL for some whacky new paradigm etc.
The Lisp that is probably closest to a functional programming style is Clojure (it has lazy evaluation, discourages OOP, uses immutable data structures throughout, restricts uncontrolled mutation (via STM), has quite a lot of pure / higher order functions in the core library etc.)
There are languages that allow and encourage functional programming paradigms. Both Python and Lisp are among these. Lisp in particular was the first one to apply theoretical concepts derived from lambda calculus. In the late 1950s, when almost only FORTRAN and Lisp existed, Lisp was highlighted as the functional one, where FORTRAN, with a fully static memory management, would never be considered functional.
However, neither Python nor Lisp enforce pure functionality, allowing mutable variables, states and imperative constructs. A mixture of styles can always be handy in practice, so probably you will not find many example of pure concepts in very successful tools.
Among purely functional languages, Haskell, Clean and Miranda are listed examples, but I cannot say anything about them.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am looking to learn functional programming with an am to integrate Boost.phoenix into my project.
What language is most similar so that I can find books that will illustrate functional programming concepts in a way that can be readily applies in that context... Are haskell and ocaml similar?
ALternately are there any good functional programming books written in general terms that can be applied to Boost.phoenix?
Phoenix enables functional programming (FP) in C++. Consequently, the language that will be most synergistic is going to be C++.
If you want to learn functional programming on its own terms, languages like Haskell and Scheme may be better choices.
http://www.boost.org/doc/libs/1_51_0/libs/phoenix/doc/html/index.html
I don't have any experience with Phoenix (I've skimmed the docs), but I do have some with C++, OCaml, and Haskell so I may be able to help there.
First off, if you learn functional programming you'll find it doesn't translate prettily to C++ - it ends up messier and more verbose than if done in an actual functional language. Nevertheless, it is still worth learning the techniques as they will give you more tools and a different mindset.
Are haskell and ocaml similar?
They are both influenced by ML so they are quite similiar (well, sorta, see the comments). OCaml is closer to C++ because of it's imperative and OO features, but I recommend you learn Haskell as it is more functional, more mindbending, and has more resources. An interesting thing about ML-like languages that they translate quite nicely to template metaprogramming.
ALternately are there any good functional programming books written in general terms that can be applied to Boost.phoenix?
The docs of Phoenix seem to use fairly standard terms. The one thing which could be confusing is their use of the word 'functor' - in C++ it means function object but in languages like Haskell it is something else.
Here are a few terms that you should look for:
lambda / anonymous function
first class function
function application
partial application and currying
composition
strict/non-strict/lazy evaluation
recursion
closures
Here are two free books which I recommend reading as they are a great introduction to functional programming:
http://learnyouahaskell.com/chapters (Haskell)
http://mitpress.mit.edu/sicp/full-text/book/book.html (Scheme)
I don't know much about Phoenix but I think that Okasaki's Purely Functional Data Structures can give you more or less general look how to write programs in functional style.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I prefer Haskell.
I already know How to create my own language with Procedural Language (for example: C, Java, Python, etc).
But, I know How to create my own language with Functional Language (for example Haskell, Clojure and Scala).
I've already read:
Internet Resources
Write Yourself a Scheme in 48 Hours
Real World Haskell - Chapter 16.Using Persec
Writing A Lisp Interpreter In Haskell
Parsec, a fast combinator parser
Implementing functional languages: a tutorial
Books
Introduction Functional Programming Using Haskell 2nd Edition -- Haskell
StackOverflow (but with procedural language)
Learning to write a compiler
create my own programming language
Source
Libraries and tools/HJS -- Haskell
Are there any other good links/sources? I would like to get some more.
Programming Languages: Application and Interpretation is frequently used in programming language classes, and is available online for free. It uses Scheme.
Types and Programming Languages is another incredible book dealing with type systems (including implementation), though only available in dead tree format. It uses ML (which represents a significant family of functional languages that I noticed was missing from your list).
Racket (formerly called PLT Scheme) is a functional language that emphasizes making your own sub-language.
read also:
Christian Queinnec's Lisp In Small Pieces book,
Andrew Appel's Compile with Continuations (and also his book Modern compiler implementation in ML isbn:0521582741)
I also think that Jacques Pitrat's latest book Artificial Beings - the conscience of a conscious machine will give you very interesting insights.
Take also a look at Compiler.HOOPL and Control.Unification libraries, and uuagc attribute grammar preprocessor. You also can read https://wiki.ittc.ku.edu/lambda/images/e/e3/Modular-interpreters.pdf on writing modular interpreters in Haskell. Also note that Parsec is not very fast and for non-toy projects Happy/Alex may be suited better.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
LISP or Haskell, I need to learn functional programming, but I heard that lisp is very old, any advice between those two languages ?
Just to echo the others, I'd learn both Scheme (a more functional Lisp dialect) and Haskell. Scheme / Lisp have some useful tricks to teach you about 'code is data / data is code' and macros. Scheme encourages a good functional style and I would recommend the 'The Little Schemer' series of books to get you started on this. SICP is also a fantastic text http://mitpress.mit.edu/sicp/full-text/book/book.html and possibly one of the best books ever written on programming. Scheme is more accessible as a first functional language.
Once you've got the hang of Scheme you'll probably find yourself becoming frustrated with the lack of libraries, lack of parallelism and the small, although excellent, community. This is where I was when I decided to learn Haskell. Haskell is very mature, very useful and very functional and it is quite a challenge to learn once you move off the basics and so having a grounding in another functional language will help enormously. You won't regret learning either (or both).
Why not both? LISP is very easy to learn (I'd go for the Scheme dialect - see http://racket-lang.org) so I'd start with that. If you like it, stick with it, but I'd also give Haskell a go, although it is (in my experience) considerably harder to wrap your head around.
The great thing about computing these days is that you can try all these languages for free, apart from your time. When I started programming LISP was only available on mainframes, which put a bit of a crimp on trying to learn it.
Haskell, because once you've learned Haskell, you will love it. And then, you will be able to learn Common LISP. However, if your editor is Emacs, then go start with Lisp.
If you want to learn functional programming through implementing a compiler or interpreter of a language, then Lisp or ML should be a better first choice as they're much simpler to implement than a lazy language. Otherwise you'd better learn both.
Choosing based on age is silly, Haskell has been around much longer than say C# and its history extends back a lot further. Anyway I'd recommend learning both eventually, for learning functional programming, Haskell is specifically about purely functional programming (in a number of senses of the meaning). Scheme is a functional orientated descendant of lisp.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Like most ppl, I started with and still do a lot of imperative code(mostly Java, Ruby, Javascript).
I've never been a big fan of OO, either because I never understood it properly or because I don't think OO.
Got my first glimpse of FP via javascript, passing functions around, closures, etc. Have been in love with FP since then.
Recently, I've developed interest in Clojure (and may be Scala) and someday might even have a go at Haskell. I like what I see in the functional approach, but how do I think functional? I've been doing imperative stuff for the past 3-4 yrs and my brain tends to think imperative while approaching a problem.
How can I unlearn the imperative style(do I need to?) and think more functionally ?
No. Don't unlearn imperative style as you'll still need it. Even many well-done FP libraries look somewhat imperative under the covers. It's better to think in terms of adding FP to your list of tools and techniques rather going full-metal with one technique or the other.
Now, as to how you go about learning the FP style? Toy projects - or utility project you write for your own use. Or hell, write yourself yet another blog - but with a twist! The key thing, as was stated above, is practice. When doing so, avoid shared state. Strive for purity (that is, avoid side effects) in as many places as you can. Use closures, pattern matching (if the language supports it) and lambda functions. Think in terms of functions being first-class data types in your program - take them as input and return them as output. The list goes on, but you'll see the same concepts repeated time and again if you're watching for them.
If you feel you need a gentle nudge in this regard, use a tool (language) that encourages the FP style such as F# or Scala.
If you feel you need more of a "tough love" kind of help, reach for Haskell :)
Otherwise use the tool of your choice and just keep FP concepts (above) in mind. If you decide go this route there's a pretty good book called Real-World Functional Programming that uses F# and C# to illustrate techniques that apply in both a "mostly" FP language (F#) and a "mostly" OO language C#.
Go for Haskell. Because it's pure you are forced to think functional. In F# or Scala you still can write very imperative code. I strongly recommend the book by Graham Hutton on Haskell.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
What's the best language (in terms of simplicity, readability and code elegancy) in your opinion, to learn and work with metaprogramming?
I think metaprogramming is the "future of coding". Not saying that code will extinct, but we can see this scenario coming on new technologies.
First -- I don't think I agree with your claim that "metaprogramming is the 'future of coding'". It's a great tool, but not everybody likes it (for example, the Java designers left macros out of the language intentionally -- not that I like Java, but people do have reasons to object to metaprogramming).
Anyway...
I can think of two different ways of doing metaprogramming: on the syntatic level and at runtime.
For syntax metaprogramming, I think Scheme is a good option (if you hadn't mentioned simplicity etc I'd suggest Common Lisp).
For runtime metaprogramming I guess both Prolog and Smalltalk are very interesting. (You can add, change and remove facts to a Prolog database on the fly; and you can change Smalltalk objects on the fly to). You can probably do runtime metaprogramming in Ruby too, but I don't know Ruby.
So --there are several different metaprogramming methods in Scheme (different macro systems). I suggest you take a look at some basic Scheme book and later read about two different macro systems.
Some good Scheme books:
Simply Scheme
Teach Yourself Scheme
Structure and Interpretation of Computer Programs
Scheme implementations are very different from each other, so you'll also use your Scheme implementation manual a lot too.
Some places to learn about Scheme macros:
http://www.lispforum.com/viewtopic.php?f=22&t=100
http://www.ibm.com/developerworks/linux/library/l-metaprog2.html
http://chicken.wiki.br/explicit-renaming-macros
If you decide to use a language that's larger and messier than Scheme, try Common Lisp. There are three books that I'd suggest:
First, "Practical Common Lisp" by Peter seibel. That will get you started on Common Lisp and macros;
Second, "On Lisp" by Paul Graham. You'll then learn that macros are more powerful than what you had thought before, and will learn really nice techniques;
Third, "Let Over Lambda" by Doug Hoyte. An advanced book, best read after Graham's On Lisp.
For Prolog, you can read "Programming in Prolog" by Clocksin and Mellish (get the latest edition!) and later move on to "Prolog Programing in Depth" by Covington, Vellino and Nute. See chapter 6.
There are lots of good Smalltalk books. I like "The Art and Science of Smalltalk" by Simon Lewis.
There's a very nice free tutorial/primer by Canol Gokel about Smalltalk too (but it doesn't go as far as teaching metaprogramming).
What do you mean by metaprogramming? Metaprogramming is a set of concepts, rather than one specific technique.
See this answer where I've listed various concepts and related languages. Here is a summary:
Metaprogramming with macro --> Lisp
Metaprogramming with DSL --> Many languages for internal DSL, external DSL is more tricky
Reflection --> Smalltalk, Ruby
Annotations --> Java
Byte-code or AST transformation --> Groovy
See the complete answer for more details. Generally speaking, I think that a good OO all-rounder is Ruby. Otherwise any Lisp-like is will do the job: it's like putty in your hands. But that will depend on what you want to do...
The Lisps are pretty much the language of choice for a wide variety of metaprogramming techniques. Of the modern Lisps available, I would recommend Clojure as a more accessible Lisp that has access to a positively HUGE library (anything in Java land) if you want something that is both powerful and immediately useful.
For other approaches to metaprogramming almost any functional language will do the trick. Haskell is a good choice for learning techniques and functional programming but isn't what I'd call the most practical language to do real work in at this time. Erlang is more practical, but not quite as amenable to metaprogramming. OCaml is another possible choice but suffers a bit on the practicality front as well. It is more accessible than Haskell in many regards, however.
In the scripting language world Ruby is a language in which metaprogramming is a popular technique. Its approach is vaguely Lisp-like, but with a far more conventional syntax. It lacks the full power and flexibility of the Lisps, however, but on the other hand, with the exception of Clojure above, it has a lot more immediate practical utility.
Ruby has very powerful and flexible metaprogramming capabilities.
There are several languages that I would recommend for studying meta-programing.
The first is Prolog. A Prolog program is a database. Prolog "code", the clauses, are part of the data. The program can read them, including their content. It can also generate new code as a data structure and assert it, thus changing itself on run-time. All of this without using term expansion, which is Prolog's smart macros system. Some Prolog AI books start with implementing a meta-interpreter in Prolog, and then changing it by need.
The second is, as mentioned, Lisp, and particularly CLOS (Common List Object System), which includes commands for meta-OOP.
Finally, Python support a nice and not too obscure mechanism for run-time meta-programming, which is it's meta-classes (classes that create classes).
I'm surprised no one has mentioned ML. ML stands for Meta Language. so... yeah... CaML is a standard implementation. (OCaML, which JUST MY correct OPINIO mentioned is the OO version of CaML, which probably adds features that make the meta-programming less obvious...)
Other than that, I am a big fan of Scheme, but pretty much any Functional programming language is good for this... There's always the Little Lisper, er, sorry, the Little Schemer...
Don't know if we have the same definition of "meta programming" but there is certainly not ONE best language to learn. I would propose that you have a deeper look at functional programming. Which language to choose for that depends on your background and working environment. I would choose F# at the moment, but Haskel should also be a good choice.
cheers,
Achim