From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: lisp: scoping vars in repetitive defuns Date: Tue, 17 Sep 2019 07:30:40 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000083fc270592be0d7b" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:55876) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iABh9-0003rD-Dz for emacs-orgmode@gnu.org; Tue, 17 Sep 2019 07:30:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iABh8-0000dR-6o for emacs-orgmode@gnu.org; Tue, 17 Sep 2019 07:30:55 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:43335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iABh7-0000cp-WE for emacs-orgmode@gnu.org; Tue, 17 Sep 2019 07:30:54 -0400 Received: by mail-pl1-x635.google.com with SMTP id 4so1383609pld.10 for ; Tue, 17 Sep 2019 04:30:53 -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 --00000000000083fc270592be0d7b Content-Type: text/plain; charset="UTF-8" I have a number of convenience functions define to help me with grading assignments. As I go through the semester, i update all of these functions modestly so that they'rehelpful for grading the current assignment. I big chunk of these simple functions is taken up just declaring variables with (let (())) forms. Each function uses some ofhte same variables, e.g: (defun dh-find-files () (interactive) (let* ((base (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY")) (gh (org-entry-get (point) "GITHUB")) (f2o `( ,(concat "Reflection/" gh ".md") ,(concat "students/" gh ".json")))) ;;;; "01/index.html" "02/index.html" "03/style.css" "04/style.css" (message "%s" f2o) ;; make more flexible for resubmits (shell-command (concat "cd " base " && git checkout " gh "-master")) (dolist (x f2o) (if (file-exists-p (concat base "/" x)) (find-file-other-window (concat base "/" x) ) (message "File %s does not exist, not opening." x))))) (defun dh-tests () (interactive) (let* ((base (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY" )) (gh (org-entry-get (point) "GITHUB"))) (with-temp-buffer (shell-command (concat "cd " base " && npm test") t)) ;; the "t" lets us suppress buffer (browse-url-of-file (concat base "/TestResults/testresults.html")) ;; (dh-mocha-run) )) ---------- This semester I changed some elements of my workflow and I had to update all the (org-entry-get) calls to new values. It makes me think the code is less maintainable than it could be. I would like to do something like this: (lexical-let ((base `(org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY") (gh `(org-entry-get (point) "GITHUB")) ) (defun dh-find-files () (with-temp-buffer (shell-command (concat "cd " base " && npm test") t)) ;; the "t" lets us suppress buffer (browse-url-of-file (concat base "/TestResults/testresults.html"))))) Obviously it doesn't work this way. But is there any way to set macros like this to be expanded later inside a function definition? I feel certain there must be... Thanks, Matt --00000000000083fc270592be0d7b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I have a number of convenience functions define to he= lp me with grading assignments. As I go through the semester, i update all = of these functions modestly so that they'rehelpful for grading the curr= ent assignment.=C2=A0

I big chunk of these si= mple functions is taken up just declaring variables with (let (())) forms.= =C2=A0 Each function uses some ofhte same variables, e.g:

(defun dh-find-files ()
=C2=A0 (interactive)
=C2=A0 (let* ((b= ase (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY"))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(gh (org-entry-get (point) "GITHUB&q= uot;))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (f2o `( ,(concat "Reflection/&qu= ot; gh ".md") ,(concat "students/" gh ".json"= )))) ;;;; "01/index.html" "02/index.html" "03/styl= e.css" "04/style.css"
=C2=A0 =C2=A0 (message "%s&quo= t; f2o)
=C2=A0 =C2=A0 ;; make more flexible for resubmits
=C2=A0 =C2= =A0 (shell-command (concat "cd " base " && git check= out " gh "-master"))
=C2=A0 =C2=A0 (dolist (x f2o)
=C2= =A0 =C2=A0 =C2=A0 (if (file-exists-p (concat base "/" x))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (find-file-other-window (concat base "= /" x) )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (message "File %s does not= exist, not opening." x)))))

(defun dh-te= sts ()
=C2=A0 (interactive)
=C2=A0 (let* ((base (org-entry-get (point= ) "ORG_LMS_ASSIGNMENT_DIRECTORY" ))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(gh (org-entry-get (point) "GITHUB")))
=C2=A0 =C2=A0= (with-temp-buffer (shell-command (concat "cd " base " &= & npm test") t)) ;; the "t" lets us suppress buffer
= =C2=A0 =C2=A0 (browse-url-of-file (concat base "/TestResults/testresul= ts.html"))
=C2=A0 =C2=A0 ;; (dh-mocha-run)
=C2=A0 =C2=A0
=C2= =A0 =C2=A0 ))

----------

This semester I ch= anged some elements of my workflow and I had to update all the (org-entry-g= et) calls to new values.=C2=A0 It makes me think the code is less maintaina= ble than it could be.=C2=A0 I would like to do something like this:

(lexical-let ((base `(org-entry-get (point) "ORG_LMS= _ASSIGNMENT_DIRECTORY")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (g= h `(org-entry-get (point) "GITHUB")) )
=C2=A0=C2=A0=C2= =A0 (defun dh-find-files ()
(with-temp-buffer (shell-command (con= cat "cd " base " && npm test") t)) ;; the "= ;t" lets us suppress buffer
=C2=A0 =C2=A0 (browse-url-of-file (conc= at base "/TestResults/testresults.html")))))

=

Obviously it doesn't work this way. But is there an= y way to set macros like this to be expanded later inside a function defini= tion? I feel certain there must be...

Thanks,

Matt
--00000000000083fc270592be0d7b--