After a bit of investigation, it seems that wallyqs implementation of ob-racket does not treat/manage :prologue arguments correctly, which is worrying because I would assume that the semantics for how prologue works should not be something that could be accidentally broken by ob-* implementations (but that is a separate issue). More relevant to this thread is that python the prologue works as others have reported, but if you include a noweb reference in the prologue it does not get expanded. It is quite possible that this should be considered a bug since it means that prologues are added only after the main block is expanded. This seems incorrect, and I suspect that it is another bug related to the one fixed in df5a83637518ad9aa586d49884a6271f11afc592 (discussion here https://orgmode.org/list/ca+g3_pni3umvbiwgbdkuc3c6vjt1t1j-rkh43lrqybr+4ns...@mail.gmail.com/). The fact that prologue is not expanded means that you can modify what code is run by putting it in a prologue and org mode will be none-the wiser. The sha1 changes if you set :cache yes, which means that something in the execution code is doing something different than in the block hashing code. Further investigation required.
* Use the code :PROPERTIES: :header-args:python: :prologue "<<python-helper>>" :END: #+name: python-helper #+begin_src python asdf = lambda : 'result' #+end_src #+begin_src python :noweb yes return asdf() #+end_src On Fri, Aug 7, 2020 at 9:20 PM Tom Gillespie <tgb...@gmail.com> wrote: > > Hah, this is what I get for not reading carefully enough. I wonder if > it is possible to stick <<racket-helper>> in the prologue and have it > expand. > > On Fri, Aug 7, 2020 at 9:18 PM Tom Gillespie <tgb...@gmail.com> wrote: > > > > I don't see a direct answer to the original question in the thread, so > > here is an example of how I do it taken from > > https://raw.githubusercontent.com/SciCrunch/sparc-curation/master/docs/developer-guide.org. > > You can ctrl-f for racket-graph-helper to see the relevant blocks. A > > reduced version is below. Recall that I use > > https://github.com/wallyqs/ob-racket. I use this pattern all over the > > place in my org blocks. Best, > > Tom > > > > * Use the code > > :cache yes" > > #+begin_src racket :lang racket/base :noweb yes > > <<racket-helper>> > > (helper-function "this should work") > > #+end_src > > > > #+RESULTS: > > : this should work hello world > > > > > > * Define the helpers > > #+name: racket-helper > > #+header: :prologue "#lang racket/base" > > #+begin_src racket :lang racket/base > > (define (helper-function arg) > > (string-append arg " hello world")) > > #+end_src