4 ms·
> I can't get past the lack of currying. Say again? Currying may not exist as a special form, but adding it is utterly trivial: [0] Which I guess is where Lis
by shakna 10y ago
> I can't get past the lack of currying.
Say again? Currying may not exist as a special form, but adding it is utterly trivial: [0]
Which I guess is where Lisp shines. Modifying the language to suit your needs is easy. You aren't bound by the limits that many languages force upon you.
That being said, I wouldn't say that Common Lisp or Ocaml have the same userbase. In much the same way that C and JavaScript don't serve the same domain.
ML languages are about safety, and correctness.
Lisps tend more to be about speed of development, and flexibility.
That being said, as just about any paradigm can be implemented in a modern Lisp, and perhaps older ones as well, there are places where they can cross over with this want of correctness.
Racket is an experimental Lisp that grew out of Scheme, and is basically a family of languages, or a Lisp-ish language framework for creating other languages. Among the inbuilt languages, is typed/racket [1]. It uses contracts or inference to ensure type safety at compile time. Due to Racket's language features, if you add contracts, typed/racket can use, or be made use of, by other Racket languages, like lazy/racket[2] and scribble[3].
Other Lisps can have similar things, as you saw with currying, Common Lisp can have compiler hints, or even static typing [4]. Clojure has a ML style matching library [5], inbuilt.
Basically, where you might hit a "I'm approaching this problem the wrong way" in most languages, you can simply write a quick, simple, effective macro, and carry on, in most Lisps.
As to what you may think a Lisp looks like... See Wisp [6]. Which, arguably, isn't a Lisp. But it is basically just a bunch of macros on top of Guile (a Scheme).
[0] http://cl-cookbook.sourceforge.net/functions.html#curry http://cl-cookbook.sourceforge.net/functions.html#curry
[1] https://docs.racket-lang.org/ts-guide/ https://docs.racket-lang.org/ts-guide/
[2] https://docs.racket-lang.org/lazy/ https://docs.racket-lang.org/lazy/
[3] https://docs.racket-lang.org/scribble/ https://docs.racket-lang.org/scribble/
[4] ftp://ftp.cs.utexas.edu/pub/boyer/diss/akers.pdf
[5] http://blog.klipse.tech/clojure/2016/10/25/core-match.html http://blog.klipse.tech/clojure/2016/10/25/core-match.html
[6] http://www.draketo.de/english/wisp http://www.draketo.de/english/wisp
- lispm 10y agoAdding 'curry' is relatively easy. Difficult is the idea of implicit currying: a function call with one argument less, returns a curried function. (mapcar (+ 1) '(1 2 3)) Above does not work in Lisp, because it has variadic function arguments and no automatic currying. One would always need to explicitly write that (+ 1) should not return 1, but the function 1+. In some functional programming languages it works, because + with one argument returns a one argument function.
- kazinator 10y agoBut we can easily write a function plus such that (plus) returns (lambda (x y) (+ x y)), (plus 1) returns (lambda (y) (+ 1 y)) and (plus 1 1) just returns 2. And we can make a function writing macro to simplify writing such a function.
- lispm 10y agoTrue: but still you have to decide at definition time what kind of function it is. Plus it adds bloat to the function. Ideally the currying would be a task for the compiler/interpreter.
- kazinator 10y agoDefinition time is a big deal in static languages. For us, that could be while the app is running. I want that three arg function inside that running service to curry if called with two args, with no restart. Poof, done.
- shakna 10y agoImplicit currying sounds like a bad idea, at least for a Lisp. Most Lisps show off inbuilt functions that have side effects, such as setf in CL or set! in Scheme. Magic with side effects tends to be looked down on in the community, because it changes an incredibly simple syntax that is just about self-describing to one that has cognitive load in differing circumstances. Take pity on whoever has to come after you. My point was merely to show that it is possible. It should be also possible to add implicit currying, by messing with a read macro, but I would ask that you don't.
- kazinator 10y agoAnother consideration/angle is this. Suppose I call a three-arg function with only two args. Why should that curry in the Haskell way? That is just someone's design opinion. Suppose I want that two-arg call to return a function, but not the ordinary curried one. For instance, I might want the function to curry to a transduce kernel. Meaning, I can pass the resulting function to reduce, such that the reduce now performs a mapping through the original function. In other words, this: (map (lambda (x) (foo 1 2 x)) list) <--> (reduce (foo 1 2) list) In mainstream languages that have implicit currying, we're stuck with the one and only currying semantics.