Here's the interface I'm 
overriding: 
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IAtom.java

And I'm using clojure 1.8.0.

Oh. Interesting. I was using cursive for compiling, but switched to boot. 
Getting some interesting warnings now too:

WARNING: Bad method signature in protocol implementation, IDeref does not 
declare method called deref at line 90 src\cljc\aautil\dewdrop.cljc
WARNING: Bad method signature in protocol implementation, IAtom does not 
declare method called reset at line 90 src\cljc\aautil\dewdrop.cljc
WARNING: Bad method signature in protocol implementation, IAtom does not 
declare method called swap at line 90 src\cljc\aautil\dewdrop.cljc
WARNING: Bad method signature in protocol implementation, IAtom does not 
declare method called compareAndSet at line 90 src\cljc\aautil\dewdrop.cljc
             clojure.lang.ExceptionInfo: 
java.lang.IllegalArgumentException: Can't define method not in interfaces: 
compareAndSet, compiling:(aautil/dewdrop.cljc:90:1)
    data: {:file
          
 "C:\\Users\\Bill\\AppData\\Local\\Temp\\boot.user1581043804101612299.clj",
           :line 31}
java.util.concurrent.ExecutionException: 
java.lang.IllegalArgumentException: Can't define method not in interfaces: 
compareAndSet, compiling:(aautil/dewdrop.cljc:90:1)


So here's the whole thing:

(ns aautil.dewdrop
  #?(:clj (:require [clojure.string :as str]
                    [clojure.edn :refer [read-string]])
     :cljs (:require [clojure.string :as str]
             [cljs.reader :refer [read-string]]))
  #?(:clj (:refer-clojure :exclude [read-string]))
  #?(:clj (:import (clojure.lang IDeref IAtom))))

(defn new-lens
  "Create a new lens."
  [getter setter]
  {:getter getter :setter setter})

(defn lget
  "Extract an item from some data.
  Returns the extracted item."
  [lens data]
  ((:getter lens) data))

(defn lderef
  "Extract an item from data held by an atom.
  Returns the extracted item."
  [lens data-atom]
  (lget lens @data-atom))

(defn lset!
  "Revise some data with an item.
  Returns the revised data."
  [lens data item]
  ((:setter lens) data item))

(defn lreset!
  "Revise some data held by an atom with an item.
  Returns the revised data."
  [lens data-atom item]
  (reset! data-atom (lset! lens @data-atom item)))

(defn lupd!
  "Update an item in some data.
  Returns the revised data."
  [lens data f]
  (lset! lens data (f (lget lens data))))

(defn lswap!
  "Update an item in some data held by an atom.
  Returns the revised data."
  [lens data-atom f]
  (swap! data-atom
         (fn [data]
           (lupd! lens data f))))

(defn lcomp
  "Combine a lens with another."
  [left right]
  {:getter
   (fn [data] (lget left (lget right data)))
   :setter
   (fn [data item]
     (let [right-data (lget right data)
           left-data (lset! left right-data item)]
       (lset! right data left-data)))})

(defn key-lens
  "Builds a lens using get and assoc"
  [key]
  {:getter (fn [data] (get data key))
   :setter (fn [data item] (assoc data key item))})

(defn atom-key-lens
  "Builds a lens using get and assoc"
  [key-atom]
  {:getter (fn [data] (get data @key-atom))
   :setter (fn [data item] (assoc data @key-atom item))})

;A lens built using read-string and pr-str.
(def edn-lens
  {:getter read-string
   :setter (fn [_ item] (pr-str item))})

(defn printing-lens
  "A lens for debugging"
  [id]
  {:getter (fn [item]
             (println id :got item)
             item)
   :setter (fn [data item]
             (println id :set data item)
             item)})

(defrecord lens-view [lens data-atom]
  IDeref
  (deref [this] (lderef lens data-atom))
  IAtom
  (reset [this item] (lreset! lens data-atom item))
  (swap [this f] (lswap! lens data-atom f))
  (swap [this f arg]
    (swap! data-atom
           (fn [data]
             (lset! lens data (f (lget lens data) arg)))))
  (swap [this f arg1 arg2]
    (swap! data-atom
           (fn [data]
             (lset! lens data (f (lget lens data) arg1 arg2)))))
  (swap [this f x y args]
    (swap! data-atom
           (fn [data]
             (lset! lens data (apply f (lget lens data) x y args)))))
  (^Boolean compareAndSet [oldv newv]
    (swap! data-atom
           (fn [data]
             (let [v (lget lens data)]
               (if (= oldv v)
                 (lset! lens data newv)
                 data)))))
  )

(defn lview [lens data-atom]
  (->lens-view lens data-atom))


On Wednesday, February 3, 2016 at 3:18:34 PM UTC-5, William la Forge wrote:
>
> Having a bit of a problem implementing the IAtom interface in a record. 
> Specifically, this is the signature giving me grief:
>
> boolean compareAndSet(Object oldv, Object newv);
>
> This isn't the answer:
>
> (^boolean compareAndSet [oldv newv] ... )
>
>
> I get "Can't define method not in interfaces: compareAndSet".
>
> Any ideas? Thanks!
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to