Re: [BBDB] ChangeLog 2016-10-02: Use lexical binding

2016-10-22 Thread Stefan Monnier
>> The first solution binds the  variables lexically rather than
>> dynamically.  That means that if those  appear lexically inside
>> the  things will work correctly, but if  calls a function
>> which then refers to  this reference will fail.
> Thank you for the clarification.  The code in bbdb-anniv binds the
> variables lexcially via let which also contains the call of eval.
> So this is fine.

Not sure I understand.  You seem to describe something like

(let ((x1 v1)) ... (eval exp) ...)

in which case the evaluation of `exp' will not have access to `x1'.
What I suggested was

(eval exp `((x1 . ,v1)))

in which case the value of `exp' can contain references to `x1'.
But it's still different from a dynamic-binding of `x1', because

(let ((exp '(+ x1 4)))
  (eval exp `((x1 . 5

will correctly return 9, but

(defun my-f (y) (+ x1 y))
(let ((exp '(my-f 4)))
  (eval exp `((x1 . 5

will signal en error because `x1' is not visible to `my-f' (it's only
visible lexically within `exp').

In many cases, this is perfectly acceptable, in which case it's the
solution I recommend.


Stefan


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [BBDB] ChangeLog 2016-10-02: Use lexical binding

2016-10-07 Thread Roland Winkler
On Fri Oct 7 2016 Stefan Monnier wrote:
> The first solution binds the  variables lexically rather than
> dynamically.  That means that if those  appear lexically inside
> the  things will work correctly, but if  calls a function
> which then refers to  this reference will fail.

Thank you for the clarification.  The code in bbdb-anniv binds the
variables lexcially via let which also contains the call of eval.
So this is fine.

> This note about lexical binding is talking about a chunk of code like
> 
> (let ((x 1))
>   ...
>   (defvar x 5)
>   ...)
> 
> if run in lexical-binding mode, the let will bind `x` statically, but
> `defvar` always refers to the dynamically-bound variable `x`, just like
> (set 'x 5) would.
> 
> > This suggests to me that in your second approach the defvar's could
> > also go inside the let, which appears rather odd to me.
> 
> No, that wouldn't work: the (defvar ) is there to declare that
> subsequent uses of  should use dynamic scoping.

Again thanks for the clarification.  I'll stay with the first
approach you suggested.

Roland

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [BBDB] ChangeLog 2016-10-02: Use lexical binding

2016-10-06 Thread Roland Winkler
On Tue Oct 4 2016 Stefan Monnier wrote:
> There are two ways to do that with lexical-binding:
> - use (eval  `(( . ,) ( . ,) ...)
>   which will not give the exact same behavior but works well in many
>   cases (i.e. depends on the code put in diary-date-forms).
> - use
> 
> (defvar ) (defvar ) ...
> (let (( )
>   ( )
>   ...)
>   (eval  t))
> 
>   which will preserve backward compatibility.

Thank you, I did not know that! - It appears to me that the first
approach is the cleaner way to go.  So I've tested it with
bbdb-anniv.el, and it seems to do exactly the right thing.  Under
what circumstances could there be a problem?  (The forms in
diary-date-forms are lists containing symbols and strings.  Then
`eval' is applied to the list elements in order to replace the
symbols by their let-bound values.  So there is nothing fancy
happening here.  Possibly there is yet a completely different
strategy for this problem?  I just copied the relevant code from
diary-list-entries-2, assuming that this should be the most reliable
strategy for bbdb-anniv even if I do not know too much about
diary-lib.el.)

Actually, I am a bit confused about the second approach you
suggested.  I believe I understand its logic, though I find it odd
to use defvar in such a context.  Interestingly, the elisp manual
says about `defvar':

 If SYMBOL is already lexically bound (e.g., if the ‘defvar’ form
 occurs in a ‘let’ form with lexical binding enabled), then ‘defvar’
 sets the dynamic value.  The lexical binding remains in effect
 until its binding construct exits.  *Note Variable Scoping::.

This suggests to me that in your second approach the defvar's could
also go inside the let, which appears rather odd to me.  Or am I
misinterpreting this paragraph?  What would be an example for this
usage of defvar in a let form?

Thanks again,

Roland

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Re: [BBDB] ChangeLog 2016-10-02: Use lexical binding

2016-10-04 Thread Stefan Monnier
> This variable contains forms that are evaluated using `eval',
> assuming that the variables appearing in this form are bound
> dynamically.  - I believe that old coding schemes like this one,

There are two ways to do that with lexical-binding:
- use (eval  `(( . ,) ( . ,) ...)
  which will not give the exact same behavior but works well in many
  cases (i.e. depends on the code put in diary-date-forms).
- use

(defvar ) (defvar ) ...
(let (( )
  ( )
  ...)
  (eval  t))

  which will preserve backward compatibility.


-- Stefan


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [BBDB] ChangeLog 2016-10-02: Use lexical binding

2016-10-02 Thread Roland Winkler
On Sun Oct 2 2016 Sam Steingold wrote:
> I think if you add
> 
> (defvar diary-date-forms)
> 
> to bbdb-anniv.el, it will work with lexical-binding too.

This variable contains forms that are evaluated using `eval',
assuming that the variables appearing in this form are bound
dynamically.  - I believe that old coding schemes like this one,
which are frequently used by the calendar / diray package are a
major reason why emacs has not completely switched to lexical
binding.  If bbdb-anniv.el hooks into the calendar /dirary package,
it needs to follow the conventions of this package till we get a
more complete overhaul of this package (which in turn is hampered by
the fact that calendar /diary has been around for a long time, and
substantial changes in its mode of operation might break more user
customizations).

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [BBDB] ChangeLog 2016-10-02: Use lexical binding

2016-10-02 Thread Sam Steingold
> * Roland Winkler  [2016-10-02 00:20:17 -0500]:
>
> I switched to lexical binding for all elisp files of BBDB except
> for bbdb-anniv.el (which relies on `diary-date-forms' that is not
> compatible with lexical binding).

I think if you add

(defvar diary-date-forms)

to bbdb-anniv.el, it will work with lexical-binding too.

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1404
http://steingoldpsychology.com http://www.childpsy.net 
http://thereligionofpeace.com
http://americancensorship.org http://www.dhimmitude.org http://think-israel.org
If you want to shoot yourself, it is YOUR responsibility to wear armor.


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


[BBDB] ChangeLog 2016-10-02: Use lexical binding

2016-10-01 Thread Roland Winkler
I switched to lexical binding for all elisp files of BBDB except
for bbdb-anniv.el (which relies on `diary-date-forms' that is not
compatible with lexical binding).

I have been using this for a little while without problems.
Still this may give rise to unexpected surprises for others.
If this happens let me know.


2016-10-02  Roland Winkler  
* lisp/bbdb-com.el, lisp/bbdb-gnus.el, lisp/bbdb-ispell.el:
* lisp/bbdb-message.el, lisp/bbdb-mhe.el, lisp/bbdb-migrate.el:
* lisp/bbdb-mu4e.el, lisp/bbdb-mua.el, lisp/bbdb-pgp.el:
* lisp/bbdb-print.el, lisp/bbdb-rmail.el, lisp/bbdb-sc.el:
* lisp/bbdb-site.el.in, lisp/bbdb-snarf.el, lisp/bbdb-vm.el:
* lisp/bbdb-wl.el, lisp/bbdb.el: Use lexical binding.

* lisp/bbdb.el (bbdb-alist-with-header): Start name of unused
variables with underscore.
(bbdb-display-record-multi-line, bbdb-display-records): Remove
unused variable.
* lisp/bbdb-com.el (bbdb-omit-record):
* lisp/bbdb-snarf.el (bbdb-snarf-surrounding-space)
(bbdb-snarf-empty-lines):
* lisp/bbdb-migrate.el (bbdb-undocumented-variables): Start name
of unused variables with underscore.
* lisp/bbdb-mua.el (bbdb-get-address-components):
* lisp/bbdb-print.el (bbdb-print-record): Remove unused variable.
* lisp/bbdb-gnus.el: Autoload message-make-domain.
(bbdb/gnus-score-as-text): Start name of unused variables with
underscore.

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/