unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Lisp error on function :documentation
Date: Mon, 17 Oct 2022 23:32:54 +0200	[thread overview]
Message-ID: <87pmeqyw3d.fsf@dataswamp.org> (raw)
In-Reply-To: Y02st325GwNrrtA0@tuxteam.de

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




  reply	other threads:[~2022-10-17 21:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-15 23:48 Lisp error on function :documentation Heime via Users list for the GNU Emacs text editor
2022-10-16  2:48 ` Michael Heerdegen
2022-10-16  2:59   ` Heime
2022-10-16  3:37     ` Michael Heerdegen
2022-10-16  3:50       ` Heime
2022-10-16  4:12         ` Michael Heerdegen
2022-10-16  4:30           ` Heime
2022-10-16 22:53             ` Michael Heerdegen
2022-10-16 23:08               ` Heime
2022-10-16 23:23                 ` Michael Heerdegen
2022-10-16 15:23           ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-16 22:58             ` Michael Heerdegen
2022-10-16 23:09               ` Heime
2022-10-16 23:25                 ` Michael Heerdegen
2022-10-16 23:39                   ` Heime
2022-10-16 23:43                     ` Michael Heerdegen
2022-10-17  0:07                       ` Heime
2022-10-17  0:15                         ` Michael Heerdegen
2022-10-17  1:01                           ` Heime
2022-10-17  1:15                             ` Michael Heerdegen
2022-10-17  1:01                           ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-17  1:22                             ` Michael Heerdegen
2022-10-17  1:27                               ` Michael Heerdegen
2022-10-17  2:08                               ` Heime
2022-10-17  2:42                                 ` Michael Heerdegen
2022-10-17  3:03                                   ` Heime
2022-10-17  3:19                                     ` Emanuel Berg
2022-10-17  1:00                 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-17  1:55                   ` Heime
2022-10-17 12:28                     ` Stefan Monnier
2022-10-17 13:15                       ` Emanuel Berg
2022-10-17 19:27                         ` tomas
2022-10-17 21:32                           ` Emanuel Berg [this message]
2022-10-18  0:51                       ` Michael Heerdegen
2022-10-18  1:05                         ` Emanuel Berg
2022-10-16  3:56 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-16  4:00   ` Heime
2022-10-16  4:05     ` Michael Heerdegen
2022-10-16  4:07     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pmeqyw3d.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).