all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Library of Babel usage of other programming languages than elisp
@ 2021-08-09 12:52 Zelphir Kaltstahl
  2021-08-09 13:34 ` Eric S Fraga
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Zelphir Kaltstahl @ 2021-08-09 12:52 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3031 bytes --]

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


[-- Attachment #2: Type: text/html, Size: 3611 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-08-11 10:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-09 12:52 Library of Babel usage of other programming languages than elisp Zelphir Kaltstahl
2021-08-09 13:34 ` Eric S Fraga
2021-08-09 14:25   ` Zelphir Kaltstahl
2021-08-09 15:11     ` Eric S Fraga
2021-08-09 16:03       ` Zelphir Kaltstahl
2021-08-10 13:18         ` Eric S Fraga
2021-08-09 15:23 ` Greg Minshall
2021-08-09 16:27   ` Zelphir Kaltstahl
2021-08-09 18:36     ` Greg Minshall
2021-08-10  5:49 ` Dr. Arne Babenhauserheide
2021-08-11 10:01   ` Zelphir Kaltstahl

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.