This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Mikael Djurfeldt <mdj@nada.kth.se> writes: > > (define my-hook-remove-handle > > (add-hook! window-close-hook > > (lambda (win) (display win)))) > > > > my-hook-remove-handle has different semantics from the `foo' symbol -- > > it *so* *happens* that it is the procedure, but the API can specify that > > it's simply something that can be used as an argument to remove-hook! > > instead of the procedure. You can look at it as an implementation > > detail that it is really the procedure. > > Are you suggesting that the above usage pattern should be mandatory? No. There'd be two ways to remove the proc from the hook -- by the proc itself or by the handle returned by add-hook!. > If we say in the API that remove-hook! takes what is returned from > add-hook! as argument, but the implementation allows for procedure > objects to be passed to remove-hook!, people might still be very > easily mislead to believe that it is OK to pass the procedure. > > Then, when the day comes when we make use of what we said in the > spec... crash! > > BTW, I don't see why it would be useful to pass something different > than the procedure. I'm hesitant to say this while I'm trying to champion my cause (and refrained from admitting this in my last email), but I'm a little uncertain of the value of my suggested change, as well. Maybe it'll help if I discuss my motivating problem instead of my initial proposed solution. The basic issue I was trying to address is not losing the ability to remove an anonymous proc from a hook. There are several ways to address this: 1) don't use anonymous procs for hooks -- give them names and don't lose them 2) don't worry about the ability to remove anonymous procs from hooks 3) extend add-hook! to return something that lets you remove the anonymous proc. This doesn't have to be the proc itself, and maybe it shouldn't be to prevent use of the proc from outside the hook (after all, if that was the intention, it's easier to use the first solution). 4) Provide an accessor to the list of procs attached to a hook. This would let me write a proc, `remove-last-added-hook' assuming there are some guarantees about the order the procs are kept in the hook. For Scwm, I've more than once been bitten by doing: (add-hook! foo-hook (lambda () (bar))) and then not being able to remove the proc; here, only #4 would be helpful, but doing #4 doesn't mean one couldn't do #3, too. Thanks, Greg