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

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

Re: Closures in Emacs and their usage scenarios.


From: Emanuel Berg
Subject: Re: Closures in Emacs and their usage scenarios.
Date: Tue, 12 Oct 2021 01:16:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Marcin Borkowski wrote:

> Yet another use (which of course - technically - is again
> a variant of the same thing) is generating a closure whose
> behavior depends on the argument of the function that
> defines it.

Not following?

> (defun negate (fun)
>   "Return a function returning the logical opposite of FUN."
>   (lambda (&rest args)
>     (not (apply fun args))))

Yes, I remember, no, I know you can do a lot with `lambda'
(anonymous function I believe :)), I mean just the

  (let ((...) ...)
    (defun ... )
    ...
    )

syntax Here are the 1 + a use cases I know of, where a -> 1.

;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;;   http://user.it.uu.se/~embe8573/emacs-init/geh.el
;;;   https://dataswamp.org/~incal/emacs-init/geh.el

(require 'cl-lib)

(let ((dope 1337))
  (defun hope ()
    (message "Hope is %d Dope" (cl-incf dope)) ))
;; (hope)

(let ((forward #'forward-char))
  (defun you-can-not-advance ()
    (apply forward '(1)))
  (defun you-can-not-redo ()
    (setq forward #'backward-char) ))
;; (you-can-not-advance)
;; (you-can-not-redo)
  
-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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