On 3/9/23 14:11, Ihor Radchenko wrote:
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> writes:

OK, to wrap up (ha!), I want to ask:

(q1) What is a rationale, if any, behind the let-wrapping?
It makes sense in ob-emacs-lisp to not litter global Emacs state.
In other ob-* lisp backends, I am not sure.
I am CCing Daniel, the maintainer of ob-clojure (we have no active
maintainer for ob-scheme now). Maybe, Daniel has some useful insight.

(q2) Any chances of that changing to (define ...)?
This sounds reasonable.

(q3) How could I change my org-mode's code to not  let-wrap, and instead use 
(define ...)?
See `org-babel-expand-body:scheme'. You can re-define it for a quick
temporary fix.

Thanks for the hint!

Here is my fix for my init.el:

~~~~START~~~~
;; Redefine/override org-babel-expand-body:scheme to avoid
;; let-wrapping with :var header args in source blocks.

(defun xiaolong/org-babel-format-vars (vars)
  "Format :var header arguments given as VARS."
  (mapconcat (lambda (var)
               (format "(define %s %S)" (car var) (cdr var)))
             vars
             "\n"))

(eval-after-load "org"
  '(defun org-babel-expand-body:scheme (body params)
     "Expand BODY according to PARAMS, return the expanded body."
     (let ((vars (org-babel--get-vars params))
           (prepends (cdr (assq :prologue params)))
           (postpends (cdr (assq :epilogue params))))
       (concat (and prepends (concat prepends "\n"))
               (if (null vars)
                   body
                 (concat (xiaolong/org-babel-format-vars vars) body))
               (and postpends (concat "\n" postpends))))))
~~~~~END~~~~~

That was simpler than I expected and the first time I overrode anything of org-mode =)

Regards,
Zelphir

-- 
repositories: https://notabug.org/ZelphirKaltstahl