From ... From: Erik Naggum Subject: Re: Macros vs Functions and a question about check-type Date: 2000/06/28 Message-ID: <3171212063253918@naggum.no>#1/1 X-Deja-AN: 640123671 References: <877lb94t5w.fsf@q-software-solutions.com> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 962223400 7547 195.0.192.66 (28 Jun 2000 20:16:40 GMT) Organization: Naggum Software; vox: +47 8800 8879; fax: +47 8800 8601; http://www.naggum.no User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 Mime-Version: 1.0 NNTP-Posting-Date: 28 Jun 2000 20:16:40 GMT Newsgroups: comp.lang.lisp * Friedrich Dominicus | I'm trying getting a bit more familiar with Common Lisp and write some | small piecs of code. I come along with this ones: | | (defun with-cwd (dir thunk) | (let ((old-wd (pwd))) | (unwind-protect | (progn | (change-directory dir) | (funcall thunk)) | (change-directory old-wd)))) | | (defmacro with-cwd-m (dir thunk) | (let ((old-wd (gensym))) | `(let ((,old-wd (pwd))) | (declare (dynamic-extent ,old-wd)) | (unwind-protect | (progn | (change-directory ,dir) | (funcall ,thunk)) | (change-directory ,old-wd))))) | | comments are ommitted frankly here. I'll supply my own: This is Scheme in Common Lisp guise. Bad karma. In Common Lisp, one generally uses bodies in macros, not thunks. Thunks are very useful when you don't have macros in the first place. (defmacro with-cwd (dir &body body) (let ((old-wd (gensym))) `(let ((,old-wd (pwd))) (unwind-protect (progn (change-directory ,dir) ,@body) (change-directory ,old-wd))))) | - I found the line with (declare (dynamic-exte... in On Lisp page | 149, it seems to me that using it might be ok here too. But I'm not | sure, can someone explain why it might be good or if I better should | omitt it. I see no use for it, but that doesn't mean it won't help a compiler somewhere decide to do something useful with it. | Now a somewhat related question but a bit away. I want the first | parameter of the funtion/macro be a String and the second to be a | function with no parameter. I think you're getting a simpler, more readable, and better fulfillment of that desire by embedding a body in the macro expansion rather than calling a thunk. On a side-note: I dislike Scheme more every time somebody fails to understand that Scheme was designed to experiment with programming methodologies and even paradigms and copies some of its ways as if they were gospel. That _really_ bugs me, mostly because it is _so_ har do undo such concrete-bound learning -- people who apparently have no experience or training in getting the abstract picture get so _obsessive_ about particulars, and some of those particulars in Scheme are just not good ideas to take with you outside of Scheme. #:Erik -- If this is not what you expected, please alter your expectations.