<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Here is one more alternative: </div><div><br></div><div><div><div>#lang racket</div><div><br></div><div>;; you can move the body of this module into a '#lang racket' file called fuzzy-set-library.rkt </div><div>(module fuzzy-set-library racket </div><div> ;; rename-out is an elegant version of the let()/define-values trick in Realm of Racket </div><div> (provide (rename-out (fuzzy-set0 fuzzy-set)) (struct-out fuzzy-element))</div><div> </div><div> (struct fuzzy-element (val degree) #:transparent)</div><div> ;; FE = (fuzzy-element Any [0,1))</div><div> </div><div> (struct fuzzy-set (vals) </div><div> #:transparent </div><div> #:guard </div><div> ;; [List-of FE] -> Fuzzy-set</div><div> (lambda (le type-name)</div><div> (define-values (members _)</div><div> (for/fold ((s '()) (keys '())) ((x le))</div><div> (unless (fuzzy-element? x) </div><div> (error type-name "fuzzy-element expected, given: ~e" x))</div><div> (define k (fuzzy-element-val x))</div><div> (if (member k keys)</div><div> (values s keys)</div><div> (values (cons x s) (cons k keys)))))</div><div> (apply set members)))</div><div> ;; FuzzySet = (fuzzy-set [Set-of FE])</div><div> </div><div> (define (fuzzy-set0 . x) ;; <--- this means take as many arguments as there are, as a list </div><div> (fuzzy-set x))</div><div> </div><div> ;; add</div><div> ;; -- fuzzy-add-element </div><div> ;; -- fuzzy-union </div><div> ;; etc.</div><div> )</div><div><br></div><div>;; this could be a '#lang racket' file too</div><div>(module fuzzy-set-client racket </div><div> ;; then you replace this with the usual require </div><div> (require (submod ".." fuzzy-set-library))</div><div><br></div><div> (fuzzy-set</div><div> (fuzzy-element 'a .1)</div><div> (fuzzy-element 'b .2)</div><div> (fuzzy-element 'c .3)</div><div> (fuzzy-element 'a .3)))</div><div><br></div><div>;; drop this, it exists to test </div><div>(require 'fuzzy-set-client)</div></div></div><div><br></div><div><br></div><br><div><div>On Aug 23, 2013, at 3:49 PM, Rian Shams wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Hello All,<br></div><div><br></div><div style="">My name is Rian and I am a new Racket user and a novice programmer (Racket is my first language). First let me say that I am very grateful for the resources available online and the books, HTDP and Realm of Racket. I find your teaching methods very clear and as a result I am picking up Racket faster than I originally thought.</div>
<div style=""><br></div><div style="">I am a System Science graduate student whose primary research focus is on Fuzzy Set Theory. A fuzzy set is a collection of distinct elements where each element has a degree of membership associated with it. </div>
<div style=""><br></div><div style="">The representation I am currently using for a fuzzy set is the following:</div><div style="">First I create a struct called fuzzy-element which consists of 2 fields; the first is the name of the element and the second is the elements degree of membership to the set which ranges from 0 to 1.</div>
<div style=""><br></div><div style="">;; Data Definition</div><div style=""><br></div><div>#lang racket</div><div><br></div><div>(struct fuzzy-element (member degree-of-membership) </div><div> #:transparent</div><div> #:guard (lambda (member degree-of-membership type-name)</div>
<div> (cond</div><div> [(not (and (number? degree-of-membership)</div><div> (<= 0 degree-of-membership 1) degree-of-membership))</div><div> (error type-name</div>
<div> "~e is not a number between 0 and 1"</div><div> degree-of-membership)]</div><div> [else (values member degree-of-membership)])))</div><div>
<br></div><div>;; fuzzy-element is (fuzzy-element Symbol Number[0, 1])</div><div>;; interp. a fuzzy-element as a struct in which:</div><div>;; -the first field is the member's name</div>
<div>;; -the second field is the respective members degree of membership</div><div><br></div><div style="">Then I combine them with a list so what I have now is a list of fuzzy elements.</div><div><br></div><div><div>
;; ListOfFuzzyElement is one of:</div><div>;; - empty</div><div>;; - (cons fuzzy-element ListOfFuzzyElement)</div></div><div><br></div><div style="">The problem with this data definition is that it allows for duplicate structs with the same field-1 elements.</div>
<div style=""><br></div><div style="">What I am looking to create is</div><div><br></div><div>;; A Fuzzy-Set is one of:</div><div>;; - empty list</div><div>;; - (cons <b>distinct</b> fuzzy-element ListOfFuzzyElement)</div><div>
<br></div><div><br></div><div><div><br></div><div><div>Ideally the type of representation I would like to use should look like: </div><div><br></div><div><div>(fuzzy-set (fuzzy-element 'a .1)</div><div> (fuzzy-element 'b .2)</div>
<div> (fuzzy-element 'c .3)</div><div> (fuzzy-element 'a .3))</div><div><br></div><div>-> (fuzzy-set (fuzzy-element 'a .1)</div><div> (fuzzy-element 'b .2)</div>
<div> (fuzzy-element 'c .3))</div></div><div><br></div><div style="">Upon evaluation, the last element, (fuzzy-element 'a .3) is deleted because there already exists a member named 'a (fuzzy-element 'a .1). It should work exactly like the built in "set" data type, except in this case it is a set of structures that checks the first fields of all structures and eliminates latter duplicates. </div>
</div><div><br></div><div style="">Any guidance on how to create fuzzy-set representation this way or if you can suggest more concise and elegant methods I would be greatly appreciative. </div><div><br></div><div style="">Thanks,</div>
-- <br>Rian Shams
</div></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>