Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

defines otp-value as a protocol and not a multimethod

  • Loading branch information...
commit a8dd46d963cc1e30d1453af9ff0651dc4d1dcc53 1 parent 4b141a7
Alvaro Videla authored August 17, 2010

Showing 1 changed file with 57 additions and 28 deletions. Show diff stats Hide diff stats

  1. 85  src/closerl/core.clj
85  src/closerl/core.clj
@@ -30,34 +30,63 @@
30 30
     (try (Integer/parseInt s) 
31 31
          (catch NumberFormatException nfe 0)))
32 32
 
33  
-(defmulti otp-value class)
34  
-
35  
-(defmethod otp-value OtpErlangBoolean [o] (.booleanValue o))
36  
-(defmethod otp-value OtpErlangAtom    [o] (.atomValue o))
37  
-
38  
-(defmethod otp-value OtpErlangBinary  [o] (String. (.binaryValue o)))
39  
-
40  
-(defmethod otp-value OtpErlangChar    [o] (parse-integer (str o)))
41  
-(defmethod otp-value OtpErlangByte    [o] (parse-integer (str o)))
42  
-(defmethod otp-value OtpErlangShort   [o] (parse-integer (str o)))
43  
-(defmethod otp-value OtpErlangUShort  [o] (parse-integer (str o)))
44  
-(defmethod otp-value OtpErlangInt     [o] (parse-integer (str o)))
45  
-(defmethod otp-value OtpErlangUInt    [o] (parse-integer (str o)))
46  
-(defmethod otp-value OtpErlangLong    [o]
47  
-  (if (.isLong o)
48  
-      (.longValue  o)
49  
-      (.bigIntegerValue o)))
50  
-(defmethod otp-value OtpErlangFloat   [o] (float (.floatValue o)))
51  
-(defmethod otp-value OtpErlangDouble  [o] (float (.floatValue o)))
52  
-(defmethod otp-value OtpErlangString  [o] (str (.stringValue o)))
53  
-(defmethod otp-value OtpErlangList    [o] (with-meta (map otp-value (.elements o)) {:otp-type "List"}))
54  
-(defmethod otp-value OtpErlangTuple   [o] (with-meta (map otp-value (.elements o)) {:otp-type "Tuple"}))
55  
-(defmethod otp-value nil              [o] "")
56  
-(defmethod otp-value OtpErlangObject  [o] o)
57  
-
58  
-(defmulti  as-seq class)
59  
-(defmethod as-seq OtpErlangList  [o] (seq (.elements o)))
60  
-(defmethod as-seq OtpErlangTuple [o] (seq (.elements o)))
  33
+(defprotocol FromErlang
  34
+  (otp-value [val]))
  35
+  
  36
+(extend-protocol FromErlang
  37
+  OtpErlangBoolean
  38
+  (otp-value [o] (.booleanValue o))
  39
+  
  40
+  OtpErlangAtom
  41
+  (otp-value [o] (.atomValue o))
  42
+  
  43
+  OtpErlangBinary
  44
+  (otp-value [o] (String. (.binaryValue o)))
  45
+  
  46
+  OtpErlangChar
  47
+  (otp-value [o] (parse-integer (str o)))
  48
+  
  49
+  OtpErlangByte
  50
+  (otp-value [o] (parse-integer (str o)))
  51
+  
  52
+  OtpErlangShort
  53
+  (otp-value [o] (parse-integer (str o)))
  54
+  
  55
+  OtpErlangUShort
  56
+  (otp-value [o] (parse-integer (str o)))
  57
+  
  58
+  OtpErlangInt
  59
+  (otp-value [o] (parse-integer (str o)))
  60
+  
  61
+  OtpErlangUInt
  62
+  (otp-value [o] (parse-integer (str o)))
  63
+  
  64
+  OtpErlangLong
  65
+  (otp-value [o]
  66
+    (if (.isLong o)
  67
+        (.longValue  o)
  68
+        (.bigIntegerValue o)))
  69
+  
  70
+  OtpErlangFloat
  71
+  (otp-value [o] (float (.floatValue o)))
  72
+  
  73
+  OtpErlangDouble
  74
+  (otp-value [o] (float (.floatValue o)))
  75
+  
  76
+  OtpErlangString
  77
+  (otp-value [o] (str (.stringValue o)))
  78
+  
  79
+  OtpErlangList
  80
+  (otp-value [o] (with-meta (map otp-value (.elements o)) {:otp-type "List"}))
  81
+  
  82
+  OtpErlangTuple
  83
+  (otp-value [o] (with-meta (map otp-value (.elements o)) {:otp-type "Tuple"}))
  84
+  
  85
+  OtpErlangObject
  86
+  (otp-value [o] o)
  87
+  
  88
+  nil
  89
+  (otp-value [o] ""))
61 90
 
62 91
 (defn otp-node
63 92
   "Creates an OtpNode"

0 notes on commit a8dd46d

Please sign in to comment.
Something went wrong with that request. Please try again.