unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* [Question] Define a macro that defines two variables
@ 2023-09-19  4:43 Rodrigo Morales
  2023-09-19  7:33 ` Simon Tournier
  0 siblings, 1 reply; 2+ messages in thread
From: Rodrigo Morales @ 2023-09-19  4:43 UTC (permalink / raw)
  To: help-guix

I want to define a macro such that given a string it defines two
variables whose name contain that string

In Emacs, I can do that as it follows

#+HEADER: :results value
#+HEADER: :results verbatim
#+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

#+RESULTS:
#+begin_example
("one" "two")
#+end_example

How to do this in Guile? I want to use this macro in my system
configuration.


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

* Re: [Question] Define a macro that defines two variables
  2023-09-19  4:43 [Question] Define a macro that defines two variables Rodrigo Morales
@ 2023-09-19  7:33 ` Simon Tournier
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Tournier @ 2023-09-19  7:33 UTC (permalink / raw)
  To: Rodrigo Morales, help-guix

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


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

end of thread, other threads:[~2023-09-19  8:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-19  4:43 [Question] Define a macro that defines two variables Rodrigo Morales
2023-09-19  7:33 ` Simon Tournier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).