by viach · 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. (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.
(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');
}Bullshit.
John Carmack:
> >An imperative API makes functional abstraction harder. What are the main selling points for Scheme/Racket now?
> I am a big believer in functional programming (and static types) for large projects, but there is an undeniable bit of awkwardness compared to just imperatively poking things for small projects. That is one of the wins for Scheme -- I can make it super-easy to get easy things working, but it isn't just a "scripting language" unsuitable for large scale development. I am going to have to sort out my Racket / Chibi module strategy sometime soon, though.
> As far as language choice goes, I don't claim to have broadly evaluated every possibility and chosen the optimal one.
> Java or C# would have been more familiar to a broader base of game industry developers, but I really didn't want to drag in all the bulk of a JVM / .NET system, and a class focused world view seems less suited for the smaller scripting tasks.
> Javascript would have been more familiar to a broader base of web industry developers, but I have basically no experience with javascript, and little desire to explore it (which is admittedly a fault of mine).
> S-expression reading and writing is a strong factor for network communication, and I like the fact that there are available options for Scheme to interpret / compile / compile-to-C. I can see valid use cases for all of them, and I'm not sure how important each will be.
> The bottom line is that I have been enjoying myself working with Racket / Scheme this year, and I have evidence that it has been objectively productive for me, so I'm going out on a bit of a limb and placing a bet on it.
> >Initial impression: 7 years after starting to program in Racket, it still surprises me how easy it is to do something > >useful in just a few lines of code.
> A big goal here is to make the authored code very clear and simple. I may yet get to a single #lang vr <ip address> declaration that gets rid of the boilerplate at the top and bottom of the file and flips the right switches to make Racket closer to R7RS.
> There are sets of creative-types that are learning how to put things together in Unity to accomplish fairly simple media related tasks. I think I can make it easier for them with very domain specific helper libraries and a little bit of scheme.
> I have basically no experience with javascript
> The bottom line is that I have been enjoying myself working with Racket
So there is no logical reason behind, he just loves Racket, ok
>and I have evidence that it has been objectively productive for me
A large AAA studio I worked at actually rolled their own scripting language, compiler, and VM from scratch. I got to get my hands dirty with this. The only time since University I've had to utilise my compilers knowledge :)
Unity gives you the choice of C#, a JavaScript dialect, or a Python dialect.
Why not lisp? :D
It seems that in order to create an immersive world on the original playstation and keep up the speed of development, iteration and dynamism required for a game he wrote his own compiler (into assembly for the playstation one) for a lisp that he created called Game Oriented Object Lisp (GOOL)[1].
[0] http://all-things-andy-gavin.com/2011/02/02/making-crash-ban...
[1] http://all-things-andy-gavin.com/video-games/making-crash/
[2] http://all-things-andy-gavin.com/2011/03/12/making-crash-ban...
He is going to be forced to add javascript by whiners anyway, I am enjoying the pipe dream of keeping it away.
Well Javascript is Javascript because of some guy personal prefences at Netscape. The same is true for C# and Java in their respective companies, and they didn't start as popular languages either.
It is dynamically typed, but so is Scheme, so that's not a reason to choose Scheme over Lua.
It has the bestest JIT currently found in any dynamically typed language, and rivaling the best JITs of statically typed languages like Java.
What's your definition of a good language that accepts scheme but not Lua?
In JS, "3" + 4 is "34", in PHP, it's 7. PHP separates concatenation and addition, unlike JS.
Anyway, huh? Lua has automatic type conversion. That's usually considered weak typing.
I'm not familiar with a rigorous definition of weak typing - but my experience is that weak typing is usually reserved for languages like TCL, Snobol, and even Perl where there's no "type" of values to speak of - everything is equivalent and decoded according to context.
Aren't the best players in this field the JavaScript engines? Not because JS is the best language, but because Google, for example, hired people like Lars Bak to make them.
And if it comes to quality of programmers, LuaJIT has Mike Pall which is a bit of a legend for those who heard of him.
Good language is a meta language. There is MetaLua, of course, which qualifies it as a "good" language, but Scheme got more bells and whistles.
I'm working on building languages on top of Lua/Luajit, since Lua has a good tracing jit, there's no reason you can't write an expanded metalanguage on it that will preprocess a bit and give you a brand new language.
By the time I'm done it will have the power of scheme (including continuations, with some functions compiled internally to use continuation passing style, since Lua guarantees tail call elimination) and macros. The main difference should be that the base type will be arrays and tables not lists, but that could be an improvement. I'll probably tack on something like s-expressions too.
OTOH, the same is true for Scheme.
Also, just because something is the "industry standard" (of popularity), doesn't mean you should always follow.