89 points · by lelf · 6y ago · 22 comments
And if their pseudo-REPL features aren't enough, there are a couple of C interpreters to choose from.
http://www.softintegration.com/
https://sourceware.org/gdb/current/onlinedocs/gdb/Expression...
It is not fully featured REPL, don't expect to use it to create stuff on the fly, it is more to query and call existing code.
For a proper REPL, check one of the listed interpreters.
https://www.reddit.com/r/lisp/comments/bgwtsh/fun_ecl_hack/
It can be as simple as:
(defun c-repl ()
(loop (fresh-line)
(princ "c99> ")
(let* ((form (read-line))
(func (eval `(let ((*compile-verbose* nil))
(compile nil (lambda () (ffi:c-inline nil nil :void ,form)))))))
(funcall func))))
> (c-repl)
c99> printf("HELLO world!\n");
HELLO world!
c99> { for(int i=0; i<4; i++) printf("*"); printf("\n"); }
****
(Though that doesn't expose all features of C. More work is required to turn it into complete REPL.)Fun thing is, you can just paste the above defun into your ECL REPL and execute it :).
Incidentally, the Swift REPL itself has another nasty misfeature: it always outputs the fully introspected debug representation of complex values, rather than calling `description`/`debugDescription` where available. Not really an issue when working with pointers, but for native structs and classes with complex internal state it can print screens and screens of unreadable noise, totally defeating the purpose. Conversely, the GUI-based “Swift Playgrounds” REPL prints line output right but lacks the CLI’s persistency so re-evaluates all lines every time a new line is entered, making it useless for stateful work.
TL;DR: Swift’s a hairy mess. [paraphrased jwz aphorism goes here]
And then the obvious thought occurs, a Lua editor/IDE environment built on top of that stack would be a very nice project. Basically, make everything Lua - the system services, etc.
One of these days I'll sit down and play with the idea of using only LOAD81 [1], for example, to build an operating environment with a fat library of functionality ..
They look perfectly fine to me. What did you find troubling?
>TL;DR: Swift’s a hairy mess. [paraphrased jwz aphorism goes here]
The only mess described thus far is in the REPL/Playgrounds for the language, which are not themselves "Swift".
If only C had those how safer it would be!
https://github.com/solidsnack/CLibPQ/blob/master/module.modu...
Once you've mapped in the library, trying it out interactively in Swift is easy and fun because of Swift's high-level features.
BUT, there is a gotcha: this “constantness” only applies to the name-value binding, not to the value itself. Thus you can still mutate the content of a let-bound value when that value is a class or class instance. Which kinda defeats the point of having the let/var distinction in the first place. C’s `const` may have its priorities backwards, but least it does what it says on the tin.
(And let’s not mention what a PITA Swift gets when you want to work with the contents of complex nested struct-based collections in a language that doesn’t have native pointers/references. Again, it makes C look good.)
As a programmer of any language, guessing at what something does, not verifying that the guess was right, and then complaining about it seems like a bad practice.