From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: managing repetitive code in export & tangling Date: Tue, 8 Oct 2019 11:26:03 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ffd777059467c9b5" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:59381) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHrNS-0004qM-5y for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 11:26:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHrNQ-0006NA-VL for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 11:26:18 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:38976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHrNQ-0006Me-PX for emacs-orgmode@gnu.org; Tue, 08 Oct 2019 11:26:16 -0400 Received: by mail-pf1-x42b.google.com with SMTP id v4so10960441pff.6 for ; Tue, 08 Oct 2019 08:26:16 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --000000000000ffd777059467c9b5 Content-Type: text/plain; charset="UTF-8" In my lectures i often have simple examples that build progressively over several slides. In order to use klipse properly, but also for clarity, I gneerally repeat variable declarations from slide to slide, so for instance: ** Making Lists (Arrays) +#NAME: js-array-historians #+BEGIN_SRC js let historians= ["Edward Gibbon", "Leopold von Ranke", "Edward Said", "Joan Scott"]; #+END_SRC ** Repetition: While Loops #+NAME: js-while-hist #+begin_src js <> let i = 0; while (i < historians.length) { console.log(historians[i] + " was a historian."); i+=1; } #+end_src There might then be a sequence of another 5 or 6 slides in which the same "historians" array is bound to the same value and used as an example. This works fine on its own. However, I would also like to tangle all this code to a single file per lecture so students can download a git repo and play with it directly in a real text editor. Unfortunately, javascript will error out if a ~let~ bound variable is redeclared in the same scope. I'm wondering if there's any way to specify that a noweb reference only be included one time in a tangled file. Or if there are cleverer workarounds that folks can suggest! Thanks much, Matt --000000000000ffd777059467c9b5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
In my lectures i often have simple examples that buil= d progressively over several slides. In order to use klipse properly, but a= lso for clarity, I gneerally repeat variable declarations from slide to sli= de, so for instance:

** Making Lists (Arrays)=

+#NAME: js-array-historians
#+BEGIN_SRC js
= let historians=3D ["Edward Gibbon", "Leopold von Ranke"= , "Edward Said", "Joan Scott"];
#+END_SRC
=
** Repetition: While Loops
#+NAME: js-while-hist
#+be= gin_src js
<<js-array-historians>>
let i =3D 0;

wh= ile (i < historians.length) {
=C2=A0 =C2=A0 console.log(historians[i]= + " was a historian.");
=C2=A0 =C2=A0 i+=3D1;
=C2=A0 }
= #+end_src

There might then be a sequence of anothe= r 5 or 6 slides in which the same "historians" array is bound to = the same value and used as an example.

This wo= rks fine on its own. However, I would also like to tangle all this code to = a single file per lecture so students can download a git repo and play with= it directly in a real text editor. Unfortunately, javascript will error ou= t if a ~let~ bound variable is=C2=A0 redeclared in the same scope.=C2=A0 I&= #39;m wondering if there's any way to specify that a noweb reference on= ly be included one time in a tangled file. Or if there are cleverer workaro= unds that folks can suggest!=C2=A0=C2=A0

Thanks mu= ch,

Matt
--000000000000ffd777059467c9b5--