[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: empty-line-p
From: |
Stefan Monnier |
Subject: |
Re: empty-line-p |
Date: |
Sun, 01 Apr 2007 16:54:49 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.96 (gnu/linux) |
>> > (if (looking-at "^[ \t\f\r]*$")
>> > t
>> > nil)))
>>
>> (if <foo> t nil)
>>
>> is an eta-regexp, which can be advantageously reduced to just <foo>.
>>
>>
>> Stefan
>>
>>
>> PS: The classical eta-regexp is (lambda (x) (<foo> x)), which is equivalent
>> to
>> just <foo>. Another variant is (cons (car <foo>) (cdr <foo>)), which
>> eta-reduces to just <foo>.
> That last one is different, because the new cons is not eq to the
> original <foo>.
Indeed, the eta rules are generally not supported 100% by most languages:
there are always some "minor" semantic differences. Aside from the problem
you mentioned for the `cons' case, the `if' case changes the result when the
tested value can be non-t and non-nil, and the `lambda' case can change the
behavior when the function is called with more than 1 argument.
So most compilers don't apply such "optimizations", which makes it that much
more valuable to apply them by hand.
Stefan
- Re: empty-line-p,
Stefan Monnier <=