Re: [Chicken-users] Defining defmacro using define-syntax

2019-05-14 Thread Juergen Lorenz
Hi all,

yes, there is a simple way: (import procedural-macros) and you'll have
not only a hygienic (if you want so) define-macro, but other procedural
macros and macro creators as well.

Cheers Juergen
> 
> The FermaT program transformation system is implemented in WSL
> and translated to Scheme for compiling or interpreting.
> 
> It was originally developed using SCM scheme which uses defmacro
> to define macros, eg:
> 
> (defmacro floop (name . body)
>   `(call-with-current-continuation
>  (lambda (,name)
>(do () (#f #t)
>   ,@body
> 
> (defmacro pop (v1 v2)
>   `(begin
>  (set! ,v1 (car ,v2))
>  (set! ,v2 (cdr ,v2
> 
> (defmacro push (v e)
>   `(set! ,v (cons ,e ,v)))
> 
> I am trying to port it to other Scheme versions. For bigloo
> I can use define-macro to define defmacro as a macro:
> 
> (define-macro (defmacro name . forms)
>   \`(define-macro (,name . ,(car forms)) ,\@(cdr forms)))
> 
> Chicken scheme does not appear to have defmacro or define-macro
> but does have define-syntax.
> 
> Is there a way to define defmacro using define-syntax?
> 
> -- 
>   Martin
> 
> Dr Martin Ward | Email: mar...@gkc.org.uk | http://www.gkc.org.uk
> G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4
> 
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users

-- 

Dr. Juergen Lorenz
Gruener Weg 27
29471 Gartow



signature.asc
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Defining defmacro using define-syntax

2019-05-13 Thread Martin Ward

On 13/05/19 19:35, Peter Bex wrote:

On Mon, May 13, 2019 at 07:11:40PM +0100, Martin Ward wrote:

Chicken scheme does not appear to have defmacro or define-macro
but does have define-syntax.

Is there a way to define defmacro using define-syntax?


This is of course highly discouraged (because defmacro is
inherently unhygienic), but you can do:

(import (chicken syntax))

(define-syntax defmacro
  (syntax-rules ()
((_ ?name ?args ?body ...)
 (define-syntax ?name
   (er-macro-transformer
 (lambda (e r c)
   (apply (lambda ?args ?body ...) (cdr e


That works, thanks! :-)

--
Martin

Dr Martin Ward | Email: mar...@gkc.org.uk | http://www.gkc.org.uk
G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Defining defmacro using define-syntax

2019-05-13 Thread Martin Ward

On 13/05/19 19:28, Phil Bewig wrote:

 From the Standard Prelude  at my
blog :

(define-syntax (define-macro x)
   (syntax-case x ()
 ((_ (name . args) . body)
   (syntax (define-macro name (lambda args . body
 ((_ name transformer)
   (syntax
(define-syntax (name y)
  (syntax-case y ()
((_ . args)
  (datum->syntax-object
(syntax _)
(apply transformer
  (syntax-object->datum (syntax args)))



This gives the following error:

% csi
CHICKEN
(c) 2008-2018, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 5.0.0 (rev 12f2f2cc)
linux-unix-gnu-x86-64 [ 64bit dload ptables ]

#;1> (define-syntax (define-macro x)
  (syntax-case x ()
((_ (name . args) . body)
  (syntax (define-macro name (lambda args . body
((_ name transformer)
  (syntax
   (define-syntax (name y)
 (syntax-case y ()
   ((_ . args)
 (datum->syntax-object
   (syntax _)
   (apply transformer
 (syntax-object->datum (syntax args)))

Error: during expansion of (define-syntax ...) - in `define-syntax' - 
symbol expected: (define-syntax (define-macro x) (syntax-case x () ((_ 
(name . args) . body) (syntax (define-macro name (lambda args . body 
((_ name transformer) (syntax (define-syntax (name y) (syntax-case y () 
((_ . args) (datum->syntax-object (syntax _) (apply transformer 
(syntax-object->datum (syntax args)))


Call history:

  (define-syntax (define-macro x) (syntax-case 
x () ((_ (name . args) . body) (syntax (define-macro na... <--

#;1>


--
Martin

Dr Martin Ward | Email: mar...@gkc.org.uk | http://www.gkc.org.uk
G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Defining defmacro using define-syntax

2019-05-13 Thread Peter Bex
On Mon, May 13, 2019 at 07:11:40PM +0100, Martin Ward wrote:
> Chicken scheme does not appear to have defmacro or define-macro
> but does have define-syntax.
> 
> Is there a way to define defmacro using define-syntax?

This is of course highly discouraged (because defmacro is
inherently unhygienic), but you can do:

(import (chicken syntax))

(define-syntax defmacro
  (syntax-rules ()
((_ ?name ?args ?body ...) 
 (define-syntax ?name
   (er-macro-transformer
 (lambda (e r c)
   (apply (lambda ?args ?body ...) (cdr e

Cheers,
Peter


signature.asc
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Defining defmacro using define-syntax

2019-05-13 Thread Phil Bewig
>From the Standard Prelude 
at my blog :

(define-syntax (define-macro x)
  (syntax-case x ()
((_ (name . args) . body)
  (syntax (define-macro name (lambda args . body
((_ name transformer)
  (syntax
   (define-syntax (name y)
 (syntax-case y ()
   ((_ . args)
 (datum->syntax-object
   (syntax _)
   (apply transformer
 (syntax-object->datum (syntax args)))

On Mon, May 13, 2019 at 1:24 PM Martin Ward  wrote:

>
> The FermaT program transformation system is implemented in WSL
> and translated to Scheme for compiling or interpreting.
>
> It was originally developed using SCM scheme which uses defmacro
> to define macros, eg:
>
> (defmacro floop (name . body)
>`(call-with-current-continuation
>   (lambda (,name)
> (do () (#f #t)
>,@body
>
> (defmacro pop (v1 v2)
>`(begin
>   (set! ,v1 (car ,v2))
>   (set! ,v2 (cdr ,v2
>
> (defmacro push (v e)
>`(set! ,v (cons ,e ,v)))
>
> I am trying to port it to other Scheme versions. For bigloo
> I can use define-macro to define defmacro as a macro:
>
> (define-macro (defmacro name . forms)
>\`(define-macro (,name . ,(car forms)) ,\@(cdr forms)))
>
> Chicken scheme does not appear to have defmacro or define-macro
> but does have define-syntax.
>
> Is there a way to define defmacro using define-syntax?
>
> --
> Martin
>
> Dr Martin Ward | Email: mar...@gkc.org.uk | http://www.gkc.org.uk
> G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4
>
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] Defining defmacro using define-syntax

2019-05-13 Thread Martin Ward



The FermaT program transformation system is implemented in WSL
and translated to Scheme for compiling or interpreting.

It was originally developed using SCM scheme which uses defmacro
to define macros, eg:

(defmacro floop (name . body)
  `(call-with-current-continuation
 (lambda (,name)
   (do () (#f #t)
  ,@body

(defmacro pop (v1 v2)
  `(begin
 (set! ,v1 (car ,v2))
 (set! ,v2 (cdr ,v2

(defmacro push (v e)
  `(set! ,v (cons ,e ,v)))

I am trying to port it to other Scheme versions. For bigloo
I can use define-macro to define defmacro as a macro:

(define-macro (defmacro name . forms)
  \`(define-macro (,name . ,(car forms)) ,\@(cdr forms)))

Chicken scheme does not appear to have defmacro or define-macro
but does have define-syntax.

Is there a way to define defmacro using define-syntax?

--
Martin

Dr Martin Ward | Email: mar...@gkc.org.uk | http://www.gkc.org.uk
G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users