public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* How to set procedure name in macros
@ 2017-01-01 23:00 Duncan Mak
  2017-01-02  0:37 ` Per Bothner
  2017-01-02 14:17 ` Per Bothner
  0 siblings, 2 replies; 5+ messages in thread
From: Duncan Mak @ 2017-01-01 23:00 UTC (permalink / raw)
  To: kawa mailing list

Hello all,

Happy new year!

In my DEFINE-FOO macro and I noticed that I can't control the name of
the lambda in the syntax expansion.

Here's a test case -

(define-syntax define-a
  (lambda (stx)
    (syntax-case stx ()
      ((_ name) #`(define name (lambda () #f))))))

(define-syntax define-bar
  (lambda (stx)
    (syntax-case stx ()
      ((_ name) #`(define name (lambda () name: 'bar #f))))))

(define-syntax define-c
  (lambda (stx)
    (syntax-case stx ()
      ((_ name) #`(define name (letrec ((foo (lambda () name: name
#f))) foo))))))

(define-syntax define-d
  (lambda (stx)
    (syntax-case stx ()
      ((_ name) #`(define name (letrec ((foo (lambda () #f)))
(set-procedure-property! foo 'name name) foo))))))

(define-a a)
(format #t "Should say a: ~A~%" (procedure-property a 'name))
(define-bar b)
(format #t "Should say bar: ~A~%" (procedure-property b 'name))
(define-c c)
(format #t "Should say c: ~A~%" (procedure-property c 'name))
(define-d d)
(format #t "Should say d: ~A~%" (procedure-property d 'name))

The output looks like this:

Should say a: a
Should say bar: b
Should say c: foo
Should say d: foo

I'm particularly interested in the C or D cases.

Thanks!


-- 
Duncan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to set procedure name in macros
  2017-01-01 23:00 How to set procedure name in macros Duncan Mak
@ 2017-01-02  0:37 ` Per Bothner
  2017-01-02  2:51   ` Duncan Mak
  2017-01-02 14:17 ` Per Bothner
  1 sibling, 1 reply; 5+ messages in thread
From: Per Bothner @ 2017-01-02  0:37 UTC (permalink / raw)
  To: Duncan Mak, kawa mailing list



On 01/01/2017 02:59 PM, Duncan Mak wrote:
> Hello all,
>
> Happy new year!
>
> In my DEFINE-FOO macro and I noticed that I can't control the name of
> the lambda in the syntax expansion.

This works:

(define-syntax define-d
   (lambda (stx)
     (syntax-case stx ()
       ((_ n) #`(define n (letrec ((foo (lambda () #f)))
                                  (set-procedure-property! foo 'name 'n)
                                  foo))))))

First, you needs to quite the property value.
Secondly, you should not use the same identifier for the syntax parameter
as the name" keyword.

I'm not clear why the following doesn't work - I'm looking into it.

(define-syntax define-c
   (lambda (stx)
     (syntax-case stx ()
       ((_ n) #`(define n (letrec ((foo (lambda () name: 'n
                                                #f)))
                            foo))))))

-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to set procedure name in macros
  2017-01-02  0:37 ` Per Bothner
@ 2017-01-02  2:51   ` Duncan Mak
  2017-01-02  2:54     ` Duncan Mak
  0 siblings, 1 reply; 5+ messages in thread
From: Duncan Mak @ 2017-01-02  2:51 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa mailing list

Hello Per,

I'm running the Kawa 2.2 release jars and define-d didn't work for me.
It still says 'foo'.

Perhaps it's a fix that hasn't made it to a released build?

Looking forward to Kawa 2.3 ;-)



Duncan.

On Sun, Jan 1, 2017 at 7:37 PM, Per Bothner <per@bothner.com> wrote:
>
>
> On 01/01/2017 02:59 PM, Duncan Mak wrote:
>>
>> Hello all,
>>
>> Happy new year!
>>
>> In my DEFINE-FOO macro and I noticed that I can't control the name of
>> the lambda in the syntax expansion.
>
>
> This works:
>
> (define-syntax define-d
>   (lambda (stx)
>     (syntax-case stx ()
>       ((_ n) #`(define n (letrec ((foo (lambda () #f)))
>                                  (set-procedure-property! foo 'name 'n)
>                                  foo))))))
>
> First, you needs to quite the property value.
> Secondly, you should not use the same identifier for the syntax parameter
> as the name" keyword.
>
> I'm not clear why the following doesn't work - I'm looking into it.
>
> (define-syntax define-c
>   (lambda (stx)
>     (syntax-case stx ()
>       ((_ n) #`(define n (letrec ((foo (lambda () name: 'n
>                                                #f)))
>                            foo))))))
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/



-- 
Duncan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to set procedure name in macros
  2017-01-02  2:51   ` Duncan Mak
@ 2017-01-02  2:54     ` Duncan Mak
  0 siblings, 0 replies; 5+ messages in thread
From: Duncan Mak @ 2017-01-02  2:54 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa mailing list

Oh sorry, I sent prematurely, define-d does work in Kawa 2.2.

Thanks!

On Sun, Jan 1, 2017 at 9:49 PM, Duncan Mak <duncanmak@gmail.com> wrote:
> Hello Per,
>
> I'm running the Kawa 2.2 release jars and define-d didn't work for me.
> It still says 'foo'.
>
> Perhaps it's a fix that hasn't made it to a released build?
>
> Looking forward to Kawa 2.3 ;-)
>
>
>
> Duncan.
>
> On Sun, Jan 1, 2017 at 7:37 PM, Per Bothner <per@bothner.com> wrote:
>>
>>
>> On 01/01/2017 02:59 PM, Duncan Mak wrote:
>>>
>>> Hello all,
>>>
>>> Happy new year!
>>>
>>> In my DEFINE-FOO macro and I noticed that I can't control the name of
>>> the lambda in the syntax expansion.
>>
>>
>> This works:
>>
>> (define-syntax define-d
>>   (lambda (stx)
>>     (syntax-case stx ()
>>       ((_ n) #`(define n (letrec ((foo (lambda () #f)))
>>                                  (set-procedure-property! foo 'name 'n)
>>                                  foo))))))
>>
>> First, you needs to quite the property value.
>> Secondly, you should not use the same identifier for the syntax parameter
>> as the name" keyword.
>>
>> I'm not clear why the following doesn't work - I'm looking into it.
>>
>> (define-syntax define-c
>>   (lambda (stx)
>>     (syntax-case stx ()
>>       ((_ n) #`(define n (letrec ((foo (lambda () name: 'n
>>                                                #f)))
>>                            foo))))))
>>
>> --
>>         --Per Bothner
>> per@bothner.com   http://per.bothner.com/
>
>
>
> --
> Duncan.



-- 
Duncan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to set procedure name in macros
  2017-01-01 23:00 How to set procedure name in macros Duncan Mak
  2017-01-02  0:37 ` Per Bothner
@ 2017-01-02 14:17 ` Per Bothner
  1 sibling, 0 replies; 5+ messages in thread
From: Per Bothner @ 2017-01-02 14:17 UTC (permalink / raw)
  To: Duncan Mak, kawa mailing list

I checked in a fix for the following.
I also checked in a testcase based on yours in testsuite/reflect-fname.scm.  Thanks!

On 01/01/2017 02:59 PM, Duncan Mak wrote:
> Hello all,
>
> Happy new year!
>
> In my DEFINE-FOO macro and I noticed that I can't control the name of
> the lambda in the syntax expansion.
>
> Here's a test case -
>
> (define-syntax define-a
>   (lambda (stx)
>     (syntax-case stx ()
>       ((_ name) #`(define name (lambda () #f))))))
>
> (define-syntax define-bar
>   (lambda (stx)
>     (syntax-case stx ()
>       ((_ name) #`(define name (lambda () name: 'bar #f))))))
>
> (define-syntax define-c
>   (lambda (stx)
>     (syntax-case stx ()
>       ((_ name) #`(define name (letrec ((foo (lambda () name: name
> #f))) foo))))))
>
> (define-syntax define-d
>   (lambda (stx)
>     (syntax-case stx ()
>       ((_ name) #`(define name (letrec ((foo (lambda () #f)))
> (set-procedure-property! foo 'name name) foo))))))
>
> (define-a a)
> (format #t "Should say a: ~A~%" (procedure-property a 'name))
> (define-bar b)
> (format #t "Should say bar: ~A~%" (procedure-property b 'name))
> (define-c c)
> (format #t "Should say c: ~A~%" (procedure-property c 'name))
> (define-d d)
> (format #t "Should say d: ~A~%" (procedure-property d 'name))
>
> The output looks like this:
>
> Should say a: a
> Should say bar: b
> Should say c: foo
> Should say d: foo
>
> I'm particularly interested in the C or D cases.
>
> Thanks!
>
>

-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-02 14:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-01 23:00 How to set procedure name in macros Duncan Mak
2017-01-02  0:37 ` Per Bothner
2017-01-02  2:51   ` Duncan Mak
2017-01-02  2:54     ` Duncan Mak
2017-01-02 14:17 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).