Re: Help porting someone else's macro from 4 to 5.

2020-01-21 Thread kooda
Andrew Mack  wrote:
> Looking through various chicken documentation, my first assumption was
> to wrap the lambda argument to define-syntax in an er-macro-transformer
> call. However this does not recognize append-map (of course defined in
> srfi-1) as bound. I thought that it might also need to be renamed with
> (r 'append-map) but this also did not work. 
> 

Indeed you have to wrap the lambda into `er-macro-transformer`.

For the append-map issue, I’m pretty sure this means the srfi-1 library
is not loaded at macro-expand time, you can do so with
`(import-for-syntax srfi-1)`.
http://wiki.call-cc.org/man/5/Modules#import-for-syntax

Hope this helps. :)


Re: Help porting someone else's macro from 4 to 5.

2020-01-20 Thread megane


Andrew Mack  writes:

> Hello all, I'm attempting to port the sdl-mixer egg (originally by
> Christian Kellermann) from 4 to 5. I think I've made most of the
> necessary changes, but  I'm running into a bit of an issue and would
> greatly appreciate some help troubleshooting.

Hi, Andrew!
>
> I'm a bit new to Chicken and lisp in general, and while I feel I have a
> decent understanding of regular macros the er- and ir-macro-transformer
> procedures are still eluding me somewhat. In sdl-mixer's chicken 4
> source, we have the macro 
>
> (module sdl-mixer-lolevel 
>
> (import ... srfi-1 ...) 
>
> ... 
>
> (define-syntax --sdl-flags
>  (lambda (e r c)
>   `(,(r 'begin)
>  ,@(append-map (lambda (str)
  ^^
append-map is being called during syntax expansion time here. So,
instead of (import srfi-1) you need (import-for-syntax srfi-1).

> (let* ((sym (string->symbol str))
> (psym (string->symbol (string-append "-" str
>   `((,(r 'define-foreign-variable) ,psym unsigned-integer ,str)
> (,(r 'define) ,sym ,psym
> (cdr e) 
>
> ... 
>
> ) ; end module 
>
> Looking through various chicken documentation, my first assumption was
> to wrap the lambda argument to define-syntax in an er-macro-transformer
> call. However this does not recognize append-map (of course defined in
> srfi-1) as bound. I thought that it might also need to be renamed with
> (r 'append-map) but this also did not work. 
>
> Since I am new to Chicken, I assume its a misunderstanding on my part of
> what is necessary, but I cannot figure out where to go from here. So
> first of all, is my assumption that I need an er-macro-transformer
> correct, or am I barking up the wrong tree? Second, after resolving the
> first question what is the next step I need to take? Any help would be
> greatly appreciated.

You're correct in that you need to use er-macro-transformer from
(chicken syntax).

Alternatively you can use ir-macro-transformer:

(define-syntax --sdl-flags
  (ir-macro-transformer
   (lambda (e i c)
 `(begin
,@(append-map (lambda (str)
(let* ((sym (string->symbol str))
   (psym (i (string->symbol (string-append "-" 
str)
  `((define-foreign-variable ,psym unsigned-integer 
,str)
(define ,sym ,psym
  (cdr e))
>
> Thanks in advance, 
>
> Andrew Mack