by technomancy · 11y ago · 0 comments
It has multiple Lipsy dialects: http://docs.racket-lang.org/guide/dialects.html
And a datalog one: http://docs.racket-lang.org/datalog/index.html
It knows C: http://pkg-build.racket-lang.org/doc/c/index.html
And Javascript: https://github.com/lwhjp/ecmascript
And Algol: http://docs.racket-lang.org/algol60/index.html
And Pascal: https://github.com/soegaard/minipascal
It shouldn't be too difficult to teach it Lua ;).
Scheme and all the other Lisp variants look terrible to me. Having an excessively simple syntax doesn't mean that it's nice to use. They went too far.
This is probably the primary reason why Lisp dialects aren't more popular. Even the simplest code examples look like some sort of practical joke.
(let ((hello0 (lambda() (display "Hello world") (newline))))
(hello0))
[Edit: This example was taken from Wikipedia's Scheme article.]Something like that in Dart:
hello() => print('Hello world');
hello();
Dart's syntax is way more complicated, but this is much easier to understand, isn't it?1. You chose a better function name (hello0 looks a little confusing)
2. You [EDIT: actually Wikipedia] decided for whatever reason to use let rather than define in the Scheme example.
3. Dart's "print" function is more suitable for console output on a single line than Scheme's "display".
Here's the fix:
(define (print something)
(display something)
(newline))
(define (hello)
(print "Hello world"))
All of a sudden (f a b) doesn't seem way more complicated than f(a, b);. (define (hello)
(displayln "Hello world"))If you want to see more realistic examples go to RosettaCode, pick interesting task and look for Scheme, Racket and Clojure entries. You can then compare them to each other and to other languages you know.
The other thing is that your code in Scheme and Dart don't do the same thing at all, unless I underestimate Dart semantics very much. A translation of your Scheme code to JS, with as much semantics preserved as possible, would look something like:
(function (){ // let introduces new scope
var hello0 = function (){ // hello0 is a variable holding an anonymous function
return console.log("Hello world");
};
return hello0();
})();
That's quite a bit of work less in Scheme, isn't it? But for when you don't need these semantics you can do a translation the other way round (Dart->Lisps). In Racket your Dart example would look like: (define (hello) (displayln "Hello world"))
(hello)
Now, that looks better, right? It's worth noting that the Racket version has only one pair of parens than Dart. (func: hello() => (displayln "Hello world"))
(hello)
All you need to do this - to change the language syntax to look like that - is to write this: (define-syntax func:
(syntax-rules (=>)
[(_ name (formal ...) => expr ...)
(define name (lambda (formal ...) expr ...))])) (define (hello)
(displayln "Hello, World!"))
(hello) define (hello)
displayln "Hello, World!";
hello;
The boot 'compiler' only did name resolution and parenthesization, then it kicked everything back to an underlying LISP. (In this case, SBCL, which rocked!)The second level language built on Boot was Spad, which used a slightly friendlier syntactic top-form:
e : t = x
With compact forms: e := x
e = x
e : t
e
Which lets you uniformly parse packages, modules, domains, categories, functions, annotations, etc. etc. For instance, we had a Spad-lite syntax: Monoid : Domain = public :
_* : (y : Monoid), (x : Monoid)
_0 : Monoid
Then you could assert membership: assert(Integer, Monoid) :=
_* : (y : Integer), (x : Integer) = (_*:Integer)(x, y)
_0 = (0:Integer)
An implementation would be: Monoid : Domain = public :
-- see above.
= implements :
-- implementations. defun fact (n)
(cond
..
..)
which makes lisp so much more bearable to parensophobic people. (defn hello [] (println "hello world"))
(hello) ;; in Clojure
(defun hello () (format t "hello world"))
(hello) ;; in Common Lisp.I do not know how to write Hello World in Scheme.
By the way, I really like how everyone's Hello World looks different.
Because everyone is posting hello world examples in different languages. Lisp is a family, a category of languages, not a single language.
The example you gave is using the lowest level primitives to printing with zero syntactic sugar. It's equivalent to writing the following in JavaScript (assuming functions called 'display' and 'newline':
(function () {
var hello = function() {
display('Hello world');
newline();
};
hello();
})();
Practical Scheme implementations include additional macros that add syntactic sugar so you an use much more straightforward mechanisms to do things. (let ([hello-func (lambda ()
(displayln "Hello world!"))])
(hello-func))
This applies globally; when it makes sense, differentiate between some lists by using brackets instead of parens. Some Lisps take this further by using other bracket types to signify certain things.I would advise not to hop on Wikipedia and assume things about languages. Scheme is not very hard to get into and with variants where batteries included you can build useful stuff right out of the box.
Go to http://www.racket-lang.org/ if you want to see a good example of a pragmatic and useful Scheme variant that may just dispel some of your prejudices.
Baby duck syndrome?
> Having an excessively simple syntax doesn't mean that it's nice to use.
Having an excessively simple syntax ensures that you can add any amount of syntax on top of it, whatever you fancy. Do not like S-expressions? Fine. Code in any syntax you like.
> but this is much easier to understand, isn't it?
No, it is not.
(let [hello (fn []
(println "Hello World"))]
(hello))
Or assuming hello is a global in your dart example: (defn hello []
(println "Hello World"))
(hello)
Nothing too complicated about that. Clojure is way less verbose than some scheme variants.The way it's written implies that it's somewhere inside some block, because "main()" is always the entry point. I wrote it like that because I couldn't be bothered to figure out how this stuff works in Scheme.
With entry point:
main() => print('Hello World');
Alternatively: main() {
print('Hello World');
}I think that sums everything up, really. This is how shallow the complaints about parens are. No one who actually bothers will make a point about what delimits expressions in a language.
To complain about parens is also doubly wrong, as they do bring something technical to the table.
What Carmack talks about when he says S-expressions are nice for reading in terms of network communication, for example, is that the messages can be read exactly like other expressions over the wire. This is true for any I/O; you can read the data just as if it was code, because the code is data. The same mechanism that reads the code you are executing is available to you to read full expressions through any medium, and use that data/code as you see fit.