all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* A more specific/targeted version of macroexpand-all?
@ 2022-06-09  1:31 Okamsn
  2022-06-09  1:36 ` Emanuel Berg
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Okamsn @ 2022-06-09  1:31 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I would like to use `macroexpand-all` to substitute code in-place, like
a macro. My problem is that `macroexpand-all` expands all known macros
in the expression. I only want to use it to expand a limited set of macros.

I have been able to explicitly prevent expansion of macros by including
them in the second argument of `macroexpand-all`, such as in

     (macroexpand-all my-code `((cl-block) (cl-return-from) ,@my-macros))

but that still leaves the possibility of other, unknown macros expanding
incorrectly.

Is there a better way to do this kind of limited expansion than
`macroexpand-all`?

If not, is there a way to be more targeted when using `macroexpand-all`?
For example, is the below code the best way to get the currently known
macros that would be expanded by `macroexpand-all`?

     (cl-loop for i being the symbols
              when (eq 'macro (car-safe (symbol-function i)))
              collect i)

Thank you.




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

* Re: A more specific/targeted version of macroexpand-all?
  2022-06-09  1:31 A more specific/targeted version of macroexpand-all? Okamsn
@ 2022-06-09  1:36 ` Emanuel Berg
  2022-06-09  1:40 ` cl-loop and collect (was: Re: A more specific/targeted version of macroexpand-all?) Emanuel Berg
  2022-06-09 10:47 ` A more specific/targeted version of macroexpand-all? Michael Heerdegen
  2 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2022-06-09  1:36 UTC (permalink / raw)
  To: help-gnu-emacs

Okamsn wrote:

> Is there a better way to do this kind of limited expansion
> than `macroexpand-all`?

`macroexpand'?

> (cl-loop for i being the symbols
>          when (eq 'macro (car-safe (symbol-function i)))
>          collect i)

Cool!

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




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

* cl-loop and collect (was: Re: A more specific/targeted version of macroexpand-all?)
  2022-06-09  1:31 A more specific/targeted version of macroexpand-all? Okamsn
  2022-06-09  1:36 ` Emanuel Berg
@ 2022-06-09  1:40 ` Emanuel Berg
  2022-06-09  1:48   ` Emanuel Berg
  2022-06-09 10:47 ` A more specific/targeted version of macroexpand-all? Michael Heerdegen
  2 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2022-06-09  1:40 UTC (permalink / raw)
  To: help-gnu-emacs

Okamsn wrote:

> (cl-loop for i being the symbols
>          when (eq 'macro (car-safe (symbol-function i)))
>          collect i)

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/negative-subtraction.el

(require 'cl-lib)

(defun number-to-list (n)
  (cl-loop
    for d across (prin1-to-string n)
    collect (cl-digit-char-p d) ))
;; (number-to-list 1234) ; (1 2 3 4)

(defun negative-subtract (a b)
  (let*((a-nums (number-to-list a))
        (b-nums (number-to-list b)) )
    (cl-loop
      for i in a-nums
      for j in b-nums
      collect (- i j) )))
;; (negative-subtract 8888 7777) ; (1 1 1 1)

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




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

* Re: cl-loop and collect (was: Re: A more specific/targeted version of macroexpand-all?)
  2022-06-09  1:40 ` cl-loop and collect (was: Re: A more specific/targeted version of macroexpand-all?) Emanuel Berg
@ 2022-06-09  1:48   ` Emanuel Berg
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2022-06-09  1:48 UTC (permalink / raw)
  To: help-gnu-emacs

> ;; (negative-subtract 8888 7777) ; (1 1 1 1)

Right, that's a poor example because

  (- 8888 7777) ; 1111

as well!

But here then

                  (- 256 118) ; 138
  (negative-subtract 256 118) ; (1 4 -2)

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




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

* Re: A more specific/targeted version of macroexpand-all?
  2022-06-09  1:31 A more specific/targeted version of macroexpand-all? Okamsn
  2022-06-09  1:36 ` Emanuel Berg
  2022-06-09  1:40 ` cl-loop and collect (was: Re: A more specific/targeted version of macroexpand-all?) Emanuel Berg
@ 2022-06-09 10:47 ` Michael Heerdegen
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2022-06-09 10:47 UTC (permalink / raw)
  To: help-gnu-emacs

Okamsn <okamsn@protonmail.com> writes:

> I have been able to explicitly prevent expansion of macros by including
> them in the second argument of `macroexpand-all`, such as in
>
>      (macroexpand-all my-code `((cl-block) (cl-return-from) ,@my-macros))

I didn't know that nil-valued bindings work there.

> but that still leaves the possibility of other, unknown macros expanding
> incorrectly.

Why would they expand incorrectly?  Not sure I understand what you want.

Michael.




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

end of thread, other threads:[~2022-06-09 10:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09  1:31 A more specific/targeted version of macroexpand-all? Okamsn
2022-06-09  1:36 ` Emanuel Berg
2022-06-09  1:40 ` cl-loop and collect (was: Re: A more specific/targeted version of macroexpand-all?) Emanuel Berg
2022-06-09  1:48   ` Emanuel Berg
2022-06-09 10:47 ` A more specific/targeted version of macroexpand-all? Michael Heerdegen

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.