From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id mL5TLcMsTmDrTwAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 15:33:23 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id qI8mKcMsTmD5ZQAA1q6Kng (envelope-from ) for ; Sun, 14 Mar 2021 15:33:23 +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 aspmx1.migadu.com (Postfix) with ESMTPS id E9CA822147 for ; Sun, 14 Mar 2021 16:33:22 +0100 (CET) Received: from localhost ([::1]:48676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLSk5-0001jQ-SR for larch@yhetil.org; Sun, 14 Mar 2021 11:33:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLSjJ-0001jG-OG for emacs-orgmode@gnu.org; Sun, 14 Mar 2021 11:32:33 -0400 Received: from mout01.posteo.de ([185.67.36.65]:51452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLSjH-0005rl-1h for emacs-orgmode@gnu.org; Sun, 14 Mar 2021 11:32:33 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id DC57E160061 for ; Sun, 14 Mar 2021 16:32:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1615735948; bh=NEZMvJNQQI5/TUG+Jx3Js8gsu/POVEZPTvBdMFzrCZY=; h=Subject:From:To:Date:From; b=VwCmCUz03k0AtlL2pp3hZc95Zv+pUCx3Ds3PhTduMpv2quxFnZyF124LOoUKq2w5t UygfaMVXRfRpQZLTz9urlxbqgHJNwmPmGXW1trH474iLqLwDJwHpRRmcxv1JVpDQLj O/vYdA85BjnJ47J5X+15c9Rdpr4tpfqlXfCTNp0Gu3XBU1KJ5e0B/lJP6M0oI5nfAG V8XYmrACnmJYI1EVgJtkazdym6Hal6im0jvv6AFLwDMkoZ1SDbkf/DghWkzgwP9TQP 8hObeHHmZDpisOVEmzDWxfkAh1zlVWUXI/dpTWwrQCDbgvdStngoxjL/k1zdYfRvwB p9h21aVPMiSPQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Dz3T82BDZz9rxY for ; Sun, 14 Mar 2021 16:32:28 +0100 (CET) Subject: Re: org source block execute not working correctly with GNU Guile source block? From: Zelphir Kaltstahl To: emacs-orgmode@gnu.org References: Message-ID: <05d6b617-a5b7-f94b-be65-cf7912101334@posteo.de> Date: Sun, 14 Mar 2021 16:32:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------631CB62D8581923B6EC49B29" 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, NICE_REPLY_A=-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=1615736003; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=VBD78j1O1T5a2VwF7RkH97le4LFQpkXBoKg07/ovIMI=; b=Vj/wzBrG2geSG88imgJ3P8MN7BlZE3hUmVTRuhxFc72K9sm3DkwrFle8bR/MohhlSVvnJu 29uEAICz5i7z1f+6Eq3PJf0IBmV1t7RhfUXLaBQQgGHDm30hoT18nMweNADHBM/mcB+8VU DVpMBLUPqA3JV+uopFwf33ajYdTXWxi5UnKmB+GS0TBbxfL2pxTy1UjK17e0VdrgwfPtcx n1ILh2CLm+NiB0VxPczt6IxCVfUnM46LiwRmZ4jo9npYaaHsQjnzB4rZ562uzCl408lqn9 d1VI+vpx064V3OSbOKqRF8iOSfqPZ8zPQgMXDa0xmJkXoq3QD8xtup5594V6ZA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615736003; a=rsa-sha256; cv=none; b=N1vJkEdvJeUClM8h6wzpFQej7SAU4Sb96WdB7lW5JBW6WmXgLzTncrDOC31iHCukkwHvWH JLM050TtsetDqZW29P+F+I8LYax0bGDAJJmX1VXrvCDa79Rp3pYmWN8y0dZ3tc2ECDlu4E Lh+ghK1SoZYIEMr0Ttd99bPwmKSR00psFyBlmILPONgMJYSICTaxj0z8C1L5vEsflcS4h/ jQJgFlSIFZkq31djQOG6a5frDE5hWlpCgP4V4OXCdU2HEsU+l3pbDOgkSMkKVZyZIIqrxm eHqxPvWgXzJgIV1bAunF9qpf4setVs1dYWv6t/lzqCN1mGbq5JsTrc+wl3n4kA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.de header.s=2017 header.b=VwCmCUz0; dmarc=pass (policy=none) header.from=posteo.de; spf=pass (aspmx1.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: aspmx1.migadu.com; dkim=pass header.d=posteo.de header.s=2017 header.b=VwCmCUz0; dmarc=pass (policy=none) header.from=posteo.de; spf=pass (aspmx1.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: E9CA822147 X-Spam-Score: -2.10 X-Migadu-Scanner: scn0.migadu.com X-TUID: cmX7WeY7ZXr1 This is a multi-part message in MIME format. --------------631CB62D8581923B6EC49B29 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Ah, I am sorry, I forgot to include basic information: Emacs installed via GNU Guix: GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0) Org: org, 9.3, built-in On 3/14/21 4:28 PM, Zelphir Kaltstahl wrote: > > 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 -- repositories: https://notabug.org/ZelphirKaltstahl --------------631CB62D8581923B6EC49B29 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Ah, I am sorry, I forgot to include basic information:

Emacs installed via GNU Guix:

GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)

Org:

org, 9.3, built-in
On 3/14/21 4:28 PM, Zelphir Kaltstahl wrote:

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
-- 
repositories: https://notabug.org/ZelphirKaltstahl
--------------631CB62D8581923B6EC49B29--