Are there any purely functional Schemes or Lisps?

前端 未结 9 1158
不知归路
不知归路 2020-12-24 07:10

I\'ve played around with a few functional programming languages and really enjoy the s-expr syntax used by Lisps (Scheme in particular).

I also see the advantages of

相关标签:
9条回答
  • 2020-12-24 07:34

    Probably not, at least not as anything other than toys/proofs of concept. Note that even Haskell isn't 100% purely functional--it has secret escape hatches, and anything in IO is only "pure" in some torturous, hand-waving sense of the word.

    So, that said, do you really need a purely functional language? You can write purely functional code in almost any language, with varying degrees of inconvenience and inefficiency.

    Of course, languages that assume universal state-modification make it painful to keep things pure, so perhaps what you really want is a language that encourages immutability? In that case, you might find it worthwhile to take a look at Clojure's philosophy. And it's a Lisp, to boot!

    As a final note, do realize that most of Haskell's "syntax" is thick layers of sugar. The underlying language is not much more than a typed lambda calculus, and nothing stops you from writing all your code that way. You may get funny looks from other Haskell programmers, though. There's also Liskell but I'm not sure what state it's in these days.

    On a final, practical note: If you want to actually write code you intend to use, not just tinker with stuff for fun, you'll really want a clever compiler that knows how to work with pure code/immutable data structures.

    0 讨论(0)
  • 2020-12-24 07:39

    The new Racket language (formerly PLT Scheme) allows you to implement any semantics you like with s-expressions (really any syntax). The base language is an eagerly evaluated, dynamically typed scheme variant but some notable languages built on top are a lazy scheme and a functional reactive system called Father Time.

    An easy way to make a purely functional language in Racket is to take the base language and not provide any procedures that mutate state. For example:

    #lang racket/base
    (provide (except-out (all-from-out racket/base) set! ...more here...))
    

    makes up a language that has no set!.

    0 讨论(0)
  • 2020-12-24 07:46

    If you like lisp's syntax then you can actually do similar things in Haskell

    let fibs = ((++) [1, 1] (zipWith (+) fibs (tail fibs)))
    

    The let fibs = aside. You can always use s-expr syntax in Haskell expressions. This is because you can always add parentheses on the outside and it won't matter. This is the same code without redundant parentheses:

    let fibs = (++) [1, 1] (zipWith (+) fibs (tail fibs))
    

    And here it is in "typical" Haskell style:

    let fibs = [1, 1] ++ zipWith (+) fibs (tail fibs)
    
    0 讨论(0)
  • 2020-12-24 07:48

    there is owl lisp, a dialect of scheme R5RS with all data structures made immutable and some additional pure data structures. It is not a large project, but seems to be actively developed and used by a small group of people (from what I can see on the website & git repository). There are also plans to include R7RS support and some sort of type inference. So while probably not ready for production use, this might be a fun thing to play with.

    0 讨论(0)
  • 2020-12-24 07:53

    Are there any purely functional Schemes (or Lisps in general)?

    The ACL2 theorem prover is a pure Lisp. It is, however, intended for theorem proving rather than programming, and in particular it is limited to first-order programs. It has, however, been extremely successful in its niche. Among other things, it won the 2005 ACM Software System Award.

    0 讨论(0)
  • 2020-12-24 07:54

    I don't believe there are any purely functional Lisps, but Clojure is probably the closest.

    Rich Hickey, the creator of Clojure:

    Why did I write yet another programming language? Basically because I wanted a Lisp for Functional Programming designed for Concurrency and couldn't find one.

    http://clojure.org/rationale

    Clojure is functional, with immutable data types and variables, but you can get mutable behavior in some special cases or by dropping down to Java (Clojure runs on the JVM).

    This is by design - another quote by Rich is

    A purely functional programming language is only good for heating your computer.

    See the presentation of Clojure for Lisp programmers.

    0 讨论(0)
提交回复
热议问题