<< Back to previous view

[ALGOM-2] Adding support for both :if-:then-:else and :cond statements on domacro implementations Created: 21/Jan/12  Updated: 24/Jan/12

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

Type: Enhancement Priority: Major
Reporter: Roman Gonzalez Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Mac OS X Lion


Attachments: File monadic-cond.diff     Text File monadic-cond.patch    
Patch: Code and Test

 Description   

This patch contains the same features as

http://dev.clojure.org/jira/browse/ALGOM-1

plus a new one, the ability to add :cond statements using the domonad macro.

More info can be found on the commit history of the given patch.



 Comments   
Comment by Roman Gonzalez [ 24/Jan/12 11:15 AM ]

This is a new version of the patch that handles the conflicts with whitespaces vs tabs.





[ALGOM-7] maybe-m breaks the monad laws. Created: 15/Sep/12  Updated: 15/Sep/12

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

Type: Defect Priority: Major
Reporter: Seth J. Gold Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: None


 Description   

One of the monad laws is that (m-bind (m-result v) f) should be the same as (f v). However, this is not the case in maybe-m:

user=> (with-monad maybe-m (m-bind (m-result nil) nil?))
nil

user=> (nil? nil)
true

The crux of the problem is that in algo.monad's maybe-m, there is no way to wrap a nil in a Just-like container.



 Comments   
Comment by Seth J. Gold [ 15/Sep/12 3:27 PM ]

Just realized that that demonstration doesn't actually work, because the function passed to m-bind is supposed to return a monadic value. Here's a better one:

user=> (with-monad maybe-m (m-bind (m-result nil) (comp m-result nil?)))
nil
user=> (with-monad maybe-m ((comp m-result nil?) nil))
true





[ALGOM-1] Add conditionals stratements to domonad forms Created: 06/Jan/12  Updated: 10/Jan/12

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

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

The extension was developed in Mac OS X Lion


Attachments: File monadic-if-else.diff    
Patch: Code

 Description   

I implemented a patch that would allow us to do conditionals on domonad macros

Example:

(domonad monad-m
[a (action 1)
:if (= a 3)
:then [
result (action c)
]
:else [
result (action d)
]]
result)

Conditional blocks can be nested.

One gotcha one has to be aware of is: you may use bindings from a conditional branch in the m-result sexp as long as that branch gets called, given that one doesn't know for sure which branch is going to be called, you should set the same bindings on both branches.

The patch code is on: github.com/roman/algo.monads

I didn't do a pull request given that you need to this first.

NOTE: I've added this feature in some other projects I've been working on (parser combinators) and is working perfectly so far, there is tests in the patch but I wanted to give you that safe net as well.



 Comments   
Comment by Roman Gonzalez [ 10/Jan/12 12:28 AM ]

Adding support for monadic conditionals on the domonad macro





[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")]
}}






[ALGOM-4] algo.monad state-m fetch-val bug and efficiency issue Created: 08/Sep/12  Updated: 08/Sep/12

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

Type: Defect Priority: Minor
Reporter: Sacha De Vos Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: bug, performance
Environment:

irrelevant



 Description   

;; the bug

(defn fetch-val
"Return a state-monad function that assumes the state to be a map and
returns the value corresponding to the given key. The state is not modified."
[key]
(domonad state-m
[s (fetch-state)]
(key s))) ;; does not work for integer or string keys

;; I propose replacing it with (get s key)

;; the efficiency issue :
;;
;; domonad with monad parameter binds all the monad functions,
;; looking these up in the state-m map on each call
;;
;; solution :

(defn fetch-val
"Return a state-monad function that assumes the state to be a map and
returns the value corresponding to the given key. The state is not modified."
[key]
(fn [s]
[(get s key) s]))

;; - we avoid the monad map lookups
;; - coding style brought up to par with the rest of state-m functions






[ALGOM-5] continuation monad can easily overflow stack Created: 10/Sep/12  Updated: 10/Sep/12

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

Type: Defect Priority: Minor
Reporter: ben wolfson Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: None


 Description   

The continuation monad uses tail calls, and because they aren't optimized out it's vulnerable to stack overflows for large computations:

;; there is a function clojure.algo.monads/m-reduce, but it has a
;; wierdly unuseful type.
(defmonadfn fold-m
[f a xs] (reduce (fn [macc x] (m-bind macc #(f % x))) (m-result a) xs))

(defn add [s]
(run-cont
(with-monad cont-m
(call-cc
(fn [k]
(fold-m (fn [a n]
(if (== n 8888) (k 1)
(m-result (+ a n))))
0 s))))))

(add (range 1 10000)) ;; stack overflow

Can be worked around with a trampoline:

(defmonad cont-tramp-m
[m-result m-result-cont
m-bind m-bind-cont])

(defn call-cc-tramp [f]
(fn [c] [(f (fn [v] (fn [_] [c v ::cont]))) c ::cont]))

(defn run-cont-tramp [cont]
(loop [cv (cont identity)]
(if (and (vector? cv)
(= ::cont (nth cv 2)))
(recur ((first cv) (second cv)))
cv)))

(defn add2 [s]
(run-cont-tramp
(with-monad cont-tramp-m
(call-cc-tramp
(fn [k]
(fold-m (fn [a n]
(if (= n 8888)
(k 1)
(m-result (+ a n))))
0 s))))))

(add2 (range 1 1000000)) ;; -> 1



 Comments   
Comment by ben wolfson [ 10/Sep/12 12:01 PM ]

I neglected to include m-result-cont and m-bind-cont for the cont-tramp-m call!

(defn m-result-cont [v] (fn [c] [c v ::cont]))

(defn m-bind-cont [mv f] (fn [c] [mv (fn [v] [(f v) c ::cont ]) ::cont]))





[ALGOM-6] algo.monads README has no artifacts information Created: 14/Sep/12  Updated: 14/Sep/12

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

Type: Enhancement Priority: Minor
Reporter: Andy Fingerhut Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: None


 Description   

algo.monads README has no artifacts information and does not conform to the Contrib README standards in any way. Because clojure-dev is a closed group, I am filing it here.

(originally filed by Michael Klishin in project CLJ, but seems to belong better here)






[ALGOM-9] Replace calls to deprecated functions Created: 28/Oct/12  Updated: 28/Oct/12

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

Type: Defect Priority: Minor
Reporter: Andy Fingerhut Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: None

Attachments: Text File algom-9-replace-calls-to-deprecated-fns-v1.txt    

 Description   

There are several calls to replicate, which was deprecated in Clojure 1.3. Recommended replacement is repeat, which was added in 1.0.



 Comments   
Comment by Andy Fingerhut [ 28/Oct/12 5:23 PM ]

algom-9-replace-calls-to-deprecated-fns-v1.txt dated Oct 28 2012 replaces calls to replicate with repeat.





[ALGOM-8] Cosmetic change in maybe-m Created: 12/Oct/12  Updated: 12/Oct/12

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

Type: Task Priority: Trivial
Reporter: Edward Tsech Assignee: Konrad Hinsen
Resolution: Unresolved Votes: 0
Labels: None

Attachments: Text File maybe-m-cosmetic.patch    

 Description   

Diff:
;- (if (nil? mv) nil (f mv)))
;+ (when-not (nil? mv) (f mv)))






Generated at Sat May 18 04:49:16 CDT 2013 using JIRA 4.4#649-r158309.