From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YBYLC5IlEWFF4gAAgWs5BA (envelope-from ) for ; Mon, 09 Aug 2021 14:54:42 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id eEeyBpIlEWHfBQAAbx9fmQ (envelope-from ) for ; Mon, 09 Aug 2021 12:54:42 +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 55FCC1EBBE for ; Mon, 9 Aug 2021 14:54:41 +0200 (CEST) Received: from localhost ([::1]:35426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mD4ne-0003ia-F7 for larch@yhetil.org; Mon, 09 Aug 2021 08:54:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mD4lu-0002TV-Oj for emacs-orgmode@gnu.org; Mon, 09 Aug 2021 08:52:52 -0400 Received: from mout01.posteo.de ([185.67.36.65]:54081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mD4ls-0004mU-9I for emacs-orgmode@gnu.org; Mon, 09 Aug 2021 08:52:50 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id DCC2F24002A for ; Mon, 9 Aug 2021 14:52:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1628513562; bh=IB8W1AbGFJGLo4Wm5t8IFSj/N5b9W9n0VcYLQT+qj5o=; h=To:From:Subject:Date:From; b=VF44/2IKTKQtuK83nhGm3kyykuM1dd/6qEwW46cjJ/yz20loPc2R/x1AmYuvLPF0T 1A2X8sab6WC/zBV6kNJsEhZucju8mhbd2QvvKnMigRhg54kR/kqIs2ZMUedNuCGrI1 mlM8Kp2bsKDMKOqTIYv3wAIbpWtmmqYzy/F1DQIkbgRojpd9hThjtD/GzXhvBelZO9 G13aC23n/ZvBXm3jwQnnRgpDtt4HcOxEgiM8TSatOsfRQ+AEkMyu+etcusiERTw1lV sNUp5VIVDBpu2i0aBp11l2W+qNX2btXs4SZKN99iNJecNo3gkbS9iVMAVqnphFbGF9 zRuh5oAhm6STQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GjwwV3NStz9rxQ for ; Mon, 9 Aug 2021 14:52:42 +0200 (CEST) To: emacs-orgmode@gnu.org From: Zelphir Kaltstahl Subject: Library of Babel usage of other programming languages than elisp Message-ID: Date: Mon, 9 Aug 2021 12:52:41 +0000 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------44AC79703D94A7464CE20070" 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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=1628513681; 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=C2XQCh+iW/vtzrOxs8D280Woa4gskab73PNiw+WyCQY=; b=HU36BhUEAOpB+xBdE6OTkPG2QFm3gcfXICJ4oZgllA6bQ6QM/Khlr6URD/VYdj7j22v+uK NMM3ByKkn42jd+wo0ZuP0FH3jvJTjcLxjjHEF8qHiaNfYSYpw/4GLXLX/gIvoJGfwU4a+t r3wSjJWgnyocU82odRIzn4jy86JPEjjqN9TXC0kSh09I8DnrtIhmCCIi2UscDnt8o/Cli/ tcysL0GLKKzJeKL6u2CmmxtZaYtCyzZ4PWsO0CZLsgYT5LceezL6Bn7gvnaOjMWiCl/0Ix EK9YxUpR/G46v5RcexFfwm6d9btU2Je1MM3qfW7n3b7cQpieqYkWLptBmlZAMQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628513681; a=rsa-sha256; cv=none; b=IG39vRKz72Te5rl+1VG1tukE5xXtHMQskcaVd4epcE4UA1rQf5URQSNMPhXTqyngG6IIP/ Tv61Fryt1vykHT9VjoA44Z039T8xNF5jAjFtNHQ/PWRkCGeXCS/LGJca6agNJcMn1c/HTY OIYIFPtcgtyA91yCWbY3wXDSlioRvbc+EMDIfbMPuWmBr38NhlhuA0rgb02LULz+dQK6gI 1OfvULy05TxZ/hl8RMUG9FAdckBYZx/yirpdEZ7yexWaABQ33k/4WDhtcsu+sC5SowIES6 a95/+qbbMOLyiDgyg58+0elO6sJYgnYspLgfdJbZZxccdRL8Civi7BFOtVrNGg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.de header.s=2017 header.b="VF44/2IK"; 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: -3.11 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.de header.s=2017 header.b="VF44/2IK"; 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: 55FCC1EBBE X-Spam-Score: -3.11 X-Migadu-Scanner: scn1.migadu.com X-TUID: iYTF+KvzqWrj This is a multi-part message in MIME format. --------------44AC79703D94A7464CE20070 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hello Org-mode users! I have repeatedly tried to use another programming language than elisp for writing source blocks in org-mode, which I intended to use as functions inside org-mode spreadsheets. So far without success. Here is my latest attempt: ~~~~ START ~~~~ #+HEADER: :var dt1="uninitialized1" dt2="uninitialized2" #+name: org-lob-timediff #+begin_src scheme (import (ice-9 format) (srfi srfi-19)) (define org-timestamp->time-utc (λ (timestamp-string) (let ([parsed-date (string->date timestamp-string "[~Y-~m-~d ~a ~H:~M]")]) (date->time-utc parsed-date)))) (define duration->hours (λ (duration) ;; 1h = 60min = 3600s (/ (time-second duration) 3600))) (define org-lob-timediff (λ (org-dt1 org-dt2) ;; formatting float: ;; ~@width, decimals, scale, overflowchar, padchar ;; ~ placeholder is following ;; @ with sign if negative ;; width: minimum width ;; decimals: minimum number of digits after decimal point ;; scale: ??? ;; overflowchar: ??? ;; padchar: char to use for padding (format #f "~,2f" (number->string (exact->inexact (duration->hours (time-difference (org-timestamp->time-utc org-dt2) (org-timestamp->time-utc org-dt1)))))))) #+end_src #+CALL: org-lob-timediff(dt1="[2021-01-01 Fri 00:00]", dt2="[2021-01-01 Fri 01:45]") #+RESULTS: ~~~~ END ~~~~ This code works just fine in geiser using GNU Guile: ~~~~ START ~~~~ scheme@(guile-user)> (org-lob-timediff "[2021-01-01 Fri 00:00]" "[2021-01-01 Fri 01:45]") $4 = "1.75" ~~~~ END ~~~~ However, when I C-c C-c the `CALL` line to actually run the code using library of babel, as a precursor to using `org-sbe` inside a spreadsheet, it fails! I see the following in my *Messages* buffer: ~~~~ START ~~~~ executing Scheme code block... (dt1 '"[2021-01-01 Fri 00:00]") (dt2 '"[2021-01-01 Fri 01:45]") Starting Geiser REPL ... [3 times] Guile REPL up and running! Debug REPL. Enter ,q to quit, ,h for help. => ice-9/boot-9.scm:1685:16: In procedure raise-exception: Wrong type to apply: # Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> Error during redisplay: (jit-lock-function 315) signaled (wrong-type-argument markerp nil) Code block evaluation complete. ~~~~ END ~~~~ So something obviously is getting confused. `time-second` is not a syntax-transformer. It is a procedure: ~~~~ START ~~~~ scheme@(guile-user)> time-second $5 = # ~~~~ END ~~~~ Now I have many questions: + What am I doing wrong? How comes perfectly valid code does not work in LOB? + Can LOB even be used with other languages than Elisp? + Almost all examples I see online are elisp only. Perhaps I am trying to do something, that is impossible with current Org-mode and Library of Babel? Best regards, Zelphir -- repositories: https://notabug.org/ZelphirKaltstahl --------------44AC79703D94A7464CE20070 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hello Org-mode users!

I have repeatedly tried to use another programming language than elisp for writing source blocks in org-mode, which I intended to use as functions inside org-mode spreadsheets. So far without success.

Here is my latest attempt:

~~~~ START ~~~~
#+HEADER: :var dt1="uninitialized1" dt2="uninitialized2"
#+name: org-lob-timediff
#+begin_src scheme
(import
 (ice-9 format)
 (srfi srfi-19))


(define org-timestamp->time-utc
  (λ (timestamp-string)
    (let ([parsed-date (string->date timestamp-string "[~Y-~m-~d ~a ~H:~M]")])
          (date->time-utc parsed-date))))


(define duration->hours
  (λ (duration)
    ;; 1h = 60min = 3600s
    (/ (time-second duration) 3600)))


(define org-lob-timediff
  (λ (org-dt1 org-dt2)
    ;; formatting float:

    ;; ~@width, decimals, scale, overflowchar, padchar

    ;; ~ placeholder is following
    ;; @ with sign if negative
    ;; width: minimum width
    ;; decimals: minimum number of digits after decimal point
    ;; scale: ???
    ;; overflowchar: ???
    ;; padchar: char to use for padding

    (format #f
            "~,2f"
            (number->string
             (exact->inexact
              (duration->hours
               (time-difference (org-timestamp->time-utc org-dt2)
                                (org-timestamp->time-utc org-dt1))))))))
#+end_src

#+CALL: org-lob-timediff(dt1="[2021-01-01 Fri 00:00]", dt2="[2021-01-01 Fri 01:45]")

#+RESULTS:
~~~~  END  ~~~~

This code works just fine in geiser using GNU Guile:

~~~~ START ~~~~
scheme@(guile-user)> (org-lob-timediff "[2021-01-01 Fri 00:00]" "[2021-01-01 Fri 01:45]")
$4 = "1.75"
~~~~  END  ~~~~

However, when I C-c C-c the `CALL` line to actually run the code using library of babel, as a precursor to using `org-sbe` inside a spreadsheet, it fails! I see the following in my *Messages* buffer:

~~~~ START ~~~~
executing Scheme code block...

(dt1 '"[2021-01-01 Fri 00:00]")

(dt2 '"[2021-01-01 Fri 01:45]")

Starting Geiser REPL ... [3 times]
Guile REPL up and running!
Debug REPL. Enter ,q to quit, ,h for help.
=> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Wrong type to apply: #<syntax-transformer time-second>

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> 
Error during redisplay: (jit-lock-function 315) signaled (wrong-type-argument markerp nil)
Code block evaluation complete.
~~~~  END  ~~~~

So something obviously is getting confused. `time-second` is not a syntax-transformer. It is a procedure:

~~~~ START ~~~~
scheme@(guile-user)> time-second
$5 = #<procedure %time-second-procedure (s)>
~~~~  END  ~~~~

Now I have many questions:

+ What am I doing wrong? How comes perfectly valid code does not work in LOB?

+ Can LOB even be used with other languages than Elisp?

+ Almost all examples I see online are elisp only. Perhaps I am trying to do something, that is impossible with current Org-mode and Library of Babel?

Best regards,
Zelphir

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