views:

419

answers:

7

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)?

+3  A: 

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

Don Stewart
Remove the flame bait then. You don't need to explain yourself, especially if it is irrational or immature. A more important question to answer would be: why are you so interested in referential transparency over all else (including types!). Perhaps modify your question to explain that instead of complaining about syntax.
Don Stewart
Why not split the difference and use Liskell? (To the OP: I edited the original post to remove the flamebait. If you don't want to have a "flamewar", keep your comments about the syntax to yourself. Otherwise, your question will be closed for being subjective and argumentative.)
jrockway
@nickname: As I mentioned in my answer, a lot of Haskell's syntax is actually optional fluff. Just `data`, `case`, and lambdas will let you do almost everything you'd want to do.
camccann
I tried to remove all of the flame bait and reference to it, including the comments explaining the syntax. I'm still new here, so I'm still unsure about the exact protocols for asking and answering questions.Thanks for your help :)
nickname
i'd suggest your entire question could be reduced to: "I'm interesting in playing with a purely functional / referentially transparent version of Scheme. Does anyone know of one?".
Don Stewart
@Don Stewart - Done. Thanks for helping me clarify the question.
nickname
+4  A: 

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.

camccann
"anything in IO is only "pure" in some torturous, hand-waving sense of the word". Conal is controversial. A much cleaner description relies on realizing that IO describes actions, and a clear denotation can be made: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.13.9123
Don Stewart
Thanks for the response. As I said above, I don't actually care about how "productive" the language is in the traditional sense.In general, I'm only looking for a purely functional language because I would like to play with the possibilities. Nothing more!
nickname
@Don Stewart: It's not so much denotation as the practical end result: `IO` is better than nothing, but with sufficient perverse intent it opens you up to many of the same pitfalls and mistakes that code in an impure language would. The benefit Haskell offers is that it's easier to avoid such situations in the first place. But it doesn't sound like that's relevant to the questioner, so no worries.
camccann
+4  A: 

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.

Norman Ramsey
+3  A: 

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.

j-g-faustus
+2  A: 

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)
yairchu
+1  A: 

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.

George Kangas
+3  A: 

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

jonr