Re: Macro for replacing a placeholder in an expression

2022-08-06 Thread Zelphir Kaltstahl
Hello Linus! On 8/5/22 11:42, Linus Björnstam wrote: I wrote this, which does a tree fold over a sexp: https://hg.sr.ht/~bjoli/megacut/browse/readme.txt?rev=tip It is unhygienic currently, and I will probably never change because I only use it at the repl. The code is really just a

Re: Macro for replacing a placeholder in an expression

2022-08-05 Thread Linus Björnstam
I wrote this, which does a tree fold over a sexp: https://hg.sr.ht/~bjoli/megacut/browse/readme.txt?rev=tip It is unhygienic currently, and I will probably never change because I only use it at the repl. The code is really just a syntax-case version of the fast and efficient flatten

Re: Macro for replacing a placeholder in an expression

2022-07-30 Thread Maxime Devos
On 30-07-2022 17:42, Zelphir Kaltstahl wrote: Does this mean, that recursive application of a macro inside a macro is impossible? To expand to subforms being the same macro again and this way transform a whole tree of s-expressions? You can have recursive macros, see e.g. the let^ macro at

Re: Macro for replacing a placeholder in an expression

2022-07-30 Thread Maxime Devos
On 30-07-2022 22:44, Maxime Devos wrote: "All I want to do" is to replace some placeholder (in this case ) in an arbitrary form. No matter how that form looks or how deeply it is nested, if there are inside of it, I want to replace them. Is this impossible? Yes, see e.g. the

Re: Macro for replacing a placeholder in an expression

2022-07-30 Thread Maxime Devos
On 30-07-2022 17:42, Zelphir Kaltstahl wrote: [...] But now comes the problem: Since I want to replace all occurrences of for example and does not need to be defined, I think I must use define-syntax, to avoid Guile trying to evaluate the arguments to a function call. OK, so a macro I

Re: Macro for replacing a placeholder in an expression

2022-07-30 Thread Zelphir Kaltstahl
Hi Maxime! On 7/28/22 12:23, Zelphir Kaltstahl wrote: Hello Maxime! On 7/28/22 02:55, Maxime Devos wrote: These macros all sound more complicated than necessary -- on the first one, I've sent you a message with sneek: ;; By: Maxime Devos ;; This does not recurse into #(...). ;; Also,

Re: Macro for replacing a placeholder in an expression

2022-07-28 Thread Zelphir Kaltstahl
On 7/28/22 11:48, Maxime Devos wrote: On 28-07-2022 10:39, Zelphir Kaltstahl wrote: I aimed to do everything with syntax-rules, as the simplest means, but when writing the code I have, I hit the snag, that one could not have multiple ellipses at the same level of nesting in the patterns.

Re: Macro for replacing a placeholder in an expression

2022-07-28 Thread Maxime Devos
On 28-07-2022 12:23, Zelphir Kaltstahl wrote: I'll need to look at this and learn about eval-when The eval-when is only required if the macro is 'run' when the module holding the macro is compiled (to avoid some compilation failures); often the eval-when can be dropped. Greetings, Maxime.

Re: Macro for replacing a placeholder in an expression

2022-07-28 Thread Zelphir Kaltstahl
Hello Maxime! On 7/28/22 02:55, Maxime Devos wrote: These macros all sound more complicated than necessary -- on the first one, I've sent you a message with sneek: ;; By: Maxime Devos ;; This does not recurse into #(...). ;; Also, such a construct does not nest well, you can't put a

Re: Macro for replacing a placeholder in an expression

2022-07-28 Thread Maxime Devos
On 28-07-2022 10:39, Zelphir Kaltstahl wrote: I aimed to do everything with syntax-rules, as the simplest means, but when writing the code I have, I hit the snag, that one could not have multiple ellipses at the same level of nesting in the patterns. IIUC, you mean: (syntax-rules ()   ((foo

Re: Macro for replacing a placeholder in an expression

2022-07-28 Thread Zelphir Kaltstahl
Hello Maxime! Thank you for your quick response! (Mailing list saves me again! Yay!) On 7/28/22 03:04, Maxime Devos wrote: On 28-07-2022 01:57, Zelphir Kaltstahl wrote: scheme@(guile-user)> (define-syntax test   (syntax-rules (lambda)     [(_ (op args body* ...)) ((test op) (test args)

Re: Macro for replacing a placeholder in an expression

2022-07-27 Thread Maxime Devos
On 28-07-2022 01:57, Zelphir Kaltstahl wrote: scheme@(guile-user)> (define-syntax test   (syntax-rules (lambda)     [(_ (op args body* ...)) ((test op) (test args) (test body* ...))]     [(_ thing1 thing2 things* ...) ((test thing1) (test thing2 things* ...))]     [(_ (thing))

Re: Macro for replacing a placeholder in an expression

2022-07-27 Thread Maxime Devos
These macros all sound more complicated than necessary -- on the first one, I've sent you a message with sneek: ;; By: Maxime Devos ;; This does not recurse into #(...). ;; Also, such a construct does not nest well, you can't put a replace-result-placeholder inside a

Macro for replacing a placeholder in an expression

2022-07-27 Thread Zelphir Kaltstahl
Hello Guile Users, I am trying to write a macro, which replaces all placeholders (in this case ) with an identifier in an arbitrarily structured expression (arbitrary nesting of expressions). I have the following code now: (define-syntax replace-result-placeholder (syntax-rules (