emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
To: Roland Coeurjoly <rolandcoeurjoly@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: Fwd: Support compilation of Haskell in org mode babel blocks.
Date: Tue, 5 May 2020 23:16:19 +0200	[thread overview]
Message-ID: <CAMdauZq_iNt5wL_eAD2p6keo6kHmXRY6LPCdTz2GHjsHvRAG4A@mail.gmail.com> (raw)
In-Reply-To: <87zhan1iby.fsf@nicolasgoaziou.fr>


[-- Attachment #1.1: Type: text/plain, Size: 433 bytes --]

Please see attached patch.
Regards.

On Mon, May 4, 2020 at 11:50 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > I am confused about the last point:
> > Use a let-binding instead of setq.
> >
> > If I use:
> >
> > (let* compile (string= (cdr (assq :compile params)) "yes"))
>
> I meant:
>
>   (let ((compile (string= "yes" (cdr (assq :compile params)))))
>    ...)
>

[-- Attachment #1.2: Type: text/html, Size: 891 bytes --]

[-- Attachment #2: 0001-ob-haskell-introduce-compile-header-argument.patch --]
[-- Type: text/x-patch, Size: 4179 bytes --]

From 2c05ba85bffac4019432fa461c0e4f75cd24a0f6 Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Date: Tue, 5 May 2020 23:09:58 +0200
Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument

* lisp/ob-haskell (org-babel-haskell-compiler):
(org-babel-header-args:haskell): new variables.
(org-babel-haskell-execute):
(org-babel-haskell-interpret): new functions.
(org-babel-execute:haskell): use new functions.
---
 lisp/org/ob-haskell.el | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el
index d32a2f7bc0..55989adba1 100644
--- a/lisp/org/ob-haskell.el
+++ b/lisp/org/ob-haskell.el
@@ -23,7 +23,7 @@
 
 ;;; Commentary:
 
-;; Org-Babel support for evaluating Haskell source code.
+;; Org Babel support for evaluating Haskell source code.
 ;; Haskell programs must be compiled before
 ;; they can be run, but haskell code can also be run through an
 ;; interactive interpreter.
@@ -62,19 +62,19 @@ org-babel-haskell-eoe
 
 (defvar haskell-prompt-regexp)
 
-(defcustom org-babel-Haskell-compiler "ghc"
+(defcustom org-babel-haskell-compiler "ghc"
   "Command used to compile a Haskell source code file into an executable.
-May be either a command in the path, like ghc
-or an absolute path name, like /usr/local/bin/ghc
-parameter may be used, like ghc -v"
+May be either a command in the path, like \"ghc\"
+or an absolute path name, like \"/usr/local/bin/ghc\".
+The command can include a parameter, such as \"ghc -v\""
   :group 'org-babel
-  :version "27.0"
+  :package-version '(Org "9.4")
   :type 'string)
 
-(defconst org-babel-header-args:haskell '((compile . :any))
+(defconst org-babel-header-args:haskell '(compile . :any)
   "Haskell-specific header arguments.")
 
-(defun org-babel-Haskell-execute (body params)
+(defun org-babel-haskell-execute (body params)
   "This function should only be called by `org-babel-execute:haskell'"
   (let* ((tmp-src-file (org-babel-temp-file
 			"Haskell-src-"
@@ -85,8 +85,10 @@ org-babel-Haskell-execute
          (cmdline (cdr (assq :cmdline params)))
          (cmdline (if cmdline (concat " " cmdline) ""))
          (flags (cdr (assq :flags params)))
-         (flags (mapconcat 'identity
-		           (if (listp flags) flags (list flags)) " "))
+         (flags (mapconcat #'identity
+		           (if (listp flags)
+                               flags
+                             (list flags)) " "))
          (libs (org-babel-read
 	        (or (cdr (assq :libs params))
 	            (org-entry-get nil "libs" t))
@@ -97,11 +99,12 @@ org-babel-Haskell-execute
     (with-temp-file tmp-src-file (insert body))
     (org-babel-eval
      (format "%s -o %s %s %s %s"
-             org-babel-Haskell-compiler
+             org-babel-haskell-compiler
 	     tmp-bin-file
 	     flags
 	     (org-babel-process-file-name tmp-src-file)
-	     libs) "")
+	     libs)
+     "")
     (let ((results
 	   (org-babel-eval
 	    (concat tmp-bin-file cmdline) "")))
@@ -116,10 +119,9 @@ org-babel-Haskell-execute
          (org-babel-pick-name
 	  (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
          (org-babel-pick-name
-	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))
-      )))
+	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
 
-(defun org-babel-interpret-Haskell (body params)
+(defun org-babel-interpret-haskell (body params)
   (require 'inf-haskell)
   (add-hook 'inferior-haskell-hook
             (lambda ()
@@ -157,10 +159,10 @@ org-babel-interpret-Haskell
 
 (defun org-babel-execute:haskell (body params)
   "Execute a block of Haskell code."
-  (setq compile (string= (cdr (assq :compile params)) "yes"))
+  (let ((compile (string= "yes" (cdr (assq :compile params)))))
   (if (not compile)
-      (org-babel-interpret-Haskell body params)
-    (org-babel-Haskell-execute body params)))
+      (org-babel-interpret-haskell body params)
+    (org-babel-haskell-execute body params))))
 
 (defun org-babel-haskell-initiate-session (&optional _session _params)
   "Initiate a haskell session.
-- 
2.20.1


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

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAMdauZqv91_bW2aZj=AT32vBdyPia92vjeVFMmsFazsEhJCTHg@mail.gmail.com>
2020-04-28 14:56 ` Fwd: Support compilation of Haskell in org mode babel blocks Roland Coeurjoly
2020-05-04 15:26   ` Nicolas Goaziou
2020-05-04 16:39     ` Roland Coeurjoly
2020-05-04 21:49       ` Nicolas Goaziou
2020-05-05 21:16         ` Roland Coeurjoly [this message]
2020-05-05 21:31           ` Nicolas Goaziou
2020-05-05 21:42             ` Roland Coeurjoly
2020-05-22  7:04             ` Roland Coeurjoly
2020-05-22 15:30               ` Nicolas Goaziou
2020-05-22 16:17                 ` Roland Coeurjoly
2020-05-23  5:12                   ` Kyle Meyer
2020-05-23 10:30                     ` Roland Coeurjoly
2020-05-23 14:02                       ` Bastien
2020-05-23 14:51                         ` Roland Coeurjoly
2020-05-23 15:21                           ` Bastien
2020-05-25  7:19                           ` Nicolas Goaziou
2020-05-04 15:29   ` Nicolas Goaziou
2020-05-04 15:42     ` Roland Coeurjoly
2020-05-04 21:52       ` Nicolas Goaziou
2020-05-05 21:23         ` Roland Coeurjoly

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=CAMdauZq_iNt5wL_eAD2p6keo6kHmXRY6LPCdTz2GHjsHvRAG4A@mail.gmail.com \
    --to=rolandcoeurjoly@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).