bugKawa - Bugs: bug #13821, problem with letrec and...

 
 

bug #13821: problem with letrec and define-macro

Submitted by:  None
Submitted on:  Sat 16 Jul 2005 09:18:08 PM UTC  
 
Category: Scheme languageSeverity: 3 - Normal
Item Group: Run-time exceptionStatus: Fixed
Privacy: PublicAssigned to: Per Bothner <bothner>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 21 Jul 2005 12:51:52 AM UTC, comment #1:

I checked in a fix for this.

Per Bothner <bothner>
Project AdministratorIn charge of this item.
Sat 16 Jul 2005 09:18:08 PM UTC, original submission:

In some cases letrec doesn't seem to be working with define-macro.
I haven't been able to find out why sometimes it works and sometimes it doesn't.

Here is a simple example that does not work (using the latest Kawa from CVS):

(define-macro (a-test #!key (args ()))
(letrec ((double (lambda (x) (* x 2))))
`(+ ,@(map double args))))

When I try it:

#|kawa:84|# (a-test)
0
#|kawa:85|# (a-test args: ())
0
#|kawa:86|# (a-test args: (1 2 3))
java.lang.NullPointerException
at atInteractiveLevel$37.lambda1$V(<stdin>:81)
at atInteractiveLevel$37.applyN(<stdin>)
at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:207)
at kawa.lang.Macro.expand(Macro.java:162)
at kawa.lang.Macro.scanForm(Macro.java:193)
at kawa.lang.Translator.scanForm(Translator.java:913)
at gnu.kawa.lispexpr.LispLanguage.parse(LispLanguage.java:59)
at kawa.Shell.run(Shell.java:203)
at kawa.Shell.run(Shell.java:172)
at kawa.Shell.run(Shell.java:159)
at kawa.repl.main(repl.java:673)
<stdin>:86:1: evaluating syntax transformer 'a-test' threw
java.lang.NullPointerException

This behavior seems to be quite random: some define-macro very similar to this one do work, but when I remove an unused (not called anywhere) lambda in the letrec they stop working! Sometimes even removing part of an unused lambda makes it fail. For example:

(define-macro (define-generator name #!key (fields ()) (generators ()))
(letrec ((create-field
(lambda (field)
(if (pair? field)
`(,(first field) init-value: ,(second field))
`(,field init-value: ()))))

(->slot-ref
(lambda (x)
(cond ((null? x) ())
((pair? x)
(cons (->slot-ref (car x)) (->slot-ref (cdr x))))
((symbol? x)
(if (member x fields)
`(slot-ref (this) ',x)
x))
(else x))))

(create-generator
(lambda (generator)
(let ((gname (car generator))
(gbody (cdr generator)))
`((,(string->symbol (string-append "gen-"
(symbol->string gname))))
;(->string-append ,@(map ->slot-ref gbody)))))))
(->string-append ,@gbody))))))

`(define-simple-class ,name ()
,@(map create-field fields)
,@(map create-generator generators))))

The I can do:

(define-generator some-test fields: (a b c))

and it works, but if I remove the unused ->slot-ref lambda then it fails!

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 3 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Thu 21 Jul 2005 12:51:52 AM UTCbothnerStatusNone=>Fixed
  Assigned toNone=>bothner
  Open/ClosedOpen=>Closed

Back to the top


Powered by Savane 3.1-cleanup1