pmonks / for-science

A small Discord bot that you can send Clojure code to, to experiment with the language, demonstrate core language principles, or just mess about.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support code inside fences

pmonks opened this issue · comments

When a user triggers evaluation (i.e. via !clj) and they use a clojure code fence in the subsequent content, I want the bot to recognise the code fence and pull the content to be evaluated from within it, so that the code fence formatting itself does not interfere with the evaluation of the content.

Notes:

  • Un-code-fenced code should still be evaluated as it currently is today.
  • Should this support multiple independent code-fenced sections in a single message, or just the first one? If so, should those be considered independent evaluations, or a single evaluation (i.e. concatenate the content of all of the fences, prior to evaluation)? The latter may be useful if issue #7 isn't implemented, and will also allow "literate" style messages (interspersed code & explanatory text).

Regarding the second note, all code fences within a single message are evaluated sequentially within the same interpreter context. This means that any state built up in one code block will be available to all subsequent code blocks. e.g.

!clj Here we define a function:

(defn sq [x] (* x x))

And here we invoke the function on a range of values:

(map sq (range 10))