Kamby – A programming language based on Lisp that doesn't seem like Lisp
I made a small evaluator in TXR Lisp for what appears to be my understanding &quot;Kamby-like&quot; semantics.<p><pre><code>  $ txr -i kamby.tl 
  Syntactic toffee recipe: melt butter over low heat, stir in Lisp macros.
  1&gt; (kamby-repl)
  kmb&gt; (let dz (&#x2F; 10 0))
  ** error: &#x2F;: division by zero
  kmb&gt; (let a 1)
  a
  kmb&gt; a
  1
  kmb&gt; (let foo [(let bar1 42) (let bar2 73)])
  foo
  kmb&gt; foo
  #&lt;kamby-env:(bar2 bar1)&gt;
  kmb&gt; foo.bar1
  42
  kmb&gt; foo.bar2
  73
  kmb&gt; (set a 4)
  4
  kmb&gt; a
  4
  kmb&gt; (set a (* 2 a))
  ** warning: unbound variable a
  ** error: unbound variable a
</code></pre>
Errors out at the end because unknown forms are evaled as Lisp, and Kamby variables are not Lisp variables.<p>Mostly this was to play with the &quot;construct environment tree as-you-go, with qualified pathname access&quot; idea.<p>Code:<p><pre><code>  (defstruct kamby-env ()
    bindings      ;; assoc list
    next-env      ;; kamby-env object or nil

    (:method extend (me sym value)
      (upd me.bindings (acons sym value)))

    (:method lookup (me sym)
      (assoc sym me.bindings))

    (:method delete (me sym)
      (let ((binding (assoc sym me.bindings)))
        (upd me.bindings (remq binding))))

    (:method print (me stream pretty-p)
      (format stream &quot;#&lt;~s:~s&gt;&quot; &#x27;kamby-env [mapcar car me.bindings])))

  (defvar *kamby-env* (new kamby-env))

  (defun kamby-error (form fmt . args)
    (error `~s: ~s: @fmt` &#x27;kamby-eval (if (atom form) form (car form)) . args))

  (defun kamby-eval (form)
    (let ((e *kamby-env*))
      (match-case form
        ((let @var @expr) e.(extend var (kamby-eval expr))
                          var)
        ((set @var @expr) (let ((binding e.(lookup var)))
                            (if binding
                              (rplacd binding (kamby-eval expr))
                              (kamby-error form &quot;no such variable: ~s&quot; var))
                            (cdr binding)))
        ((del @var) (unless e.(delete var)
                    (kamby-error form &quot;no such variable&quot;)))
        (@(symbolp @var) (let ((binding e.(lookup var)))
                            (if binding
                              (cdr binding)
                              (kamby-error form &quot;no such variable: ~s&quot; var))))
        ;; TXR Lisp qref syntax   a.b.c.d  &lt;--&gt; (qref a b c d)
        ((qref . @vars) (let (value)
                          (while vars
                            (let* ((var (pop vars))
                                   (binding e.(lookup var)))
                              (unless binding
                                (kamby-error form &quot;no such variable: ~s (when resolving ~s)&quot; var form))
                              (set value (cdr binding))
                              (if (and vars (not (typep value &#x27;kamby-env)))
                                (kamby-error form &quot;~s isn&#x27;t an environment object; cannot lookup ~s&quot;
                                             value (car vars)))
                              (set e value)))
                          value))
        ;; TXR Lisp dwim brackets syntax   [a b c]  &lt;--&gt; (dwim a b c)
        ((dwim . @forms) (let ((*kamby-env* (new kamby-env next-env e)))
                           [mapdo kamby-eval forms]
                           *kamby-env*))
        (@else (eval else)))))

  (defun kamby-repl ()
    (whilet ((line (progn (put-string &quot;kmb&gt; &quot;) (get-line))))
      (catch
        (prinl (kamby-eval (read line)))
        (error (x)
          (put-line `** error: @x`)))))</code></pre>