From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Lisp error on function :documentation Date: Mon, 17 Oct 2022 23:32:54 +0200 Message-ID: <87pmeqyw3d.fsf@dataswamp.org> References: <87mt9w5thu.fsf@web.de> <3aB3F8gotn0WkauCkikmQoG0bt-Zp1vYKKnElDvKwDmZOU2aICFsw5ojkVJWw6dG9fnzRZXpE0YTcdLIfIfHYIwKO3ghyRwQZ7OUsNc8CXc=@protonmail.com> <87a65wz9sn.fsf@web.de> <87czarfka0.fsf@web.de> <87a65u1thy.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11363"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:U2vp1QQVAIpnFSd62F4CcOuyP2A= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 18 11:18:40 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okikB-0002jY-UN for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 18 Oct 2022 11:18:39 +0200 Original-Received: from localhost ([::1]:39238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okik9-0008NN-IB for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 18 Oct 2022 05:18:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okXjS-0002Bw-0k for help-gnu-emacs@gnu.org; Mon, 17 Oct 2022 17:33:15 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:35002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okXjQ-0005h1-2D for help-gnu-emacs@gnu.org; Mon, 17 Oct 2022 17:33:09 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1okXjL-0000Bo-Lv for help-gnu-emacs@gnu.org; Mon, 17 Oct 2022 23:33:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 18 Oct 2022 05:11:52 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:140118 Archived-At: tomas wrote: > It means that a regular closure is a special case of an > OClosure, where all slots are hidden. A regular closure is a _special_ case? > Turning that around, an OClosure is a generalization of > a closure where some slots are visible. I'm only aware of the lexical/static let-closure which is a `let' with a (one or several) `defun' within it. I have found two use cases, (1) share variables between functions; and (2) have persistent (state) variable values between function calls. Here [last] is an interesting example that where both use cases are present, and we further encapsulation by puting two inner closures into one big on the outside. I've heard that closures can also be used in general to "use variables like they are global variables, only they aren't really" so it is as practical, but not as bad a practice ... However, all such cases I've had, upon closer examination, they are actually examples of either use case (1) or (2). As a practical note, if you consider global variables bad, they can be, thru shuffling around function into files that make sense - which is a good thing anyway, so you want that as well - global variables can be virtually eliminated by using closures. It just makes the code cooler and more exciting! In terms of theory they are a proto-OO system - or, if closures were there before the OO paradigm, an OO system is an extended system-system that's based on closures, i.e. the coupling of functions (methods) and variables (data). I'm not familiar with OClosure so if you'd care to show what they look like and what they can do - actually this also brings the thought to the OO world were certain variables (members) are private and some are public, or better perhaps, the variables are private and some methods (setters) are public, and now that I write it that's what you get by default with a let-closure, i.e., the regular one, since the variables are just usable from the functions which, at least in Elisp, are all one the same, public if you will, level ... ;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/w3m/w3m-survivor.el (require 'w3m-search) (require 'cl-lib) (let ((opts "torrent magnet 720p") (show "Survivor") (prompt "episode: ") ) (let ((next 1)) (defun australian-survivor (ep) (interactive (list (read-number prompt next))) (w3m-search w3m-search-default-engine (format "\"s10e%02d\" Australian %s %s" ep show opts) ) (setq next (1+ ep)) )) (declare-function australian-survivor nil) (defalias 'aus #'australian-survivor) (let ((next 1)) (defun us-survivor (ep) (interactive (list (read-number prompt next))) (w3m-search w3m-search-default-engine (format "\"s43e%02d\" %s %s" ep show opts) ) (setq next (1+ ep)) )) (declare-function us-survivor nil) (defalias 'us #'us-survivor) ) -- underground experts united https://dataswamp.org/~incal