hasu / emacs-ob-racket

Emacs Org-Mode Babel code block Racket support
https://tero.hasu.is/blog/2011-09-08-on-racket-support-in-emacs-org-mode.html
GNU General Public License v3.0
36 stars 12 forks source link

tangling should not wrap code #6

Open bremner opened 11 months ago

bremner commented 11 months ago

When using org for literate programming, when I tangle blocks, I don't expect them wrapped in

(let () (write ....)

for example

#+begin_src racket :lang plait :tangle test.rkt
'(1 2 3)
#+end_src

currently exports to

(write (let ()

'(1 2 3)))

I guess this has something to do with execution results, but tangling needs to be closer to "verbatim" to be useful for me.

ZelphirKaltstahl commented 11 months ago

Note, that there was a similar/equivalent problem in org babel Scheme before, that is now fixed:

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d97ba5ba5

I am guessing you are experiencing similar problems as I was, when I wanted to use source blocks in literate programming and relied on bindings being in scope, but they were not, due to being let-wrapped.

bremner commented 11 months ago

Zelphir Kaltstahl @.***> writes:

Note, that there was a similar/equivalent problem in org babel Scheme before, that is now fixed:

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d97ba5ba5

I am guessing you are experiencing similar problems as I was, when I wanted to use source blocks in literate programming and relied on bindings being in scope, but they were not, due to being let-wrapped.

That makes sense. Since I'm not using header arg variables, I could not see the purpose of the let. A similar fix should be possible here.

hasu commented 10 months ago

The purpose of the let wrapper is to turn the contents of the code block into single expression giving a value to be writen out as the result of the block. (And yes, additionally the let expression also creates a local definition context for any header arg variables to be defined.)

As that wrapper only gets inserted when the requested result type for the block is value, one option for the use case might be to simply change the result type to output for all racket blocks in a file to be tangled:

#+PROPERTY: header-args:racket :results output

Another alternative is to override the template used to construct the program (part) for a block so that no let wrapper is included:

#+PROPERTY: header-args:racket :program '(lines prologue define-vars :body epilogue)