Lisp HUG Maillist Archive

Slightly more on capi:execute-with-interface ...

Hello,

Nick was gracious enough to help me with my previous question about 
capi:execute-with-interface, and I've used his solution with success.

Basically, my problem was capturing the return value from the function 
called by execute-with-interface.

Nick suggested this function as a model for what I should be doing ...

(defun frob (function interface)
  (let ((result))
    (capi:execute-with-interface interface
                                 (lambda ()
                                   (setf result
                                         (list (funcall function)))))
    (mp:process-wait "frobbing"
                     (lambda () result))
    (car result)))

I modified this slightly to this:

(defun frob (interface function &rest args)
  (let ((result))
    (capi:execute-with-interface interface
                                 (lambda ()
                                   (setf result (apply function args))))
    (mp:process-wait "frobbing"
                     (lambda () result))
    result))

Nick, note that in modifying your suggestion, I eliminated the call to
(list ...) and the subsequent (car result) to return the result.  I don't
think this breaks anything, but I'd welcome any advice you have if this
is a mistake.

Finally, using my slightly-hacked version of Nick's solution, I can now
write my interface accessors like this:

(defmethod reply-text ((self question-ui))
  (frob self #'(lambda (self) (text-input-pane-text (reply self))) self))

(defmethod (setf reply-text) (text (self question-ui))
  (frob self #'(lambda (self text) (setf (text-input-pane-text (reply self)) text)) self text))

In summary, this has worked out well, and resolved my problem.  Thanks for
the help.

John Sambrook


Re: Slightly more on capi:execute-with-interface ...

On Sat, 23 Jul 2005 06:52:11 -0700, John Sambrook <john.sambrook@common-sense.com> wrote:

> Nick, note that in modifying your suggestion, I eliminated the call
> to (list ...) and the subsequent (car result) to return the result.
> I don't think this breaks anything, but I'd welcome any advice you
> have if this is a mistake.

In Nick's example the function can also return NIL.  It'll wait
forever in your case.


Re: Slightly more on capi:execute-with-interface ...

John Sambrook wrote:

> Nick, note that in modifying your suggestion, I eliminated the call to
> (list ...) and the subsequent (car result) to return the result.  I don't
> think this breaks anything, but I'd welcome any advice you have if this
> is a mistake.

I think that Nick used the (LIST ...) / (CAR ...) idiom to make sure that
everything keeps working when the result happens to be NIL.  By removing
the list wrapper, you can't distinguish between an empty list result and
no result at all.

 --
Arthur


Re: Slightly more on capi:execute-with-interface ...

Unable to parse email body. Email id is 4216

Updated at: 2020-12-10 08:51 UTC