emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Daly <nick.m.daly@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] ob-haskell: Line Continuations Mangle Block Output
Date: Sun, 17 May 2020 15:07:27 -0500	[thread overview]
Message-ID: <CAM-YhhD09NR1qXntX4Jd8o=+eui+DXgPqu+Nh1t04sFD4iMJJQ@mail.gmail.com> (raw)
In-Reply-To: <CAM-YhhCxDAtD3=6VzK0ojYfF5=Zti8OS7LnUbResqC0uCtTZGg@mail.gmail.com>

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

Hi Org Maintainers,

Attached is an updated patch that makes output trimming work with
blocks that do and don't produce results.  The old patch creates a
=let: Wrong type argument: arrayp, nil= error when evaluating blocks
that don't produce output.  This necessarily incorporates yesterday's
patch.

Thanks for your time,
Nick


Multi-line function declarations with output still work fine.

#+BEGIN_SRC haskell
  :{
  chain :: (Integral a) => a -> [a]
  chain 1 = [1]
  chain n
      | even n = n:chain (n `div` 2)
      | odd n  = n:chain (n*3 + 1)
  :}
  chain 10
#+END_SRC

#+RESULTS:
| 10 | 5 | 16 | 8 | 4 | 2 | 1 |


Silent declaration-only blocks correctly evaluate silently.

#+BEGIN_SRC haskell :results silent
  :{
  flip' :: (a -> b -> c) -> (b -> a -> c)
  flip' f = \x y -> f y x
  :}
#+END_SRC


Single-line function calls also return the expected results.

#+name: flip'-hello
#+BEGIN_SRC haskell
  flip' zip [1,2,3,4,5,6] "hello"
#+END_SRC

#+RESULTS: flip'-hello
| h | 1 |
| e | 2 |
| l | 3 |
| l | 4 |
| o | 5 |

[-- Attachment #2: ob-haskell-trim-prelude-2.diff --]
[-- Type: text/x-patch, Size: 1031 bytes --]

diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index bea162528..cb581fe3b 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -83,12 +83,16 @@
 			  (cdr (member org-babel-haskell-eoe
                                        (reverse (mapcar #'org-trim raw)))))))
     (org-babel-reassemble-table
-     (let ((result
+     (let* ((result
             (pcase result-type
               (`output (mapconcat #'identity (reverse results) "\n"))
-              (`value (car results)))))
+              (`value (car results))))
+            (result
+             (if (stringp result)
+                 (replace-regexp-in-string "Prelude[|>] " "" result)
+               result)))
        (org-babel-result-cond (cdr (assq :result-params params))
-	 result (org-babel-script-escape result)))
+	 result (if (stringp result) (org-babel-script-escape result))))
      (org-babel-pick-name (cdr (assq :colname-names params))
 			  (cdr (assq :colname-names params)))
      (org-babel-pick-name (cdr (assq :rowname-names params))

  reply	other threads:[~2020-05-17 20:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 19:30 [PATCH] ob-haskell: Line Continuations Mangle Block Output Nick Daly
2020-05-17 20:07 ` Nick Daly [this message]
2020-05-20  5:51   ` Kyle Meyer
2020-05-24  0:02     ` Nick Daly
2020-05-24  2:46       ` Nick Daly
2020-05-26  0:05         ` Kyle Meyer
2020-05-31 17:00           ` Nick Daly
2020-05-26  0:02       ` Kyle Meyer

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='CAM-YhhD09NR1qXntX4Jd8o=+eui+DXgPqu+Nh1t04sFD4iMJJQ@mail.gmail.com' \
    --to=nick.m.daly@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).