Ihor Radchenko <[email protected]> writes:

> (defcustom org-babel-scheme-null-to 'hline
>   "Replace `null' and empty lists in scheme tables with this before 
> returning."

This is no good either.  There are no "scheme tables" and there is no
`null' symbol in Scheme.  I added a fix into my patch:

  "Replace `()' in proper lists with this string before returning results."

> The docstring only talk about tables, which are always proper lists, so
> what I did is probably an overkill.

Overkill yes, but more importantly incorrect, as it messes up results
the way it should not.  I suggest we revert your patch and apply the one
attached to this message.

Rudy
>From fe5f9d42a5d24cac0a65de0f7ee297de723dc9ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <[email protected]>
Date: Sun, 16 Nov 2025 19:40:06 +0100
Subject: [PATCH] ob-scheme: Fix errors when the result is a cons cell

* lisp/ob-scheme.el (org-babel-scheme-null-to): Improve docstring.
(org-babel-scheme--table-or-string): Fix Org Babel
crashing with 'Wrong type argument: listp, 2' when the result is a
cons cell.
* testing/lisp/test-ob-scheme.el (test-ob-scheme/list): Rename the
test to `test-ob-scheme/proper-list' in order to differentiate proper
lists from cons cells.  Also re-indent.
(test-ob-scheme/cons-cell): Add a test to avoid future regressions.
(test-ob-scheme/proper-list): The renamed test.

Reported-by: "tusharhero" <[email protected]>
Link: https://list.orgmode.org/[email protected]
---
 lisp/ob-scheme.el              |  4 ++--
 testing/lisp/test-ob-scheme.el | 26 +++++++++++++++++++-------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index 084d7b75e..c7e1f1f8a 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -69,7 +69,7 @@ (declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
 (declare-function geiser-eval--error-msg "ext:geiser-eval" (err))
 
 (defcustom org-babel-scheme-null-to 'hline
-  "Replace `null' and empty lists in scheme tables with this before returning."
+  "Replace `()' in proper lists with this string before returning results."
   :group 'org-babel
   :version "26.1"
   :package-version '(Org . "9.1")
@@ -233,7 +233,7 @@ (defun org-babel-scheme--table-or-string (results)
 If the results look like a list or tuple, then convert them into an
 Emacs-lisp table, otherwise return the results as a string."
   (let ((res (and results (org-babel-script-escape results))))
-    (cond ((listp res)
+    (cond ((proper-list-p res)
            (mapcar (lambda (el)
 		     (if (or (null el) (eq el 'null))
 			 org-babel-scheme-null-to
diff --git a/testing/lisp/test-ob-scheme.el b/testing/lisp/test-ob-scheme.el
index 0fb79ad53..c4f1065c4 100644
--- a/testing/lisp/test-ob-scheme.el
+++ b/testing/lisp/test-ob-scheme.el
@@ -54,15 +54,27 @@ (ert-deftest test-ob-scheme/verbatim ()
 	    (buffer-substring-no-properties (line-beginning-position 2)
 					    (point-max))))))
 
-(ert-deftest test-ob-scheme/list ()
-  "Test list output."
+(ert-deftest test-ob-scheme/cons-cell ()
+  "Test cons cell output."
+  (should
+   (equal ": (1 . 2)\n"
+	  (org-test-with-temp-text
+           "#+begin_src scheme\n(cons 1 2)\n#+end_src"
+	   (org-babel-execute-maybe)
+	   (let ((case-fold-search t)) (search-forward "#+results"))
+	   (buffer-substring-no-properties (line-beginning-position 2)
+					   (point-max))))))
+
+(ert-deftest test-ob-scheme/proper-list ()
+  "Test proper list output."
   (should
    (equal "- 1\n- 2\n- 3\n"
-	  (org-test-with-temp-text "#+begin_src scheme :results list\n'(1 2 3)\n#+end_src"
-	    (org-babel-execute-maybe)
-	    (let ((case-fold-search t)) (search-forward "#+results"))
-	    (buffer-substring-no-properties (line-beginning-position 2)
-					    (point-max))))))
+	  (org-test-with-temp-text
+           "#+begin_src scheme :results list\n'(1 2 3)\n#+end_src"
+	   (org-babel-execute-maybe)
+	   (let ((case-fold-search t)) (search-forward "#+results"))
+	   (buffer-substring-no-properties (line-beginning-position 2)
+					   (point-max))))))
 
 (ert-deftest test-ob-scheme/prologue ()
   "Test :prologue parameter."
-- 
2.39.5 (Apple Git-154)

-- 
"'Obvious' is all too often a synonym for 'wrong'."

--- Jeff Erickson, Algorithms, 2019

Rudolf Adamkovič <[email protected]> [he/him]
http://adamkovic.org

Reply via email to