<< Back to previous view

[ALGOM-3] Bug in writer-monad-protocol for lists Created: 18/Apr/12  Updated: 18/Apr/12

Status: Open
Project: algo.monads
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Greg Chapman Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Clojure 1.4, Java 1.7, Windows 7


Attachments: File monads.clj.diff    

 Description   

The writer-monad-protocol for lists uses concat in writer-m-combine, the result of which has type LazySeq. However, LazySeq does not have an implementation in writer-monad-protocol (the first example, using vectors, shows expected output):

{{
user=> (use 'clojure.algo.monads)
nil
user=> (domonad (writer-m []) [_ (domonad [_ (write "foo")] nil) _ (write "bar")] 1)
[1 ["foo" "bar"]]
user=> (domonad (writer-m ()) [_ (domonad [_ (write "foo")] nil) _ (write "bar")] 1)
IllegalArgumentException No implementation of method: :writer-m-combine of protocol: #'clojure.algo.monads/writer-monad-
protocol found for class: clojure.lang.LazySeq clojure.core/-cache-protocol-fn (core_deftype.clj:527)
}}

I suggest changing the protocol extension to ISeq as in the attached diff. With that change:

{{
user=> (use 'clojure.algo.monads)
nil
user=> (domonad (writer-m []) [_ (domonad [_ (write "foo")] nil) _ (write "bar")] 1)
[1 ["foo" "bar"]]
user=> (domonad (writer-m ()) [_ (domonad [_ (write "foo")] nil) _ (write "bar")] 1)
[1 ("foo" "bar")]
}}


Generated at Sat May 18 18:15:26 CDT 2013 using JIRA 4.4#649-r158309.