6 ms·
> Because Crystal is compiled, it is impossible to have a true REPL Impossible, or just hard?
by asplake 8y ago
> Because Crystal is compiled, it is impossible to have a true REPL
Impossible, or just hard?
- giancarlostoro 8y agoYou'd need an interpreted runtime for the language for that to work. D has a 'scripting' runtime but I'm not sure if anyone's done a REPL or what the limitations would be.
- jsjolen 8y ago/smug-lisp-weenie-mode I didn't realise that SBCL is interpreted.
- DonaldFisk 8y agoI'm not sure how SBCL is implemented, but I've written my own Lisp. It's incrementally compiled to byte code - the compiler is called when defun or defmacro is evaluated - but the REPL still relies on the interpreter, the same interpreter which does everything until the compiler compiles itself during a clean build. So compiled code can have a REPL, but a REPL needs an interpreter as well.
- lispm 8y agoSBCL compiles always. Code from the REPL is also compiled. OTOH LispWorks uses an interpreter for the REPL interaction. Yes, an Interpreter offers some more interactive features - but usually lacks the compile-time warnings/errors.
- ModernMech 8y agoThe main difference between compiled and static languages is that compiled languages go through a phase of "checking your work", where it compares parts of your program to other parts before running it. For example, if you misspelled a name, the compiler will look everywhere in your program for that name before you run it, and tell you it can't find the name. That's why we like compiled languages. By contrast, dynamic language handle this by looking up the name right before the code in question is executed. If the name's not there at that time, an error is thrown. Now think about this in the context of a REPL, which again stands for Read, Evaluate, Print, Loop. If you write code and evaluate it right away, this whole business about checking your work won't work right. You would basically have to recompile your entire program on every REPL eval, which defeats the whole purpose of a REPL. There are lots of other tricks to getting this to work, as the article hints at, but they're all very unsatisfactory in delivering the freedom of a dynamic language.
- lispm 8y agoReally? SBCL: * (defun foo (a) (+ a 42)) FOO * (defun bar (b) (foo 10 20)) ; in: DEFUN BAR ; (FOO 10 20) ; ; caught STYLE-WARNING: ; The function was called with two arguments, but wants exactly one. ; (SB-INT:NAMED-LAMBDA BAR ; (B) ; (BLOCK BAR (FOO 10 20))) ; ; caught STYLE-WARNING: ; The variable B is defined but never used. ; ; compilation unit finished ; caught 2 STYLE-WARNING conditions BAR
- ModernMech 8y agoThat's not the point. You can run static languages in a REPL. Some easier than others. You've chosen a particularly easy static language to write REPLs for as a counterpoint. LISPs and other homoiconic languages are especially well suited for interpreters because they're especially well designed languages. Languages like C which require header files and a pre-processor are much harder to write REPLs for. You can try to do it and you can build a thing that works kind of like a REPL (look I type code and press enter and it evaluates, yay), but the experience always falls short of using a dynamic language in a REPL. It's just not even close, and that's just due to the simple fact you're trying to use something in a way it's not intended. Compiled languages simply are not designed with a tight development loop as a major design goal.
- lispm 8y agoSBCL is compiled, dynamic and supports REPL based programming.
- ModernMech 8y agoLike I said, Lisps are well suited for REPLs.
- sam0x17 8y agoThis explains it a lot better than I do in the article.
- chhs 8y agoI had a quick search, REPLs exist for C, C++, D, Go, and Rust (my shortlist of statically typed, compiled languages). I would question what is meant by a 'true REPL'. It's certainly seems possible to build a REPL of a statically typed compiled language.
- nonsince 8y agoI don't know about the others (reportedly Cling for C++ is good) but the Rust repl doesn't work properly and is basically just a frontend for incrementally writing a Rust file.
- steveklabnik 8y agoNot only that but it’s about a year out of date at this point. I’m hoping someone eventually makes a new one, possibly based on MIRI.
- sam0x17 8y agoThis is also the current state of the crystal repl shard
- amorphid 8y agoHaskell static, compiled, and has a REPL, yes? Is the Haskell REPL not useful?