From ... Path: supernews.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!195.54.122.107!newsfeed1.bredband.com!bredband!uio.no!Norway.EU.net!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: IF & AND redefined, why? Date: 18 Apr 2001 11:11:23 +0000 Organization: Naggum Software, Oslo, Norway Lines: 47 Message-ID: <3196581083601514@naggum.net> References: <3ADCC6AE.BFE927BF@asme.org> <3ADD1851.FDADF98D@worldnet.att.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: oslo-nntp.eunet.no 987592283 19303 195.0.192.66 (18 Apr 2001 11:11:23 GMT) X-Complaints-To: newsmaster@eunet.no NNTP-Posting-Date: 18 Apr 2001 11:11:23 GMT Mail-Copies-To: never User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Xref: supernews.google.com comp.lang.lisp:9387 * Ted Sandler > e.g. the following code has to compute the function "calculate-answer" > twice: > > (if (calculate-answer) > (format t "The answer is ~A" (calculate-answer)) > (format t "There is no answer")) > > The "myif" macro sought to avoid this by setting "it" to the result of > the conditional as in: > > (myif (calculate-answer) > (format t "The answer is ~A" it) > (format t "There is no answer")) Programmers with slightly more experience would probably write this: (format t "~:[There is no answer~;The answer is ~:*~A~]" (calculate-answer)) Similar options are frequently available. Incidentally, you could name your anaphoric variable $_ or whatever Perl uses for the last value computed, and avoid the problem that it might look as if it were a tasteful thing to do. "it" is not a reserved word, but it becomes one in myif and myand, and that's even worse than using a disgusting-looking Perlism. If you really, really want anaphoric if and and, at least allow the programmer to choose the variable name, as in (iflet ((with-it (calculate-answer)) (whatever with-it) (whatever-else))) Note: this is intentionally syntactically like a binding, so as not to confuse readers to believe that with-it is a function call. This also makes it possible to roll this into a normal if. (Provided precautions are taken against misinterpreting lamda forms, which are syntactically different from the binding form even in the one really pathological case.) And don't forget the functional style: ((lambda (x) (if x (whatever x) (whatever-else))) (calculate-answer)) #:Erik -- I found no peace in solitude. I found no chaos in catastrophe. -- :wumpscut: