bugKawa - Bugs: bug #48938, lambda cannot be cast to...

 
 

bug #48938: lambda cannot be cast to java.util.Comparator

Submitter:  Sakamoto Osamu <saka1029>
Submitted:  Mon 29 Aug 2016 02:48:59 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 30 Aug 2016 04:45:05 AM UTC, comment #2: 

I checked in fix, along with your testcase. Thanks!

Per Bothner <bothner>
Group administrator
Mon 29 Aug 2016 05:20:28 AM UTC, comment #1: 

I'm guessing this is because Comparator has an equals method, which Kawa doesn't realize has a default implementation (in Object).

Should be relatively easy to fix.

Per Bothner <bothner>
Group administrator
Mon 29 Aug 2016 02:48:59 AM UTC, original submission:  

I defined a macro.

(define-syntax ->
  (syntax-rules ()
     ((_ o)
      o)
     ((_ o (m a ...) r ...)
      (-> (invoke o 'm a ...) r ...))
     ((_ o f r ...)
      (-> (field o 'f) r ...))))

And I called java8 stream APIs.

#|kawa:68|# (-> [1 3 5 7 9 8 6 4 2]
#|(---:69|#     (stream)
#|(---:70|#     (filter (lambda (x) (<= x 5)))
#|(---:71|#     (sorted)
#|(---:72|#     (toArray))
[1 2 3 4 5]

It works fine.
But when I add an argument to 'sorted' method, it doesn't work.

#|kawa:73|# (-> [1 3 5 7 9 8 6 4 2]
#|(---:74|#     (stream)
#|(---:75|#     (filter (lambda (x) (<= x 5)))
#|(---:76|#     (sorted (lambda (a b) (- b a)))
#|(---:77|#     (toArray))
/dev/stdin:76:13: warning - type function is incompatible with required type java.util.Comparator
java.lang.ClassCastException: gnu.expr.ModuleMethod cannot be cast to java.util.Comparator
        at atInteractiveLevel-21.run(stdin:75)
        at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
        at gnu.expr.ModuleExp.evalModule(ModuleExp.java:212)
        at kawa.Shell.run(Shell.java:291)
        at kawa.Shell.run(Shell.java:203)
        at kawa.Shell.run(Shell.java:184)
        at kawa.repl.processArgs(repl.java:687)
        at kawa.repl.main(repl.java:793)


Sakamoto Osamu <saka1029>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by saka1029 (Submitted the item)
  • -email is unavailable- added by saka1029
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-01-16 bothner Open/ClosedOpen Closed
    2016-08-30 bothner StatusIn Progress Fixed
    2016-08-29 bothner StatusNone In Progress
        Assigned toNone bothner
    2016-08-29 saka1029 Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code