emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Greg Minshall <minshall@umich.edu>
Cc: Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: Library of Babel usage of other programming languages than elisp
Date: Mon,  9 Aug 2021 16:27:40 +0000	[thread overview]
Message-ID: <a9291139-f633-88bc-88ba-2eae544f6af2@posteo.de> (raw)
In-Reply-To: <547907.1628522603@apollo2.minshall.org>

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

Hi Greg!

On 8/9/21 5:23 PM, Greg Minshall wrote:
> Zelphir,
>
> actually...
>
> Everybody,
>
> i have an awkwardness about not being clear of the meaning of "Library
> of Babel".  my sense is it a collection of "subroutines".
>
> in my typical use of Org mode for programming, all my code blocks are
> defined in the same .org file, and executed in that file, or tangled to
> external files (normally, scripts).  i do use <<noweb>> to include bits
> from one part of the same file to the code in another part.  i don't
> know if this means i am using the Library of Babel or not.

I love noweb and literate programming facilities. Have done the same thing
multiple times, especially, when there was some code I want to learn about and
understand or simply explain to my future self. My best example is at:
https://notabug.org/ZelphirKaltstahl/the-little-schemer/src/master/chapter-09-y-combinator/code.org
<https://notabug.org/ZelphirKaltstahl/the-little-schemer/src/master/chapter-09-y-combinator/code.org>
Big fan of noweb : )

> then, on to...
>
> Zelphir,
>
> i also don't know what is going on.  but, installing geiser,
> geiser-guile, and running your code from the source block, looking at
> the output results, i get an error that might mean something to you?
> see below.  (notice i embedded your call to =org-lob-timediff= at the
> end of your source code.)
>
> in addition to with elisp, i use org src blocks with R, shell scripts,
> awk, etc.  but, never (till now!) with scheme.
>
> hth.  good luck.  i'll be curious what your next steps are.
>
> cheers, Greg
> ----
>
> #+HEADER: :var dt1="uninitialized1" dt2="uninitialized2"
> #+name: org-lob-timediff
> #+begin_src scheme :results output
>   (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))))))))
>   (org-lob-timediff "[2021-01-01 Fri 00:00]" "[2021-01-01 Fri 01:45]")
> #+end_src
>
> #+RESULTS: org-lob-timediff
> : ice-9/boot-9.scm:222:17: In procedure map1:
> : Syntax error:
> : unknown file:12:0: definition in expression context, where definitions are not allowed, in form (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))))
> : 
> : Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> : scheme@(guile-user) [1]> 

Hmmm this might be a GNU Guile version difference. I remember something about
definition context changing in something like Guile 3.0.3 or so, allowing
definitions in more places than before. For me this error does not happen, as I
use GNU Guile 3.0.7 currently:

~~~~ START ~~~~
scheme@(guile-user)> (version)
$6 = "3.0.7"
~~~~  END  ~~~~

Perhaps org-babel for Guile (I think ob-scheme? or ob-guile?) wraps everything
inside another (define ...) and that causes an error with the definition context.

What I did notice before is, that the set locale seems to matter for the short
names of weekdays and can lead to an error, but that was on another laptop and
not on this system:

~~~~ START ~~~~
executing Scheme code block (org-lob-timediff)...

(dt1 '"uninitialized1")

(dt2 '"uninitialized2")

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:
In procedure string->date: TIME-ERROR type bad-date-format-string: "[~Y-~m-~d ~a ~H:~M]"

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  ~~~~

But that is a Guile thing and nothing to do with LOB and easily fixed.

I began collecting small snippets and facts about whatever I learn about Emacs
in sone repository: https://notabug.org/ZelphirKaltstahl/emacs-usage-guide
<https://notabug.org/ZelphirKaltstahl/emacs-usage-guide>. Not much there yet,
but I will add a working example of LOB, if I can manage to get it working.
Perhaps I will also split that in a separate file.

I already got a small example working (not forgetting to run C-c C-v i or
`org-babel-lob-ingest` before C-c C-c on the CALL line):

~~~~ START ~~~~
#+HEADER: :var input-str="unspecified"
#+name: org-lob-upcase
#+begin_src scheme
(define upcase
  (λ (str)
    (string-upcase str)))

(upcase input-str)
#+end_src

#+CALL: org-lob-upcase(input-str="test")

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

So it does not seem to be completely impossible then. The whole
syntax-transformer instead of procedure error message thing makes me think, that
perhaps it is not using the correct version of Guile or something, so I did the
following experiment:

~~~~ START ~~~~
#+name: org-lob-guile-version
#+begin_src scheme
(version)
#+end_src

#+CALL: org-lob-guile-version()

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

Seems to work fine.

So I still have not understood, what the actual issue is with the timediff
function. Perhaps it is something about the imports.

Thanks for taking the time to try and reproduce the behavior!

Best regards,
Zelphir

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


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

  reply	other threads:[~2021-08-09 16:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 12:52 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 [this message]
2021-08-09 18:36     ` Greg Minshall
2021-08-10  5:49 ` Dr. Arne Babenhauserheide
2021-08-11 10:01   ` Zelphir Kaltstahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a9291139-f633-88bc-88ba-2eae544f6af2@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=minshall@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).