[developers] dot.emacs redefinition of 'unless' and 'when'

Michael Wayne Goodman goodmami at uw.edu
Wed Dec 20 19:07:07 CET 2017


Thank you, Dan, for looking into this.

On Wed, Dec 20, 2017 at 2:04 AM, Dan Flickinger <danf at stanford.edu> wrote:

> HI Mike,
>
>
> I can't tell you why LOGON redefines those two macros, but note that you
> can see what the macro is doing by asking Emacs to evaluate for example the
> following:
>
> (macroexpand '(unless t t))
>
> which in the LOGON universe shows you
>
> (or t (progn t))
>
> which returns T, confirming that here you get the value of the first
> argument to `unless if it is non-nil, and the value of the final argument
> otherwise.
>
> In contrast, in unmodified Emacs, the macroexpand shows you
>
> (if t nil t)
>
> confirming that you get NIL if the first argument is non-nil, and the
> value of the final argument otherwise.
>

I also found out (sometime between my first and third email) that I could
C-x C-e to evaluate an expression in a buffer and get the result in the
status bar. I didn't know about macroexpand, but that helps me see what's
going wrong. Thanks!


> As for usage, I looked at the three files in the LOGON repository with
> suffix ".el", and reckon that the pg-interface.el file is not used by
> anyone but me (for the lexical database).  Of the other two, lkb.el only
> calls 'unless once, with no interest in the returned value, and tdl-mode.el
> makes just one call to `when, and it looks like it might matter what is
> returned (to set the value of 'indent-me).
>

There are also .el files under franz/, but maybe those aren't affected?

And in tdl-mode.el I think you're talking about this expression:

    (progn (forward-char 1)
       (when (and (eq (preceding-char) ?\[)
                  (not (tdl-comma-at-end-p indent-point)))
             (progn (skip-chars-forward " \t")
                    (re-search-forward "[ \t]" nil t)))
       (skip-chars-forward " \t")
       (current-column))

If the return value is meaningful, could that be rewritten as:

    (progn (forward-char 1)
       (let ((x (and (eq (preceding-char) ?\[)
             (not (tdl-comma-at-end-p indent-point)))))
         (if x (progn (skip-chars-forward " \t")
              (re-search-forward "[ \t]" nil t))
           x))
       (skip-chars-forward " \t")
       (current-column))

I used the (let ...) form to prevent writing the (and ...) form twice. I
don't know if this is idiomatic elisp or not.


> So my impression is that there is no need to preserve the LOGON
> redefinition of 'unless, and perhaps the effect of the redefined 'when
> could be managed differently in the one call in tdl-mode.el without
> redefining the macro.
>

The future is looking brighter.


>  Dan
>
>
>
>
>
>
> ------------------------------
> *From:* developers-bounces at emmtee.net <developers-bounces at emmtee.net> on
> behalf of Michael Wayne Goodman <goodmami at uw.edu>
> *Sent:* Tuesday, December 19, 2017 1:49 PM
> *To:* developers
> *Subject:* Re: [developers] dot.emacs redefinition of 'unless' and 'when'
>
> Sorry, one more change to my original mail. I mistakenly assumed that
> 'unless' was not returning the last value when the condition was false
> (based on some symptoms I was seeing), but I didn't explicitly test this,
> and my lisp is not good enough to deduce this by looking at the defmacro
> expression in ${LOGONROOT]/dot.emacs. In fact, it *does* appear to return
> the last value, but the difference from the default definition is that
> LOGON-unless returns the value of the condition when it's non-nil, rather
> than returning nil.
>
> ; standard unless
> (unless nil 1 2 3)  ; returns: 3
> (unless 'value 1 2 3)  ; returns: nil
>
> ; LOGON unless
> (unless nil 1 2 3)  ; returns: 3
> (unless 'value 1 2 3)  ; returns: value
>
> So when LOGON-unless is used in constructing a list, it will (I think)
> append the value of the condition to the list instead of nothing.
>
>
> On Tue, Dec 19, 2017 at 10:18 AM, Michael Wayne Goodman <goodmami at uw.edu>
> wrote:
>
> On Tue, Dec 19, 2017 at 8:12 AM, Michael Wayne Goodman <goodmami at uw.edu>
> wrote:
>
> Hi Developers,
>
> Does anyone know why ${LOGONROOT}/dot.emacs redefines the 'unless' and
> 'when' macros? It breaks some other Emacs packages I have that depend on
> the return value of the 'unless', which should be the value of the last
> argument. I'm aware that 'unless' and 'when' should be used when the return
> value is *not* important (according to https://www.emacswiki.org/emac
> s/WhenToUseIf), but do we have to enforce that suggestion by redefining
> the macros so they don't return the last value?
>
> Also see https://www.gnu.org/software/emacs/manual/html_node/elisp/Co
> nditionals.html, which says that 'unless' is equivalent to:
>
>     (if condition nil
>        a b c)
>
>
> Er... I meant that the guide says `(unless condition a b c)' is equivalent
> to the above, not in the general case. And I think the expected return
> value of the 'unless' expression would be c if condition returns nil.
>
>
> Thanks
>
> --
> Michael Wayne Goodman
> Ph.D. Candidate, UW Linguistics
>
>
>
>
> --
> Michael Wayne Goodman
> Ph.D. Candidate, UW Linguistics
>
>
>
>
> --
> Michael Wayne Goodman
> Ph.D. Candidate, UW Linguistics
>



-- 
Michael Wayne Goodman
Ph.D. Candidate, UW Linguistics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.delph-in.net/archives/developers/attachments/20171220/eae31ffd/attachment-0001.html>


More information about the developers mailing list