From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id IJ++J33mTmfskwAAqHPOHw:P1 (envelope-from ) for ; Tue, 03 Dec 2024 11:07:41 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id IJ++J33mTmfskwAAqHPOHw (envelope-from ) for ; Tue, 03 Dec 2024 12:07:41 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rensoliemans.nl header.s=soverin header.b=CDVnk0Mh; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1733224061; a=rsa-sha256; cv=none; b=ll/JicRW8ZfDt1Wo2HUQIMg7VBjqZPrxIae7QEobLwZjCGGzYe5Ks/h7wx7tZD1F3bRCOf P0bNk+BhDcUeCiQhPECkCnFZi9nv085r43uXeSiMY2tBmjZHV0861ALRlOlsytUTlVrxIO xFNQtLXAXAFlhCy60FoReICTYV888JhyO9nEqOgK67AtS0V66PqgO4kPtmV8Ucmn8jLy37 18FPEJSPGkxrk0zJzk7rT76PvN+oNQjLMDmxLOZZYtK+5OW8hr8gBN9w439pUi4jhC5m0z 91IS4KXyQMKalJYrIDctlPBT0QyaVc3JxpjmbhKS9Hmk5y96BcadmwsmFPaT1A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rensoliemans.nl header.s=soverin header.b=CDVnk0Mh; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1733224061; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=sHrHcwA2bl/sxoxsiIKVJPaMxTQDO0mNiJ6xjvxl5hQ=; b=GF49D6k09Xfe4Is+4DBrOSAU5iAuR8cPCkbLUiMPuPE4E6nRqb8+EbuFXB7jpsrKXvfubw skDxZeTSs5L8OdhW53w9UBA2yhYZC56y7WSv+x8vQ9g9UuiUIDpdWeCPaqN8HwHqE+cw7+ ejillRafhTQoRJ+nrTPFxAaNs1MMjUoenuGEukx01+P62MTIHz/Pkyy/62JSKYvtKkAOKH YZ0/W6yFYfxGaddTj1jKb2Lk3t8h4U24CuZqsuYfSNWCNFJPW6r5OKVqRE7O+zDTctfMmx ClZY45v4d70AIAJA46aUYPeW11PabTovufsTSQFKMEoxZvkqmoLONrmQD83fBQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 73657189CE for ; Tue, 03 Dec 2024 12:07:41 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIQkA-00038K-4s; Tue, 03 Dec 2024 06:07:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIQk8-0002ve-1v for emacs-orgmode@gnu.org; Tue, 03 Dec 2024 06:07:00 -0500 Received: from outbound.soverin.net ([185.233.34.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIQk4-00064T-J0 for emacs-orgmode@gnu.org; Tue, 03 Dec 2024 06:06:59 -0500 Received: from smtp.soverin.net (c04cst-smtp-sov02.int.sover.in [10.10.4.100]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4Y2dBx4GFBz3X; Tue, 3 Dec 2024 11:06:49 +0000 (UTC) Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4Y2dBx0v0yzHv; Tue, 3 Dec 2024 11:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=rensoliemans.nl; s=soverin; t=1733224009; bh=UV5bz5msrr5Ru4zVx89dE9GEovwRdUXLUOPauITKHDA=; h=From:To:Cc:Subject:Date:From; b=CDVnk0MhRUde93pfK05iJwxPp9AiAVS5EunXDc3k9rlHsi+6a1uKkB01KJ6PNcUws JWPuUn6ZRzSSCJB7U/C5ffIrrBE/NZWIdYnCL83PUaRZXJXY22O6D1MEuh/yx/Mt8N t8u1wZr6ZiSScRPoIAOISFFczgaKVNzpjdgH+bt9As+Osyujy5lzVcwPouLsLE9TzH kBJq+K65/XtIathVXSaeHWals72WMupFwVuemf2UhFJaZEjxJdBkFDe42D2lKKIYit Nx4f3MWvHr2Xb6QzPZZYOh5fDrrChMf3r77lTMfiwRnfV9LVCakCxlxOX+XEoxJxkB eHb8Gj7nhPXjQ== From: Rens Oliemans To: "emacs-orgmode@gnu.org" Cc: Daniel Kraus Subject: [BUG] ob-clojure doesn't handle namespaces properly Date: Tue, 03 Dec 2024 12:07:23 +0100 Message-ID: <87mshdowic.fsf@rensoliemans.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spampanel-Class: ham Received-SPF: pass client-ip=185.233.34.18; envelope-from=hallo@rensoliemans.nl; helo=outbound.soverin.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -1.05 X-Spam-Score: -1.05 X-Migadu-Queue-Id: 73657189CE X-Migadu-Scanner: mx12.migadu.com X-TUID: dvWsPn0FzqDu --=-=-= Content-Type: text/plain Hi, There are two bugs introduced in commit 6efb073463481ee572eb3bb1155cc3b0d6987df6; I Cced Daniel, the commit author. It persists on main. Since the bugs are intimately related to ob-clojure and the org mode source blocks, I've just attached an org file that highlights the two bugs, I think that's easiest. I'm fairly sure that they have the same root cause: wrapping each block inside `(binding [*out (java.io.StringWriter.)])'. I'm not too familiar with (ob-)clojure, so I'm not sure what the best way to solve this would be, but I'm happy to try if necessary. Best, Rens --=-=-= Content-Type: text/org Content-Disposition: attachment; filename=bugs.org #+title: Clojure bugs I bisected this to [[https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6efb073463481ee572eb3bb1155cc3b0d6987df6][6efb073463481ee572eb3bb1155cc3b0d6987df6]]. I've only tested this on =cider=, I'm not sure if that makes a difference. * Bug 1: Different namespaces in the same document don't work well Say I have the following structure: ** Util :PROPERTIES: :header-args:clojure: :exports both :session *clojure-util* :END: It seems ~(ns example.util)~ isn't run properly: =sum= gets added to the default namespace the first time it's run. The second time it's run, it does work. In general, a block with a ~(ns)~ call needs to be run twice, it seems. To show this behaviour, I've added =:results value append= to the block below. #+begin_src clojure :results value append (ns example.util) (defn sum [vec] (reduce + vec)) #+end_src #+RESULTS: : Please reevaluate when nREPL is connected : #'user/sum : #'example.util/sum This has the result that if I execute the above block only once, other functions cannot use =util/sum=; see the code blocks below. If the REPL is restarted, it needs to be run twice again. To show that you need to run the above block twice, see the output of the block below. I executed it once after the /first/ time the previous was run (and =sum= was defined in the =user= namespace), and once after the /second/ time. #+begin_src clojure :results value append (sum (range 10)) #+end_src #+RESULTS: : class clojure.lang.Compiler$CompilerException : 45 ** Program :PROPERTIES: :header-args:clojure: :exports both :session *clojure-01* :END: This code block always errors: #+begin_src clojure (ns example.program (:require [example.util :as util])) (util/sum (range 10)) #+end_src #+RESULTS: : class clojure.lang.Compiler$CompilerException * Bug 2: When tangling, code blocks can't see previously defined vars :PROPERTIES: :header-args:clojure: :tangle tangled.clj :session *clojure-tangle* :results none :END: This does not occur with =:results output=, since in that case =ob-clojure= keeps the body unchanged. If we use the default, however, each code block is individually wrapped in a =prn= call, and all variables defined are limited to the scope of the org source block.. If we first define some function =sum=, #+begin_src clojure (ns example.tangle) (defn sum [xs] (reduce + xs)) #+end_src We cannot use it in later code blocks. Well, when executing this from Org mode or when exporting, things go well. However, when this file gets tangled (here to =tangled.clj=), the following line fails (/Unable to resolve symbol: sum in this context/). #+begin_src clojure (sum (range 10)) #+end_src #+RESULTS: : 45 #+begin_src sh :results output clj -M tangled.clj 2>&1 #+end_src #+RESULTS: : #'user/sum : Syntax error compiling at (tangled.clj:5:46). : Unable to resolve symbol: sum in this context : : Full report at: : /tmp/clojure-14548717163049100556.edn --=-=-=--