Are there any purely functional Schemes or Lisps?

北城余情 提交于 2019-12-03 18:34:33

问题


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 working in a purely functional language. Therefore:

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


回答1:


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.




回答2:


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!.




回答3:


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.




回答4:


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.




回答5:


inconsistent and non-extendable syntax

What is "inconsistency" here?

It is odd to base a language choice soley on syntax. After all, learning syntax will take a few hours -- it is a tiny fraction of the investment required.

In comparison, important considerations like speed, typing discipline, portability, breadth of libraries, documentation and community, have far greater impact on whether you can be productive.

Ignoring all the flame bait, a quick google for immutable Scheme yields some results: http://blog.plt-scheme.org/2007/11/getting-rid-of-set-car-and-set-cdr.html




回答6:


30 years ago there was lispkit lisp
Not sure how accesible it is today.
[Thats one of the places where I learnt functional programming]




回答7:


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.




回答8:


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)



回答9:


There are a couple of projects that aim to use haskell underneath a lispy syntax. The older, deader, and more ponderous one is "Liskell". The newer, more alive, and lighter weight one is hasp. I think you might find it worth a look.



来源:https://stackoverflow.com/questions/2890347/are-there-any-purely-functional-schemes-or-lisps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!