emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: org-babel guile source block bug in handling multiple values


From: Zelphir Kaltstahl
Subject: Re: org-babel guile source block bug in handling multiple values
Date: Tue, 7 Mar 2023 15:18:26 +0000

On 3/7/23 15:36, Ihor Radchenko wrote:
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> writes:

* Multiple values involving =:var= variables

#+begin_src scheme :eval query-export :results output replace drawer :var x=1 
:var y=2
(import (except (rnrs base) error vector-map)
          (only (guile)
                lambda*
                λ)
          ;; let-values
          (srfi srfi-11))

(let-values ([(a b) (values x y)])
    (simple-format #t "~a ~a\n" a b))
#+end_src

#+RESULTS:
:results:
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: a

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]>
:end:
I am not familiar with scheme, but AFAIK all ob-scheme does is wrapping
the code block into (let (...) ,@body) See `org-babel-expand-body:scheme'.

May the problem be with your let-values form?

The problem seems to be associated with returning multiple values, which `let-values` is designed to capture. The expression `(values ...)` returns 2 values and the `(let ([(a b) <multi-value-expression>]) <body>)` will capture those 2 values, binding them to `a` and `b`. The `(let-values ...)` then creates a value (or in other scenarios any number of values) in its `<body>` part as a result of the whole `let-values` expression. In my case the body performs a side-effect of printing something out, which is required to get something as an output of the source block.

If org merely wraps in a `let`, it should not notice any of the multiple values business, because that is something done internally in `let-values`.

I can run the code in geiser manually without error, but when I run it as a source block, I get the error as seen in the example org document of my original e-mail.

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]