Ihor Radchenko <[email protected]> writes: > So, I am not sure about your docstring change.
Good point, Ihor. Please see the attached patch. WDYT? > Note that the docstring still talks about "list or tuple". > I am wondering how tuple look like in Scheme. There are no tuples in Scheme. Grep shows the same text in other Org Babel files, so most probably the text was copied without editing. I fixed this as well. Rudy
>From 6d598e9848183415d2897b9e28aa5a60b202bc27 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. Also improve the docstring. * 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 | 10 +++++----- testing/lisp/test-ob-scheme.el | 26 +++++++++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el index 084d7b75e..22dd7a8fd 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." + "Replacement for `()' and `null' in tabulated Scheme results." :group 'org-babel :version "26.1" :package-version '(Org . "9.1") @@ -229,11 +229,11 @@ (defun org-babel-scheme-execute-with-geiser (code output impl repl &optional hos result)) (defun org-babel-scheme--table-or-string (results) - "Convert RESULTS into an appropriate elisp value. -If the results look like a list or tuple, then convert them into an -Emacs-lisp table, otherwise return the results as a string." + "Convert RESULTS into an appropriate Elisp value. +If the results are in the form of a proper list, 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)
-- "The power of mathematics rests on its evasion of all unnecessary thought." --- Ernst Mach, 1838-1916 Rudolf Adamkovič <[email protected]> [he/him] http://adamkovic.org
