208 points · by texdraft · 4y ago · 52 comments
The fact that this was once the norm but has since been done away with saddens me. I've always been fascinated with "live environments" but felt they only went half way if they didn't include the source code itself. If I'm going to be updating something in a running system, I want to know what source code was used to get the system to the state its currently in, and preferably be able to query that source code as data. Of course, that code could be kept within source control, but then it's a shadow of the running system -- a map of the territory and not the territory.
As far as I know, the only languages/environments where this functionality is still available are Tcl, Smalltalk, and to some extent stored procedures within an RDBMS.
If the Forth compiler generates native code the one-to-one relationship with the source is lost and SEE will typically show the compiled code as Assembly Language.
And its easy to view the source code from the console (REPL). Some examples from Rebol2...
>> source func
func: func [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg words (and opt type and string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
>> source source
source: func [
"Prints the source code for a word."
'word [word!]
][
prin join word ": "
if not value? word [print "undefined" exit]
either any [native? get word op? get word action? get word] [
print ["native" mold third get word]
] [print mold get word]
]http://www.lispworks.com/documentation/lw80/lw/lw-dspecs-ug....
Common Lisp has standard function FUNCTION-LAMBDA-EXPRESSION:
* (defun foo (a)
(my-if (> a 10) 'big 'small))
FOO
* (function-lambda-expression #'foo)
(LAMBDA (A) (BLOCK FOO (MY-IF (> A 10) 'BIG 'SMALL)))
T
FOOI had no idea that this was in LISP 1.5. If you had asked me, I would have sworn it was Steele, 1977. Wikipedia supports that[1], albeit one might not consider it the most reliable source.
So apparently (partial) TCE has been around since at least 1961. In that light, it's baffling that it's not supported more universally.
[edit]
I should also point out that just storing the names of all of the symbols in the common lisp specification exceeds the RAM requirements of uLisp. Obviously builtins can go in ROM, but it gives you an idea of the sizes involved.
Building lists out of pairs and then using them as your intermediate format creates a lot of garbage.
I wonder if a Lisp-like language which used vectors rather than pairs as its fundamental data structure might be a better fit for severely memory-constrained systems? On average, vectors take up half the memory consumption of lists.
Such a language would end up looking rather different to Lisp though. Cons cells encourage CAR/CDR and recursion. A vector-centric language would naturally lead to a more iterative programming style.
Hint, they support them since Interlisp-C, ZetaLisp, Common Lisp,... so there is enough documentation and books where to educate yourself.
By today's standards, the RAM usage isn't necessarily huge.
Here is the TXR Lisp compiler recompiling stdlib/compiler.tl -> stdlib/compiler.tlo, as seen in top:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
11488 kaz 20 0 17800 14804 2964 R 98.1 0.7 0:07.07 txr
^^^^^ ^^^^^
On the order of a bash session. It's a lot of RAM by 1982 standards at the institution level, and even 1992 standards at the consumer level, but today it means nothing.You can easily see a Bash process a footprint on that order.
It could be reduced by tuning the garbage collector. One way to do that is to build for less memory use (useful for embedded). Here it is with txr rebuilt using #define CONFIG_SMALL_MEM 1 in config.h:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12838 kaz 20 0 11964 9768 3140 R 99.0 0.5 0:10.39 txr
Bash footprints for comparison: $ ps aux | head -1 ; ps aux | grep bash
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
kaz 1093 0.0 0.1 9288 2132 pts/2 Ss+ May15 0:01 -bash
kaz 2833 0.0 0.0 8904 1992 pts/0 Ss May15 0:00 -bash
kaz 3509 0.0 0.2 10532 4988 pts/1 Ss+ May15 0:28 -bash
kaz 7898 0.0 0.1 8968 2212 pts/3 Ss+ May20 0:00 -bash
Lists are used for everything: the compiler produces a list-based assembly code which is used from then through assembly. There is an optimizer which divides it into basic blocks, which are objects put into a graph, but the instructions still being lists. The peephole pattern matching is done on lists. The compiler does not bother using destructive append (nconc) for stitching together fragments of code; just straight garbage-generating appends. Same with most of the other rewriting that happens later.In a computer in 1960, your compiler would be capped to the physical memory available. That would be the RAM use. The garbage collector would have to be called whenever the memory is exhausted, or else the show would stop. A successful compilation would demonstrate that the compiler needed no more memory than what the machine has. The closer its actual usage would be to the available memory, the longer it would take, due to the frequent garbage collections required to stay afloat.
I'd say that given people's expectations today, shaped by experiences with everyday software, they likely greatly overestimate how much RAM you need for Lisp compiling.
It's Greenberg.