From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id IFlaCcUrTmBDSQAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 15:29:09 +0000 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id MNn7BMUrTmDzBwAAbx9fmQ (envelope-from ) for ; Sun, 14 Mar 2021 15:29:09 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx2.migadu.com (Postfix) with ESMTPS id DFA1811ABC for ; Sun, 14 Mar 2021 16:29:07 +0100 (CET) Received: from localhost ([::1]:45878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLSfx-0000Ds-N1 for larch@yhetil.org; Sun, 14 Mar 2021 11:29:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLSfR-0000Dl-5K for emacs-orgmode@gnu.org; Sun, 14 Mar 2021 11:28:33 -0400 Received: from mout01.posteo.de ([185.67.36.65]:41212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLSfN-0003yy-QQ for emacs-orgmode@gnu.org; Sun, 14 Mar 2021 11:28:32 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 21FD1160062 for ; Sun, 14 Mar 2021 16:28:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1615735706; bh=xsNly2jUk+krrElC+FlH3isCicoG5GTw00IBmbLLqKk=; h=To:From:Subject:Date:From; b=dPFlf+3DZ3jnRDCJO7CNHMuUcckSfJQ4MJVAP0BPNBunT5CpYDXiyHyKjFIHMP8dj JAHEjGy/86orMNrC6jFxXh2mOQ8afeG7P1oNn+xTuNwxfVKpi8XsTjVRnjJBVsoaNp a+6655hwOXG++BbXaoMDxDw6QR3Z/oPmxGWsVo8WBuyyZRq/ETw7LKiiLbTFO7xeCD tNrts7hIcyl0E/YCTCKn246Xkr/ejwWRKEokSgkejK+exkJipdMPoOTlwifYcv/4Gn R2KG5693XHfcqS4uFO7zHo7VpQ7AZeQFStxE7kvZEXnHqFvc4Cljd6qm2pwtEjBXvD MqIbQFbpcO2wA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Dz3NT3CFXz9rxQ for ; Sun, 14 Mar 2021 16:28:25 +0100 (CET) To: emacs-orgmode@gnu.org From: Zelphir Kaltstahl Subject: org source block execute not working correctly with GNU Guile source block? Message-ID: Date: Sun, 14 Mar 2021 16:28:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------9E40797CCBA26FDDE7A91AC5" Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_SBL=1.623 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1615735748; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=o5UxDmePgvibPJ4V9YVCORZvFiOYSj3ruwXxGgrHsjs=; b=gEM/sN8hysjEYebLbso9etkMt0NVXrVRTX2N1TUNyUScXgofeX8ggLvrfyhN5L0LG/yVCW fMLQS7BUVWUq2WBqOOCnOy9y9sC9fYhoBs1eKJLX2JgLE9jo1jZ6QfK3tQzUr3zIqAvobH qoQsr2DTLfL/ajh8GAM7SaV+1bEGuRLwTqslQginXO0MlO3dpNsDxkGLZ5b7taoCFzP9P8 FD8/zYZU1wSen5DxeooTvcTQnHnCnjnwAKT15UthhmGmML9VjVqfxXj8qHfW90hn34lcK4 BuB1vCOvMTFhisnwnkTdsglnT5rvs8PZp5kXpfux0f1hvp5/J/2vvPexGgrXug== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615735748; a=rsa-sha256; cv=none; b=ln3rtbQsGv4dEAvS85tI+nlfQeUlx7QFbtThDBTRYNTw065ZsTDp18Bx6RwHZWq2SSbLD2 H96H1a1jvYBstSWFJNMod1SdbRw0hF3K5i0oCiH1nAsaLyjLuXx9GSGNl5pvDQK0hrCJXs YM6kmfJHtGHPog3pW+PxL+cJcKfacfTUNxReJBhguPqtguA2iIFGO6unH+whU0wewNmraI RGok2Pqgloz+q9ohV/hHtCTx9tYGOg+gZ6myr2YuFVNtY8w9E5KDIwKGgEAKcSMxMfieNW xqtCNmuLDbmxuVL88/XE7mVkJvdtsqcJYofv3eNgn543M3ZSuH3edV/mTEBL5A== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=pass header.d=posteo.de header.s=2017 header.b=dPFlf+3D; dmarc=pass (policy=none) header.from=posteo.de; spf=pass (aspmx2.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.10 Authentication-Results: aspmx2.migadu.com; dkim=pass header.d=posteo.de header.s=2017 header.b=dPFlf+3D; dmarc=pass (policy=none) header.from=posteo.de; spf=pass (aspmx2.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: DFA1811ABC X-Spam-Score: -2.10 X-Migadu-Scanner: scn0.migadu.com X-TUID: 4ZD3FSL1J1sK This is a multi-part message in MIME format. --------------9E40797CCBA26FDDE7A91AC5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hello! I have an org-mode spreadsheet, in which I calculate durations from timestamps like "[2021-03-14 Sun 03:50]" for example. Recently I saw, that using org-sbe (org source block execute) in combination with the :var header argument can be used to run arbitrary code for calculating values to put as result of spreadsheet formulas (on https://home.fnal.gov/~neilsen/notebook/orgExamples/org-examples.html ). So I went trying it out. The following is some GNU Guile code for calculating time differences in hours: ~~~~ #+NAME: allinone #+begin_src scheme :noweb yes :var org-timestamp-1="[2021-01-01 Fri 00:00]", org-timestamp-2="[2021-01-01 Fri 01:00]" :results output drawer replace :exports none (import (srfi srfi-19)) (define SECOND 1) (define MINUTE (* 60 SECOND)) (define HOUR (* 60 MINUTE)) (define org-timestamp-format "[~Y-~m-~d ~a ~H:~M]") (define duration->time-utc (λ (duration) (make-time time-utc (time-nanosecond duration) (time-second duration)))) (define org-timestamp->time-utc (λ (timestamp-string) (let ([parsed-date (string->date timestamp-string org-timestamp-format)]) (date->time-utc parsed-date)))) (define org-time-duration (λ (org-timestamp-1 org-timestamp-2) (time-difference (org-timestamp->time-utc org-timestamp-2) (org-timestamp->time-utc org-timestamp-1)))) (define duration->org-timestamp (λ (duration) (time-utc->date (duration->time-utc duration) ;; timezone offset, assume all with no offset 0))) (define duration->hours (λ (duration) (/ (time-second duration) HOUR))) (number->string (duration->hours (org-time-duration org-timestamp-1 org-timestamp-2))) #+end_src ~~~~ The source block is named "allinone", because I tried previously with :noweb yes and referencing other code blocks to be included, but thought that perhaps org-sbe does not deal well with :noweb yes, so I wanted to make sure to keep everything in one source block. The variables org-timestamp-1 and org-timestamp-2 are referenced at the bottom of the code. The code runs find in run-guile for example, when I replace the 2 variables with the default values of the variables, given in the header argument :var, as you can see in this transcript: ~~~~ GNU Guile 3.0.5 Copyright (C) 1995-2021 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guile-user)> (import (srfi srfi-19)) (define SECOND 1) (define MINUTE (* 60 SECOND)) (define HOUR (* 60 MINUTE)) (define org-timestamp-format "[~Y-~m-~d ~a ~H:~M]") (define duration->time-utc (λ (duration) (make-time time-utc (time-nanosecond duration) (time-second duration)))) (define org-timestamp->time-utc (λ (timestamp-string) (let ([parsed-date (string->date timestamp-string org-timestamp-format)]) (date->time-utc parsed-date)))) (define org-time-duration (λ (org-timestamp-1 org-timestamp-2) (time-difference (org-timestamp->time-utc org-timestamp-2) (org-timestamp->time-utc org-timestamp-1)))) (define duration->org-timestamp (λ (duration) (time-utc->date (duration->time-utc duration) ;; timezone offset, assume all with no offset 0))) (define duration->hours (λ (duration) (/ (time-second duration) HOUR))) scheme@(guile-user)> (define org-timestamp-1 "[2021-01-01 Fri 00:00]") scheme@(guile-user)> (define org-timestamp-2 "[2021-01-01 Fri 01:00]") scheme@(guile-user)> (number->string (duration->hours (org-time-duration org-timestamp-1 org-timestamp-2))) $2 = "1" scheme@(guile-user)> ~~~~ This code assumes, that I have to convert to a string at the end, to make a good return value for org-mode spreadsheets. Then I have this table in my document: ~~~~ | | timestamp 1 | timestamp 2 | result | |---+------------------------+------------------------+--------| | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:55] | | | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | nil | | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | | #+TBLFM: $4='(org-sbe "allinone" (org-timestamp-1 $2) (org-timestamp-2 $3)) ~~~~ The one nil is from one time, when I answered "no" to the question, whether I want to run the associated source block: ~~~~ Evaluate this emacs-lisp code block on your system? (yes or no) ~~~~ What is weird is, that it asks about an emacs-lisp code block, while my block is a scheme block, which is set to GNU Guile on my Emacs. When I answer "yes" instead, I get an error pasted into my table, destroying its structure: ~~~~ | | timestamp 1 | timestamp 2 | result | |---+------------------------+------------------------+---------------------------------------------------------| | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:55] | ice-9/boot-9.scm:1669:16: In procedure raise-exception: | In procedure open-input-string: Wrong type argument in position 1: (#{2021-03-14}# Sun #{03:55}#) Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> | | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | nil | | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | | #+TBLFM: $4='(org-sbe "allinone" (org-timestamp-1 $2) (org-timestamp-2 $3)) ~~~~ Knowing, that the code worked just fime in Geiser, I wonder what the problem is. I also only get that output, when I set the header arg :results of the source block to `output`. When I set :results to `value`, then I get simply no result at all. To check, whether the same version of GNU Guile is running in whatever org-sbe runs as is running in Geiser, I replace the whole source block code with the following: ~~~~ (version) ~~~~ And it fills in the following: ~~~~ | | timestamp 1 | timestamp 2 | result | |---+------------------------+------------------------+---------| | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:55] | "3.0.5" | | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | nil | | # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | | #+TBLFM: $4='(org-sbe "allinone" (org-timestamp-1 $2) (org-timestamp-2 $3)) ~~~~ I have put the minimal org file with my code on https://notabug.org/ZelphirKaltstahl/guile-examples/raw/488b4a73c3fc4c505a95c904402cbaeeeddd330c/time/minimal.org How can I get my time calculating code working? What am I doing wrong? Best regards, Zelphir -- repositories: https://notabug.org/ZelphirKaltstahl --------------9E40797CCBA26FDDE7A91AC5 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hello!

I have an org-mode spreadsheet, in which I calculate durations from timestamps like "[2021-03-14 Sun 03:50]" for example. Recently I saw, that using org-sbe (org source block execute) in combination with the :var header argument can be used to run arbitrary code for calculating values to put as result of spreadsheet formulas (on https://home.fnal.gov/~neilsen/notebook/orgExamples/org-examples.html). So I went trying it out. The following is some GNU Guile code for calculating time differences in hours:

~~~~
#+NAME: allinone
#+begin_src scheme :noweb yes :var org-timestamp-1="[2021-01-01 Fri 00:00]", org-timestamp-2="[2021-01-01 Fri 01:00]" :results output drawer replace :exports none
(import (srfi srfi-19))

(define SECOND 1)
(define MINUTE (* 60 SECOND))
(define HOUR (* 60 MINUTE))

(define org-timestamp-format "[~Y-~m-~d ~a ~H:~M]")

(define duration->time-utc
  (λ (duration)
    (make-time time-utc
               (time-nanosecond duration)
               (time-second duration))))

(define org-timestamp->time-utc
  (λ (timestamp-string)
    (let ([parsed-date (string->date timestamp-string org-timestamp-format)])
          (date->time-utc parsed-date))))

(define org-time-duration
  (λ (org-timestamp-1 org-timestamp-2)
    (time-difference (org-timestamp->time-utc org-timestamp-2)
                     (org-timestamp->time-utc org-timestamp-1))))

(define duration->org-timestamp
  (λ (duration)
    (time-utc->date
     (duration->time-utc duration)
     ;; timezone offset, assume all with no offset
     0)))

(define duration->hours
  (λ (duration)
    (/ (time-second duration) HOUR)))

(number->string
 (duration->hours
  (org-time-duration org-timestamp-1
                     org-timestamp-2)))
#+end_src
~~~~

The source block is named "allinone", because I tried previously with :noweb yes and referencing other code blocks to be included, but thought that perhaps org-sbe does not deal well with :noweb yes, so I wanted to make sure to keep everything in one source block.

The variables org-timestamp-1 and org-timestamp-2 are referenced at the bottom of the code.

The code runs find in run-guile for example, when I replace the 2 variables with the default values of the variables, given in the header argument :var, as you can see in this transcript:

~~~~
GNU Guile 3.0.5
Copyright (C) 1995-2021 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (import (srfi srfi-19))

(define SECOND 1)
(define MINUTE (* 60 SECOND))
(define HOUR (* 60 MINUTE))

(define org-timestamp-format "[~Y-~m-~d ~a ~H:~M]")

(define duration->time-utc
  (λ (duration)
    (make-time time-utc
               (time-nanosecond duration)
               (time-second duration))))

(define org-timestamp->time-utc
  (λ (timestamp-string)
    (let ([parsed-date (string->date timestamp-string org-timestamp-format)])
          (date->time-utc parsed-date))))

(define org-time-duration
  (λ (org-timestamp-1 org-timestamp-2)
    (time-difference (org-timestamp->time-utc org-timestamp-2)
                     (org-timestamp->time-utc org-timestamp-1))))

(define duration->org-timestamp
  (λ (duration)
    (time-utc->date
     (duration->time-utc duration)
     ;; timezone offset, assume all with no offset
     0)))

(define duration->hours
  (λ (duration)
    (/ (time-second duration) HOUR)))
scheme@(guile-user)> (define org-timestamp-1 "[2021-01-01 Fri 00:00]")
scheme@(guile-user)> (define org-timestamp-2 "[2021-01-01 Fri 01:00]")
scheme@(guile-user)> (number->string
 (duration->hours
  (org-time-duration org-timestamp-1
                     org-timestamp-2)))
$2 = "1"
scheme@(guile-user)>
~~~~

This code assumes, that I have to convert to a string at the end, to make a good return value for org-mode spreadsheets.

Then I have this table in my document:

~~~~
|   | timestamp 1            | timestamp 2            | result |
|---+------------------------+------------------------+--------|
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:55] |        |
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | nil    |
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] |        |
#+TBLFM: $4='(org-sbe "allinone" (org-timestamp-1 $2) (org-timestamp-2 $3))
~~~~

The one nil is from one time, when I answered "no" to the question, whether I want to run the associated source block:

~~~~
Evaluate this emacs-lisp code block on your system? (yes or no)
~~~~

What is weird is, that it asks about an emacs-lisp code block, while my block is a scheme block, which is set to GNU Guile on my Emacs.

When I answer "yes" instead, I get an error pasted into my table, destroying its structure:

~~~~
|   | timestamp 1            | timestamp 2            | result                                                  |
|---+------------------------+------------------------+---------------------------------------------------------|
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:55] | ice-9/boot-9.scm:1669:16: In procedure raise-exception: |
In procedure open-input-string: Wrong type argument in position 1: (#{2021-03-14}# Sun #{03:55}#)

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> |
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | nil    |
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] |        |
#+TBLFM: $4='(org-sbe "allinone" (org-timestamp-1 $2) (org-timestamp-2 $3))

~~~~

Knowing, that the code worked just fime in Geiser, I wonder what the problem is. I also only get that output, when I set the header arg :results of the source block to `output`. When I set :results to `value`, then I get simply no result at all.

To check, whether the same version of GNU Guile is running in whatever org-sbe runs as is running in Geiser, I replace the whole source block code with the following:

~~~~
(version)
~~~~

And it fills in the following:

~~~~
|   | timestamp 1            | timestamp 2            | result  |
|---+------------------------+------------------------+---------|
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:55] | "3.0.5" |
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] | nil     |
| # | [2021-03-14 Sun 03:50] | [2021-03-14 Sun 03:50] |         |
#+TBLFM: $4='(org-sbe "allinone" (org-timestamp-1 $2) (org-timestamp-2 $3))
~~~~

I have put the minimal org file with my code on https://notabug.org/ZelphirKaltstahl/guile-examples/raw/488b4a73c3fc4c505a95c904402cbaeeeddd330c/time/minimal.org

How can I get my time calculating code working?

What am I doing wrong?

Best regards,
Zelphir

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