help-guix
[Top][All Lists]
Advanced

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

Re: [Question] Define a macro that defines two variables


From: Simon Tournier
Subject: Re: [Question] Define a macro that defines two variables
Date: Tue, 19 Sep 2023 09:33:12 +0200

Hi,

On Tue, 19 Sep 2023 at 04:43, Rodrigo Morales <moralesrodrigo1100@gmail.com> 
wrote:

> #+BEGIN_SRC elisp
> (defmacro my-define-variables (string)
>   `(progn
>     (defvar ,(intern (concat string "-1")) "one")
>     (defvar ,(intern (concat string "-2")) "two")))
>
> (my-define-variables "hello")
>
> (list hello-1 hello-2)
> #+END_SRC

Well, Guile implements the good way and the traditional way. :-)

https://www.gnu.org/software/guile/manual/html_node/Macros.html

Let use « Lisp-style Macro Definitions » which looks similar to Emacs
Lisp.

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> (defmacro my-define-variables (str)
  `(begin
     (define ,(string->symbol (string-append str "-1")) "one")
     (define ,(string->symbol (string-append str "-2")) "two")))
scheme@(guix-user)> (my-define-variables "hello")
scheme@(guix-user)> (list hello-1 hello-2)
$2 = ("one" "two")
--8<---------------cut here---------------end--------------->8---

Well, I do not know if it is the correct way.

Hope that help,
simon



reply via email to

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