emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Raku evaluation for org-babel


From: Stefan Monnier
Subject: Re: Raku evaluation for org-babel
Date: Fri, 10 Apr 2020 16:34:31 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> I have spitballed together a module that adds Raku (formerly known as
> Perl 6) evaluation to Org-Babel.
> According to the org-babel docs I should contact this mailing list for
> help to get it ready for inclusion on elpa.

I'm not very familiar with Org-Babel, so I was wondering if it's best to
distribute such packages as standalone packages or include them in
Org-Babel, but if the org-babel doc pointed you here, I guess that's the
place they prefer, which is fine by me.

> This is my first module for Emacs, so I'm not familiar with proper
> process, I believe I have to add the .el file to this e-mail, so
> I shall do so.

Actually, if you have public Git branch somewhere, it's better, this way
we can preserve the (pre)history.

> If there is anything I have to do before I can proceed, I would be
> grateful for any advise offered.

See some comments below but the main issue is that it seems you haven't
signed the needed copyright paperwork yet.  I'll send you the forms
off-list for that.

> ;; Author: Tim Van den Langenbergh <address@hidden>
> ;; Keywords: literate programming, reproducible research
> ;; Homepage: https://github.com/tmtvl/ob-raku
> ;; Version: 0.05

This is equal to 0.5 (GNU ELPA's versions are lists of numbers and 05 is
the same number as 5).

It'd be good to add a `Package-Requires: ((emacs "NN"))` to clarify
with which versions of Emacs it's supposed to work.

> ;; News: 0.05 --- Added initial support for parentheses and commas in strings 
> in lists without breaking the lists on return.
> ;;       0.04 --- Added square brackets to list splitting, so as to split 
> embedded arrays as well as lists.
> ;;       0.03 --- Removed the double execution, simplified the formatting of 
> the Raku output, fixed hline support.
> ;;       0.02 --- Added support for tables, removed unneeded require 
> statements, error when trying to use a session.
> ;;       0.01 --- Initial release. Accept inputs, support for output and 
> value results.

We usually prefer to put the news in a separate ";;;; News" section.
Also we recommend to avoid using more than 80 columns.

> ;; You should have received a copy of the GNU General Public License
> ;; along with GNU Emacs; see the file COPYING.  If not, write to the
> ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
> ;; Boston, MA 02110-1301, USA.

This has been updated to:

    ;; You should have received a copy of the GNU General Public License
    ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

> (add-to-list 'org-babel-tangle-lang-exts '("raku" . "raku"))

IIUC this is the part that tells org-babel about the existence of support
for raku, but it's only executed if `ob-raku` is loaded.

It'd be nice to make it so that the user doesn't need to explicitly
require `ob-raku`, i.e. advertise the existence of raku support to
org-babel before the file is loaded.  For that you'll want to add
some ;;;###autoload cookies at a few appropriate places.

Sadly, the above `add-to-list` can't be autoloaded as-is since it will
will signal error if executed before `org-babel-tangle-lang-exts` is defined.
I don't know how it's supposed to be done for org-babel, so you may need
to ask the org-babel about that.

>     (mapconcat
>          (lambda (string)
>            (cond
>             ((string= string "\"")
>              (setq in-string (not in-string))
>              string)
>             ((and
>               in-string
>               (or
>                (string= string "(")
>                (string= string ")")
>                (string= string "[")
>                (string= string "]")
>                (string= string ",")))

Last few lines => (member string '("(" ")" "[" "]" ","))

>              (concat "\\" string))
>             (t string)))
>          (split-string list "" t)
>          "")))

Turning your string into a list of single-char strings is terribly
wasteful.  Every char in your original string will end up occupying
something like:
- 2 words for the cons cell.
- 4 words for the actual Lisp_String object.
- 2 words for the actual string bytes (1 word of header, 1 byte for the
  char, 1 terminating NUL byte, plus alignment padding).
So 8 words per char, which on a 64bit system means 64 bytes per char.

It also makes the subsequent tests more expensive since
`(string= string "(")` takes significantly more effort than (eq char ?\().

>   ;;(replace-regexp-in-string "\\\\\([][(),]\)" "\1" string) ;; This doesn't 
> work.
                                     ^^       ^^   ^^^
                                     \\(     \\)   "\\1"?

\( and \) in a string are not special, so they're treated just like
( and ) and the regexp engine never sees your backslash!

>           (and (stringp (car sanitized-table))
>                (string= (car sanitized-table) "HLINE"))

Aka (equal (car sanitized-table) "HLINE")


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]