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

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

Re: Another question about lambdas


From: Emanuel Berg
Subject: Re: Another question about lambdas
Date: Mon, 30 Jan 2023 18:44:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Michael Heerdegen wrote:

>>> My feeling is that lexical binding comes - while the
>>> principle is not hard to understand - with a larger space of
>>> non-trivial implications [...]
>>
>> And those are ... ?
>
> An example: try to write something that transforms code into
> a CPS, continuation passing style, form. Therefore you
> really need closures.

Are we talking lexical/static `let' inside or outside
`defun's?

Inside defuns they are very practical, local variables,
basically, outside defuns they are interesting, rather, I have
found 2 use cases so far, first, what in other languages are
refered to as static variables (whose value don't reset
between calls), second, the possibility to share such
variables between functions.

This file demonstrate those use cases, other than that I don't
know what one is supposed to do with them, really, and so far
they don't do anything global variables don't. So they are
a method to not have those, basically?

;;; -*- 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]