emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)]
@ 2023-05-06  3:27 Ag Ibragimov
  2023-05-06  6:30 ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Ag Ibragimov @ 2023-05-06  3:27 UTC (permalink / raw)
  To: emacs-orgmode


Tangling Clojure code blocks appear to be broken.

Repro steps:

- Create a Clojure source block, e.g., 

#+begin_src clojure :tangle foo.clj
{:foo :bar}
#+end_src

- Tangle it, M-x org-babel-tangle

- Check the file content

Observed:

It's wrapping the content into
`(prn (binding [*out* (java.io.StringWriter.)]{:foo :bar}))`

Expected:

{:foo :bar}

------------------------------------------------------------------------



Emacs  : GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin22.4.0, NS appkit-2299.50 Version 13.3.1 (Build 22E261))
 of 2023-04-27
Package: Org mode version 9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)



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

* Re: [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)]
  2023-05-06  3:27 [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)] Ag Ibragimov
@ 2023-05-06  6:30 ` Ihor Radchenko
  2023-05-08  5:18   ` Ag Ibragimov
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2023-05-06  6:30 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-orgmode

Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> Repro steps:
> ...
> Observed:
>
> It's wrapping the content into
> `(prn (binding [*out* (java.io.StringWriter.)]{:foo :bar}))`
>
> Expected:
>
> {:foo :bar}

I see the expected result on my side.
May you follow the steps starting from emacs -Q or make repro?
See https://orgmode.org/manual/Feedback.html#Feedback

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)]
  2023-05-06  6:30 ` Ihor Radchenko
@ 2023-05-08  5:18   ` Ag Ibragimov
  2023-05-08  5:26     ` Ag
  2023-05-08  6:49     ` Ihor Radchenko
  0 siblings, 2 replies; 7+ messages in thread
From: Ag Ibragimov @ 2023-05-08  5:18 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> I see the expected result on my side.

I'm using the latest, org-version reports "Org mode version 9.7 (9.7-??-fdea200 ..."
This particular line here is causing the problem I described:

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ob-clojure.el#n191

```emacs-lisp
(if cljs-p
    "(binding [cljs.core/*print-fn* (constantly nil)]"
  "(binding [*out* (java.io.StringWriter.)]")         ;;; <----- this one
```


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

* Re: [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)]
  2023-05-08  5:18   ` Ag Ibragimov
@ 2023-05-08  5:26     ` Ag
  2023-05-08 10:05       ` Daniel Kraus
  2023-05-08  6:49     ` Ihor Radchenko
  1 sibling, 1 reply; 7+ messages in thread
From: Ag @ 2023-05-08  5:26 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Setting :results output header makes it work as expected. Without it -
it's as I described, wrapped.

On Mon, May 8, 2023 at 12:18 AM Ag Ibragimov <agzam.ibragimov@gmail.com> wrote:
>
> Ihor Radchenko <yantar92@posteo.net> writes:
>
> > I see the expected result on my side.
>
> I'm using the latest, org-version reports "Org mode version 9.7 (9.7-??-fdea200 ..."
> This particular line here is causing the problem I described:
>
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ob-clojure.el#n191
>
> ```emacs-lisp
> (if cljs-p
>     "(binding [cljs.core/*print-fn* (constantly nil)]"
>   "(binding [*out* (java.io.StringWriter.)]")         ;;; <----- this one
> ```
>


-- 
Regards,
Ag.


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

* Re: [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)]
  2023-05-08  5:18   ` Ag Ibragimov
  2023-05-08  5:26     ` Ag
@ 2023-05-08  6:49     ` Ihor Radchenko
  1 sibling, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2023-05-08  6:49 UTC (permalink / raw)
  To: Ag Ibragimov; +Cc: emacs-orgmode, Daniel Kraus

Ag Ibragimov <agzam.ibragimov@gmail.com> writes:

> I'm using the latest, org-version reports "Org mode version 9.7 (9.7-??-fdea200 ..."

Please detail the steps you tried. At least "version 9.7" does not look
right because the latest version is labeled "9.7-pre".

Also, provide the clojure backend you are using.

> This particular line here is causing the problem I described:
>
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ob-clojure.el#n191
>
> ```emacs-lisp
> (if cljs-p
>     "(binding [cljs.core/*print-fn* (constantly nil)]"
>   "(binding [*out* (java.io.StringWriter.)]")         ;;; <----- this one
> ```

Maybe, but please provide more data to reproduce the problem on our side.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)]
  2023-05-08  5:26     ` Ag
@ 2023-05-08 10:05       ` Daniel Kraus
  2023-05-08 15:21         ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Kraus @ 2023-05-08 10:05 UTC (permalink / raw)
  To: Ag; +Cc: Ihor Radchenko, emacs-orgmode

Hi!

Ag <agzam.ibragimov@gmail.com> writes:

> Setting :results output header makes it work as expected. Without it -
> it's as I described, wrapped.

I can reproduce the bug.

The problem is that or :results value (/the default) I only want the
result of the last expression and I do that `binding` of stdout to surpress
all other output.
But I guess during tangle this should just be ignored?
Is there a simple way to find out if `org-babel-execute:clojure` is
executed or tangled?

If it should be ignored on tangle, what about the :var defines.
We recently discussed this for ob-scheme where there was a problem with the
`let` wrapper.
Is it ok or expected that a the tangled code is wrapped in a let block?
Should I change it to a global `def`?

Thanks for the bug report.

PS, a minimal repo is

minimal-org-clj.el:
#+BEGIN_SRC emacs-lisp
;;; Minimal setup to load latest `org-mode'.

;; Activate debugging.
(setq debug-on-error t
      debug-on-signal nil
      debug-on-quit nil)

;; Add latest Org mode to load path.
(add-to-list 'load-path (expand-file-name "/home/daniel/.emacs.d/lib/org/lisp"))

(org-babel-do-load-languages
 'org-babel-load-languages
 '((clojure . t)))
#+END_SRC

/usr/bin/emacs -Q -l minimal-org-clj.el

And then tangle something like:

#+begin_src clojure :backend babashka :tangle foo.clj
{:foo :bar}
#+end_src

Cheers,
  Daniel


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

* Re: [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)]
  2023-05-08 10:05       ` Daniel Kraus
@ 2023-05-08 15:21         ` Ihor Radchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2023-05-08 15:21 UTC (permalink / raw)
  To: Daniel Kraus; +Cc: Ag, emacs-orgmode

Daniel Kraus <daniel@kraus.my> writes:

> The problem is that or :results value (/the default) I only want the
> result of the last expression and I do that `binding` of stdout to surpress
> all other output.
> But I guess during tangle this should just be ignored?
> Is there a simple way to find out if `org-babel-execute:clojure` is
> executed or tangled?

You can just move this extra logic arranging :results to
org-babel-execute:clojure.

> If it should be ignored on tangle, what about the :var defines.

:var defines are affecting how the code is written. :results should not.
So, :var is expected to affect tangling.
If necessary, code block expansion can be disabled via :no-expand header
argument:

       By default Org expands code blocks during tangling.  The ‘no-expand’
    header argument turns off such expansions.  Note that one side-effect of
    expansion by ‘org-babel-expand-src-block’ also assigns values (see *note
    Environment of a Code Block::) to variables.  Expansions also replace
    noweb references with their targets (see *note Noweb Reference
    Syntax::).  Some of these expansions may cause premature assignment,
    hence this option.  This option makes a difference only for tangling.
    It has no effect when exporting since code blocks for execution have to
    be expanded anyway.

> We recently discussed this for ob-scheme where there was a problem with the
> `let` wrapper.
> Is it ok or expected that a the tangled code is wrapped in a let block?
> Should I change it to a global `def`?

I think that keeping `let' should be fine as long as it does not break
things. In the previous discussion, the whole issue was that `let' was
not always safe in that particular lisp dialect.

We just need to make sure that it is documented.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2023-05-08 15:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-06  3:27 [BUG] Tangling of clojure code blocks is broken [9.7 (9.7-??-0807107 @ /Users/ag/.emacs.d/.local/straight/build-30.0.50/org/)] Ag Ibragimov
2023-05-06  6:30 ` Ihor Radchenko
2023-05-08  5:18   ` Ag Ibragimov
2023-05-08  5:26     ` Ag
2023-05-08 10:05       ` Daniel Kraus
2023-05-08 15:21         ` Ihor Radchenko
2023-05-08  6:49     ` Ihor Radchenko

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).