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) (test body* ...))]

    [(_ thing1 thing2 things* ...)
 ((test thing1) (test thing2 things* ...))]

    [(_ (thing))
 (thing)]

    [(_ thing)
 thing]))
scheme@(guile-user)> (test (lambda (a) (+ a 1)))
While compiling expression:
Syntax error:
unknown file:798:0: lambda: invalid argument list in subform ((a)) of (test (a))


There seems to be something about a template like (one-thing) that I do not 
understand or something completely different is going on. 


Here's what happening:

(test (lambda (a) (+ a 1))

--> because  the 'test' in the beginning is a macro

((test lambda) (test (a)) (test (+ a 1))

--> likewise

(lambda (test (a)) (test (+ a 1))

Now we end up with the 'lambda' macro. The lambda macro sees as argument list 
(test (a)) and interprets 'test' as the first argument, but the second part 
'(a)' is not an identifier so the lambda macro cannot do anything with that 
and tells you that by saying: lambda: invalid argument list in 


Ahhh now I get it! lambda is also a macro … I did not think of that.




This seems the same issue as in 'Re: boiler plate class generation, writing 
fresh variables with macros' to me but in a slightly different context


Syntax transformations in Scheme work from the outside to the inside, not the 
other way around, so you can't do things like this (define-class doesn't know 
what to do with this 'slot-machine' thing, it will reject it for not being a 
valid slot definition). However, you can define a syntax that generates the 
surrounding define-class and interprets things to insert the result of 
slot-matchine into a proper define-class form. 


And this explains the order of expansion! Something I've already been wondering 
about, what the order is or what the rules are.



I consider a (in your case recursive, but in that case more like something 
like syntax-map (which can be defined recursively in terms of syntax-case)) 
syntax-case to be practical for this (more so than pure syntax-rules), see my 
other response.


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. After some thinking I 
found the solution to build up a temporary list, which then is of course 1 
deeper level of nesting, where I could then use ellipses again. I felt quite 
clever doing that trick. Maybe I could implement a syntax-map using that trick 
and then use syntax-map in my macro instead.


I have a question regarding syntax-case:

If I use it, does my code become less portable to other Schemes?

And regarding syntax-rules:

How portable are macros, which exclusively use syntax-rules?



Greetings,
Maxime


Thank you again for your help and explanations! Things are much clearer now!

Best regards,
Zelphir

--
repositories: https://notabug.org/ZelphirKaltstahl




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 x ... y ...) [the replacement]))

? If so, such a construct is ambigious.

After some thinking I found the solution to build up a temporary list, 
which then is of course 1 deeper level of nesting, where I could then 
use ellipses again. I felt quite clever doing that trick. Maybe I 
could implement a syntax-map using that trick and then use syntax-map 
in my macro instead. 
I have a question regarding syntax-case:


If I use it, does my code become less portable to other Schemes?

And regarding syntax-rules:

How portable are macros, which exclusively use syntax-rules?

Everything that supports syntax-case most likely supports syntax-rules 
too, as syntax-rules can easily be defined in terms of syntax-case, so 
syntax-rules is at least as portable as syntax-case.


syntax-rules and syntax-case are pretty standard (it's in the R6RS), so 
I expect them to be available in recent-ish non-minimalistic Schemes.


However, some Schemes (likely Schemes that predate the R6RS, or in 
Schemes that try new things out), use other syntax systems.


Anyway, I've found a table:


https://docs.scheme.org/surveys/syntax-definitions/


Looks like syntax-rules is supported by all the tested systems. 
syntax-case is less supported, but among the 'low-level' macro systems 
it has the highest support.  It's a bit out-of-date though, syntax-case 
is supported for Chicken: 
http://code.call-cc.org/legacy-eggs/3/syntax-case.html,


Decide for yourself of course, but I don't think going for maximal 
portability is worth the effort here of something making things work 
with syntax-rules.




Greetings,
Maxime


Thank you again for your help and explanations! Things are much 
clearer now!


Best regards,
Zelphir 




OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


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 
replace-result-placeholder inside a replace-result-placeholder meaningfully,
;; so I'm wondering why you're doing this, maybe your goal can be accomplished 
more robustly with a different method.
(eval-when (expand load eval)
   (define (replace-placeholder new code) ; <--- recursively transforms code to 
replace '' by new
 (syntax-case code ()
   ( new)
   ((x . y)
#`(#,(replace-placeholder new #'x) . #,(replace-placeholder new #'y)))
   (rest #'rest

(define-syntax replace-result-placeholder
   (lambda (s)
 (syntax-case s () ; : placeholder
   ((_ new code) (replace-placeholder #'new #'code)

(display (replace-result-placeholder
quote
( bar))) ; -> bar

(I think thinking in terms of 'operations' and special-casing lambda etc would 
make things harder here)


As a bonus, this supports things like `((x . ) (z . w)) which aren't 
supported by the original macro as that macro assumed lists.


Greetings,
Maxime.

I'll need to look at this and learn about eval-when. I also did not think about 
vectors yet. Thank you!


Best regards,
Zelphir

--
repositories:https://notabug.org/ZelphirKaltstahl


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.



OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


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.


IIUC, you mean:

(syntax-rules ()
  ((foo x ... y ...) [the replacement]))

? If so, such a construct is ambigious.


Yep, that is the case I meant : )


After some thinking I found the solution to build up a temporary list, which 
then is of course 1 deeper level of nesting, where I could then use ellipses 
again. I felt quite clever doing that trick. Maybe I could implement a 
syntax-map using that trick and then use syntax-map in my macro instead. 
I have a question regarding syntax-case:


If I use it, does my code become less portable to other Schemes?

And regarding syntax-rules:

How portable are macros, which exclusively use syntax-rules?

Everything that supports syntax-case most likely supports syntax-rules too, as 
syntax-rules can easily be defined in terms of syntax-case, so syntax-rules is 
at least as portable as syntax-case.


syntax-rules and syntax-case are pretty standard (it's in the R6RS), so I 
expect them to be available in recent-ish non-minimalistic Schemes.


However, some Schemes (likely Schemes that predate the R6RS, or in Schemes 
that try new things out), use other syntax systems.


Anyway, I've found a table:


https://docs.scheme.org/surveys/syntax-definitions/


Looks like syntax-rules is supported by all the tested systems. syntax-case is 
less supported, but among the 'low-level' macro systems it has the highest 
support.  It's a bit out-of-date though, syntax-case is supported for Chicken: 
http://code.call-cc.org/legacy-eggs/3/syntax-case.html,


Decide for yourself of course, but I don't think going for maximal portability 
is worth the effort here of something making things work with syntax-rules.


Hm OK, thanks for that! Well, it is in a repository of guile-examples, so I 
guess I can let go of wanting to do it all with syntax-rules.





Greetings,
Maxime


Thank you again for your help and explanations! Things are much clearer now!

Best regards,
Zelphir 


--
repositories:https://notabug.org/ZelphirKaltstahl


Re: G-Golf - handling of unresloved symbols in gobject-inspection

2022-07-28 Thread Andy Tai
Thanks for the fix.  Now G-Golf works on Ubuntu 20.04, which has GI
1.64, an old version

On Wed, Jul 27, 2022 at 6:23 PM David Pirotte  wrote:
>
> Hello Andy,
>
> > > For example, on GNU Guix, the GI version is for now at 0.64.  So
> > > G-Golf, when invoked from a guile program using it,  would fail
> > > with
>
> > > ;;; In procedure dlsym: Error resolving
> > > "g_callable_info_create_closure":
> > > "/gnu/store/g6gxhcy7lcmnx14jrinmh6vhanx8rh79-profile/lib/libgirepository-1.0.so:
> > > undefined symbol: g_callable_info_create_closure"
>
> I pushed a fix to the master branch.
>
> Thanks for the report,
> David