help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lisp error on function :documentation


From: Emanuel Berg
Subject: Re: Lisp error on function :documentation
Date: Mon, 17 Oct 2022 23:32:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]