A Lisp implemented in AWK
# SPDX-License-Identifier: BSD-2-Clause

function _print_with_no_ors(x,      sors) {
    sors=ORS
    ORS=""
    print x
    ORS=sors
    fflush()
}

function _prompt() {
    _print_with_no_ors(PROMPT)
}

function rep(s,       form, result) {
    form = read_str(s)
    result = _eval(form)
    _print(result)
    if(N > (N_at_last_gc + GC_EVERY)) {
# for debugging garbage collector:
#        logg_dbg("rep", "auto-gc at N " N)
#        _dump_dot("pre-gc-" N ".dot")
#        _gc_dot(_cons(_GLOBALS,
#                      _cons(_MACROS,
#                            _cons(_COMPARED_SYMBOLS,
#                                  _nil()))),
#                "auto-gc-" N "-marks.dot",
#                "auto-gc-" N "-sweeps.dot")
#        _dump_dot("post-gc-" N ".dot")

        _gc(_cons(_GLOBALS,
                  _cons(_MACROS,
                        _cons(_COMPARED_SYMBOLS,
                              _nil()))))        
        N_at_last_gc = N
    }
}


BEGIN {
    if(PROMPT == 0) PROMPT = "user> "
    _prompt()
}

{ rep($0); _prompt() }