Committed revision 257 to http://mwolson.org/bzr/dvc/

Rework dvc-capturing-lambda to not depend on lexical behavior from the Emacs 
`let' form
  
  * lisp/dvc-lisp.el (dvc-capturing-lambda-helper): Explain
    `captured-symbols'.
    (dvc-capturing-lambda): Re-make and test.  This removes my grievance
    about the unnecessary (funcall (lambda () ...)) form at the end.
    Further explanation below.
  
  I noticed that the `sort-by-nearness-1' example that I gave in the
  documentation for dvc-capturing-lambda caused a warning about "a" being
  undefined when byte-compiling.  This was due to the code generating a
  let-bind around a lambda, which is completely incorrect in Emacs Lisp:
  that construct assumes lexical binding, which we don't have.
  
  The best way of doing this is to instead pass extra arguments to a new
  lambda form.  This way, we guarantee that the necessary bindings exist
  inside of the lambda form.  We use the newly generated symbol names as
  the names of these "extra" arguments, and preserve the names of the real
  arguments which are in the outer lambda form.
  
  To illustrate, the old way generated code similar in effect to this:
  
  [Assume the statements (capture sym1) and (capture sym2) exist in body,
  and that these symbols have been replaced with dvc-uniq-1 and dvc-uniq-2
  in body, respectively.]
  
  `(lambda (arg1 arg2)
    (let ((dvc-uniq-1 ,sym1)
          (dvc-uniq-2 ,sym2))
      (funcall (lambda () body))))
  
  The new way is to generate code like the following, instead:
  
  `(lambda (arg1 arg2)
     (apply (lambda (arg1 arg2 dvc-uniq-1 dvc-uniq-2) body)
            arg1 arg2
            '(,sym1 ,sym2)))
  
  This code has passed all of the tests that I have thrown at it (both
  byte-compiled and interpreted), so I am certain that it works.

-- 
       Michael Olson -- FSF Associate Member #652     |
 http://mwolson.org/ -- Jabber: mwolson_at_hcoop.net  |  /` |\ | | |
            Sysadmin -- Hobbies: Lisp, GP2X, HCoop    | |_] | \| |_|
Projects: Emacs, Muse, ERC, EMMS, ErBot, DVC, Planner |

Attachment: pgp14S83Pk3N3.pgp
Description: PGP signature

_______________________________________________
Dvc-dev mailing list
[email protected]
https://mail.gna.org/listinfo/dvc-dev

Reply via email to