unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Barzilay <eli@barzilay.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] trunk r117340: * lisp/calculator.el: Lots of revisions
Date: Sun, 22 Jun 2014 08:23:25 -0400	[thread overview]
Message-ID: <21414.51901.656160.869117@home.barzilay.org> (raw)
In-Reply-To: <jwvzjha5k7t.fsf-monnier+emacsdiffs@gnu.org>

On Wednesday, Stefan Monnier wrote:
> > -          (cl-letf (((symbol-function 'F)
> > -                     (lambda (&optional x y) (calculator-funcall f x y)))
> > -                    ((symbol-function 'D)
> > -                     (lambda (x) (if calculator-deg (/ (* x 180) float-pi) x))))
> > -            (eval f `((X . ,X)
> > -                      (Y . ,Y)
> > -                      (TX . ,TX)
> > -                      (TY . ,TY)
> > -                      (DX . ,DX)
> > -                      (L . ,L))))))
> > -    (error 0)))
> > +      (cl-flet ((F (&optional x y) (calculator-funcall f x y))
> > +                (D (x) (if calculator-deg (/ (* x 180) float-pi) x)))
> > +        (eval `(let ((X ,X) (Y ,Y) (DX ,DX) (TX ,TX) (TY ,TY) (L ',L))
> > +                 ,f)
> > +              t)))))
> 
> Hmm... have you tested this?  `cl-flet' creates lexically-scoped
> function bindings (contrary to the old `flet'), so the F and D above
> in your new code aren't accessible to the `f' expression.

[I know I did, since one of my commits fixed the `fib' example in the
`calculator-user-operators' docstring.  But I probably tested it with
24.3.1 which is my regular emacs, though something else must have
happened since it's broken there too now.]

Is there some way to make it work with 24.3.1 and the trunk version?
Using the original seems to complain about unbound functions when letf
is trying to save the old `symbol-function' values.


> As for changing the `eval' call, the form I used is more efficient
> than the (eval `(let ...)) you're using now: what was the motivation
> for this change?

The change I did makes it work in 24.3.1 (my regular version) which
doesn't have the new eval feature.  Efficiency is really not important
in this case, but making me test it more is important...


> >    (let ((inp (or keys (this-command-keys))))
> [...]
> > +      ;; translates kp-x to x and [tries to] create a string to lookup
> > +      ;; operators; assume all symbols are translatable via
> > +      ;; `function-key-map' or with an 'ascii-character property
> > +      (concat (mapcar (lambda (k)
> > +                        (if (numberp k) k (or (get k 'ascii-character)
> > +                                              (error "??bad key??"))))
> > +                      (or (lookup-key function-key-map inp) inp))))))
> 
> (this-command-keys) should return "fully decoded events", i.e. after
> passing through the keyboard-coding-system, input-decode-map,
> function-key-map, and key-translation-map.  So neither (lookup-key
> function-key-map inp) nor (get k 'ascii-character) should be
> necessary.
> 
> IOW if this code really is needed, it deserves a comment explaining
> why it's needed despite the fact that function-key-map was already
> applied.

It's code that has been there before, and I was never sure about it.
Here's what leads to it:

* If there is a binding for kp-whatever, rebinding whatever doesn't
  affect kp-whatever.

* Since I have (or had) a few of these, I made the code bind *both*
  kp-whatever and whatever.  (Thinking that for anyone, a good reason
  to have kp-whatever bound globally doesn't contradict calculator
  re-grabbing it.)

* With both bound, the lookup is needed, otherwise it ends up with
  [kp-7] and [kp-add] instead of "7" and "+".

The bottom line is, I'm not sure about the whole thing -- one of these
should be done:

1. The above is what it is, and needs to be synthesized into the
   comment you mention.  (Something that says that it's needed because
   kp-whatever key bindings are made.)

2. Maybe the kp-whatever key bindings should go away instead?  (I
   think that I don't need them anymore, but I hesitate to do such a
   big change in an area I don't know much about.)

3. It would really be best if there's a good way to just eliminate the
   need for the whole thing -- currently things like [kp-]7 and [kp-]+
   are bound to `calculator-op' and `calculator-digit', which need to
   lookup the actual key.  But I suppose that this will take time.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!



  reply	other threads:[~2014-06-22 12:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1Ww2Qw-0002aL-HF@vcs.savannah.gnu.org>
2014-06-16 21:22 ` [Emacs-diffs] trunk r117340: * lisp/calculator.el: Lots of revisions Stefan Monnier
2014-06-18 10:08   ` Eli Barzilay
2014-06-18 18:49     ` Stefan Monnier
2014-06-23  5:21       ` Eli Barzilay
2014-06-23  5:48         ` Nicolas Semrau
2014-06-23 14:24         ` Stefan Monnier
2014-06-18 15:21 ` Stefan Monnier
2014-06-22 12:23   ` Eli Barzilay [this message]
2014-06-23 13:24     ` Stefan Monnier
2014-06-24  7:47       ` Eli Barzilay
2014-06-25  1:11       ` Stephen J. Turnbull

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21414.51901.656160.869117@home.barzilay.org \
    --to=eli@barzilay.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).