drym-org / symex.el

An intuitive way to edit Lisp symbolic expressions ("symexes") structurally in Emacs
Other
271 stars 22 forks source link

Side effect form #124

Closed countvajhula closed 1 year ago

countvajhula commented 1 year ago

Summary of Changes

Formerly, side effects could be specified as a mode of evaluation (via a side-effect argument to symex-execute-traversal). Instead, this PR adds them as just a distinct traversal type, just like maneuver or decision. This allows us to attach side effects to any traversal or even components of traversals without needing to treat them in a special way. This simplifies the evaluator and gives us more flexibility in general.

I believe this also increases the power of the DSL from regular (finite automaton) to context-free (pushdown automaton), since we can leverage bindings in the ELisp lexical scope to store and update a variable (e.g. to use it as a stack). This is a little bit cheating since the memory representation isn't internal to the Symex language but is part of the host language (i.e. a Lisp variable defined and mutated in ELisp), but it's seamless enough for our purposes.

I'm not a computer scientist so if anyone else happens to have more thoughts on this I would be curious to understand further. But for example, we can now count things like this:

(defun my-count-remaining-expressions ()
  (let ((my-count 1))
    (symex-execute-traversal
     (symex-traversal
       (circuit (effect (move forward)
                        (setq my-count (1+ my-count))))))
    my-count))

Technically, as the return value of a traversal is (by default) the list of moves executed, we could also have counted the number of expressions by inspecting this return value, but once again, that would be an operation done in Lisp rather than Symex. Come to think of it, we can also define other kinds of fold-like computations in the existing evaluator that might be able to count, I don't recall now how that works or if it still works.

Public Domain Dedication

(Why: The freely released, copyright-free work in this repository represents an investment in a better way of doing things called attribution-based economics. Attribution-based economics is based on the simple idea that we gain more by giving more, not by holding on to things that, truly, we could only create because we, in our turn, received from others. As it turns out, an economic system based on attribution -- where those who give more are more empowered -- is significantly more efficient than capitalism while also being stable and fair (unlike capitalism, on both counts), giving it transformative power to elevate the human condition and address the problems that face us today along with a host of others that have been intractable since the beginning. You can help make this a reality by releasing your work in the same way -- freely into the public domain in the simple hope of providing value. Learn more about attribution-based economics at drym.org, tell your friends, do your part.)