Re: [Chicken-users] is it possible to define expand-time values?

2019-05-05 Thread Peter Bex
On Sat, May 04, 2019 at 09:06:08PM +0200, Marco Maggi wrote:
> That  example just  shows the  mechanism, and  it is  not really  a good
> example (I wrote it).  What I  am thinking of, as reference scenario, is
> an infix-to-prefix macro  with infrastructure that allows  to define new
> binary operators, in which the operator name is not necessarily equal to
> the name of the function that implements the operation itself.
> 
>   So it should go like this:
> 
>(define (spiffy-operation X Y)
>  (do-something-spiffy-with X Y))
> 
>(define-infix-binary-operator spiffy
>  (right-binding-power 55)
>  ...
>  (procedure spiffy-operation))
> 
>(infix 2 * 3 + 88 spiffy 99)

I don't quite understand this example.  Nevertheless, I still get
the feeling that this is a concept that's unnecessary.

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] is it possible to define expand-time values?

2019-05-04 Thread Marco Maggi
Peter Bex wrote:

> On Sat, May 04, 2019 at 03:56:12PM +0200, Marco Maggi wrote:
>> ...  in CHICKEN  5.0.0  or in  a  future release?   I  can find  nothing
>> relevant on the CHICKEN Wiki.  Here what they should do:

>> 

>> it would open a can of worms^H^H^H^H^H possibilities.

> Hi Marco,

> This seems like a superfluous feature to me.

> To give an example of the first example on the page you linked,
> I would use this in a begin-for-syntax, like so:

> (begin-for-syntax
>   (define obj1 (+ 1 2 3)))

> (define-syntax get-obj1
>   (er-macro-transformer
> (lambda (e r c)
>   obj1)))

> (get-obj1) => 6

> Maybe I'm missing something, but this seems much simpler to me.

That  example just  shows the  mechanism, and  it is  not really  a good
example (I wrote it).  What I  am thinking of, as reference scenario, is
an infix-to-prefix macro  with infrastructure that allows  to define new
binary operators, in which the operator name is not necessarily equal to
the name of the function that implements the operation itself.

  So it should go like this:

   (define (spiffy-operation X Y)
 (do-something-spiffy-with X Y))

   (define-infix-binary-operator spiffy
 (right-binding-power 55)
 ...
 (procedure spiffy-operation))

   (infix 2 * 3 + 88 spiffy 99)

the  use of  the macro  DEFINE-INFIX-BINARY-OPERATOR should  expand into
something like:

   (define-syntax spiffy
 (make-expand-time-value
   (make-infix-operator 55 ... spiffy-operation)))

and the macro INFIX should parse  its input form and retrieve the record
instance of type "infix-operator" with code like:

   (if (expand-time-value? token)
   (let ((etv (retrieve-expand-time-value token)))
 (if (infix-operator? etv)
 (process-the-operator etv)
   ---))
 ---)

  I  think that  Racket's implementation  of the  infix-to-prefix syntax
does something like this (I have not checked).

  Another  use  case,  if  the  identifier ""  is  bound  to  an
appropriate expand-time value, we could expand.

   (define* (doit {X } {Y })
 ---)

into:

   (define (doit X Y)
 (assert (fixnum? X))
 (assert (fixnum? Y))
 ---)

-- 
Marco Maggi

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


Re: [Chicken-users] is it possible to define expand-time values?

2019-05-04 Thread Marco Maggi
Marco Maggi wrote:

> ...  in CHICKEN  5.0.0  or in  a  future release?   I  can find  nothing
> relevant on the CHICKEN Wiki.  Here what they should do:

> 

> it would open a can of worms^H^H^H^H^H possibilities.

Lame self reply.  I see I can do something similar with:

   (define-for-syntax ciao (list 1 2 3))

   (define-syntax hello
 (ir-macro-transformer
   (lambda (input x y)
 (let ((it (cadr input)))
(pretty-print (eval it))
1
   
   (hello ciao)

but EVAL uses are ugly (and dangerous).
-- 
Marco Maggi

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


Re: [Chicken-users] is it possible to define expand-time values?

2019-05-04 Thread Peter Bex
On Sat, May 04, 2019 at 03:56:12PM +0200, Marco Maggi wrote:
> ...  in CHICKEN  5.0.0  or in  a  future release?   I  can find  nothing
> relevant on the CHICKEN Wiki.  Here what they should do:
> 
> 
> 
> it would open a can of worms^H^H^H^H^H possibilities.

Hi Marco,

This seems like a superfluous feature to me.

To give an example of the first example on the page you linked,
I would use this in a begin-for-syntax, like so:

(begin-for-syntax
  (define obj1 (+ 1 2 3)))

(define-syntax get-obj1
  (er-macro-transformer
(lambda (e r c)
  obj1)))

(get-obj1) => 6

Maybe I'm missing something, but this seems much simpler to me.

Cheers,
Peter


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