all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Thread and closure
@ 2023-05-04 12:02 Manuel Giraud via Users list for the GNU Emacs text editor
  2023-05-04 13:48 ` Manuel Giraud via Users list for the GNU Emacs text editor
  2023-05-04 23:33 ` Emanuel Berg
  0 siblings, 2 replies; 5+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2023-05-04 12:02 UTC (permalink / raw)
  To: gnu-emacs-help

Hi,

Is it possible in Emacs to have lisp threads to works with closures?
With the following example, 'M-x closure' displays a message but 'M-x
threaded-closure' does not:

--8<---------------cut here---------------start------------->8---
(defun closure ()
  (interactive)
  (let ((my-message "Hello world"))
    (funcall #'(lambda ()
		 (message "%s" my-message)))))

(defun threaded-closure ()
  (interactive)
  (let ((my-message "Hello world"))
    (make-thread #'(lambda ()
		     (message "%s" my-message)))))
--8<---------------cut here---------------end--------------->8---

Best regards,
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Thread and closure
  2023-05-04 12:02 Thread and closure Manuel Giraud via Users list for the GNU Emacs text editor
@ 2023-05-04 13:48 ` Manuel Giraud via Users list for the GNU Emacs text editor
  2023-05-04 23:33 ` Emanuel Berg
  1 sibling, 0 replies; 5+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2023-05-04 13:48 UTC (permalink / raw)
  To: Manuel Giraud via Users list for the GNU Emacs text editor; +Cc: gnu-emacs-help

Manuel Giraud via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> Hi,
>
> Is it possible in Emacs to have lisp threads to works with closures?
> With the following example, 'M-x closure' displays a message but 'M-x
> threaded-closure' does not:

Of course, I needed lexical-binding:

(setf-local lexical-binding t)
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Thread and closure
  2023-05-04 12:02 Thread and closure Manuel Giraud via Users list for the GNU Emacs text editor
  2023-05-04 13:48 ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2023-05-04 23:33 ` Emanuel Berg
  2023-05-05 13:40   ` Manuel Giraud via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2023-05-04 23:33 UTC (permalink / raw)
  To: help-gnu-emacs

Manuel Giraud via Users list for the GNU Emacs text editor wrote:

> (defun closure ()
>   (interactive)
>   (let ((my-message "Hello world"))
>     (funcall #'(lambda ()
> 		 (message "%s" my-message)))))
>
> (defun threaded-closure ()
>   (interactive)
>   (let ((my-message "Hello world"))
>     (make-thread #'(lambda ()
> 		     (message "%s" my-message)))))

(threaded-closure, sounds like something from the mechanics
world BTW! :))

But you can add this to your list:

;;; -*- lexical-binding: t -*-

(let ((msg "Hello world!"))
  (defun let-closure ()
    (message "%s" msg) ))

(declare-function let-closure nil)

;; (let-closure)

;; (make-thread #'let-closure)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Thread and closure
  2023-05-04 23:33 ` Emanuel Berg
@ 2023-05-05 13:40   ` Manuel Giraud via Users list for the GNU Emacs text editor
  2023-05-13 13:08     ` Emanuel Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Manuel Giraud via Users list for the GNU Emacs text editor @ 2023-05-05 13:40 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

[...]

> But you can add this to your list:

Thanks,

> ;;; -*- lexical-binding: t -*-
>
> (let ((msg "Hello world!"))
>   (defun let-closure ()
>     (message "%s" msg) ))
>
> (declare-function let-closure nil)

Is this necessary?  Or just to say that 'let-closure' is not defined in
a file?
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Thread and closure
  2023-05-05 13:40   ` Manuel Giraud via Users list for the GNU Emacs text editor
@ 2023-05-13 13:08     ` Emanuel Berg
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2023-05-13 13:08 UTC (permalink / raw)
  To: help-gnu-emacs

Manuel Giraud via Users list for the GNU Emacs text editor wrote:

>> (declare-function let-closure nil)
>
> Is this necessary? Or just to say that 'let-closure' is not
> defined in a file?

It shouldn't be. But if you don't use it the byte-compiler
will complain when/if a call to that function also appears in
the code.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-13 13:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-04 12:02 Thread and closure Manuel Giraud via Users list for the GNU Emacs text editor
2023-05-04 13:48 ` Manuel Giraud via Users list for the GNU Emacs text editor
2023-05-04 23:33 ` Emanuel Berg
2023-05-05 13:40   ` Manuel Giraud via Users list for the GNU Emacs text editor
2023-05-13 13:08     ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.