From 99a38e67a16c7541ce2d5da2d8d46e5914e559ae Mon Sep 17 00:00:00 2001 From: Zelphir Kaltstahl Date: Sat, 25 Mar 2023 15:21:38 +0100 Subject: [PATCH] org-babel-expand-body:scheme: define header arg vars using define * ob-scheme.el (org-babel-expand-body:scheme, org-babel-expand-header-arg-vars:scheme): Change the way header argument :var variables are expanded for for Scheme source blocks. Use `define' instead of wrapping using `let'. Wrapping binding definitions using `let' can lead to issues with GNU Guile and potentially other Scheme dialects. GNU Guile will only get to the body of the let at evaluation time, not at macro expansion time. If the let form wraps any imports of libraries that define macros, then those imported macros are seen too late and their corresponding forms inside the body of the let are not expanded. Using `define' to define bindings avoids this problem, at least in GNU Guile. For more context see the mailing list discussion at: https://lists.gnu.org/archive/html/emacs-orgmode/2023-03/msg00087.html --- lisp/ob-scheme.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el index 9f12f42cb..7424ab652 100644 --- a/lisp/ob-scheme.el +++ b/lisp/ob-scheme.el @@ -79,6 +79,14 @@ (defvar org-babel-default-header-args:scheme '() "Default header arguments for scheme code blocks.") +(defun org-babel-scheme-expand-header-arg-vars (vars) + "Expand :var header arguments given as VARS." + (mapconcat + (lambda (var) + (format "(define %S %S)" (car var) (cdr var))) + vars + "\n")) + (defun org-babel-expand-body:scheme (body params) "Expand BODY according to PARAMS, return the expanded body." (let ((vars (org-babel--get-vars params)) @@ -86,13 +94,7 @@ (postpends (cdr (assq :epilogue params)))) (concat (and prepends (concat prepends "\n")) (if (null vars) body - (format "(let (%s)\n%s\n)" - (mapconcat - (lambda (var) - (format "%S" (print `(,(car var) ',(cdr var))))) - vars - "\n ") - body)) + (concat (org-babel-scheme-expand-header-arg-vars vars) body)) (and postpends (concat "\n" postpends))))) -- 2.25.1