From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry OReilly Newsgroups: gmane.emacs.help Subject: Re: Returning variable "references" under lexical binding Date: Tue, 21 May 2013 10:41:51 -0400 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1369147330 32541 80.91.229.3 (21 May 2013 14:42:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 May 2013 14:42:10 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 21 16:42:09 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UenlR-0006sM-Ke for geh-help-gnu-emacs@m.gmane.org; Tue, 21 May 2013 16:42:09 +0200 Original-Received: from localhost ([::1]:43930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UenlR-0003Wn-8x for geh-help-gnu-emacs@m.gmane.org; Tue, 21 May 2013 10:42:09 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UenlG-0003Vn-Hl for help-gnu-emacs@gnu.org; Tue, 21 May 2013 10:41:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UenlA-0007mC-Ga for help-gnu-emacs@gnu.org; Tue, 21 May 2013 10:41:58 -0400 Original-Received: from mail-oa0-f53.google.com ([209.85.219.53]:60981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UenlA-0007m3-AK for help-gnu-emacs@gnu.org; Tue, 21 May 2013 10:41:52 -0400 Original-Received: by mail-oa0-f53.google.com with SMTP id g12so903385oah.12 for ; Tue, 21 May 2013 07:41:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=FchOm0m0T/sRPYpRXYbguoW8IrhQuWskAiRn2Gaseco=; b=H1zf5DefLoO7IqmV2O7V0dTnFPABvSkVYMMrbhzs1/KI7DZ27KoW7/zW4wucMlgcFI 2HNZkqOJo6nzedhCTPHCKbOyyjTYtKmOCo34ly9m5fUTDiHNOyKcy5LGmp7Z1srZ5KHZ fOYXL2dUmhJtiDr67Em57qPIN1NbaOppizhh74Uy2AipANLdq0vmunVRe0BiUzyOjAjn TeBtcE7glTvotSTctKVSEPvEMUZ3YKJQoz0ubtLXomwF183kPr+4+crny3F9hevr7Mai YURRTlG1trLmVfgXFDT4nFlXga/puV/wuQvE//+SKuUw+/ChnbCXqkelxuOWJrXCjPT5 7q5Q== X-Received: by 10.182.225.199 with SMTP id rm7mr1679669obc.20.1369147311520; Tue, 21 May 2013 07:41:51 -0700 (PDT) Original-Received: by 10.76.93.68 with HTTP; Tue, 21 May 2013 07:41:51 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.219.53 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:90949 Archived-At: >> Why not >> >> (defun start-my-timer () >> (let ((timer (make-timer ...)) >> ... >> timer)) >> (defun cancel-my-timer (timer) >> (cancel-timer timer)) > > Because start-my-timer sets up callbacks that may repeatedly change the > value of the "timer" variable: But you said: > I want my routine to return an object that can be used to cancel the > most recently set timer. How is the above start-my-timer inadequate then? > (defun start-my-timer () > (let (timer) > ;; ... (setq timer (make-timer ...)) ... > (lambda () timer))) > > (defun cancel-my-timer (timer) > (cancel-timer (funcall timer))) Each invocation of this start-my-timer will return a different closure. Whether start-my-timer returns a timer or a closure, you still have to keep track of which one to pass to cancel-my-timer. So the use of closures doesn't facilitate anything that I can see.