~subsetpark/fugue

10dd0687976e4831319ffd2d99ca9a4490fc2128 — Zach Smith 6 months ago 5d73312
Test for bare table
3 files changed, 22 insertions(+), 13 deletions(-)

M README.md
M fugue.janet
M test/fugue.janet
M README.md => README.md +4 -4
@@ 100,7 100,7 @@ Extending an open multimethod (see `extend-multi`) from any other
environment makes the case extension available wherever the
multimethod has been imported.

[3]: fugue.janet#L572
[3]: fugue.janet#L579

## defgeneric



@@ 205,7 205,7 @@ repl:12:> (cat "hello" 100)
"hello #100"
```

[6]: fugue.janet#L496
[6]: fugue.janet#L503

## defproto



@@ 293,7 293,7 @@ See that function's documentation for full usage reference.
Whenever a case is added to `multi`, that case is available
wherever the multimethod is imported.

[8]: fugue.janet#L585
[8]: fugue.janet#L593

## fields



@@ 333,7 333,7 @@ Check to see if the types `args` match the sequence `arg-types`,
according to multimethod rules (ie, following prototype membership
and using `:_` as a fallback)

[11]: fugue.janet#L425
[11]: fugue.janet#L432

## prototype?


M fugue.janet => fugue.janet +10 -9
@@ 53,8 53,8 @@
           (put proto-allocations field ',name))
         (put-in object [:_meta :prototype-allocations]
                 (table/setproto
                  proto-allocations
                  (get-in parent [:_meta :prototype-allocations])))
                   proto-allocations
                   (get-in parent [:_meta :prototype-allocations])))

         (put-in object [:_meta :instance-defaults] ',instance-defaults)



@@ 122,7 122,7 @@
      # Assemble mapping of fields to default values for instances
      (when-let [default-value (attrs :default)]
        (put instance-defaults key-field (eval default-value))))
    

    [init-args proto-allocated-fields proto-allocations instance-defaults]))

(defn- getters


@@ 378,7 378,7 @@
                  sym
                  (type sym))
          evaled))))
    (tuple/slice (map f types)))
  (tuple/slice (map f types)))

(defn- put-case
  [name types fun store]


@@ 453,10 453,6 @@
          (break)))
      res)))

(defn- make-case
  [args body]
  (eval ~(fn ,args ,;body)))

(defn- construct-cond
  "Build main function logic of multimethod"
  [name cases args-symbol]


@@ 500,6 496,10 @@
     (set ((cell :ref) 0) f)
     (set (cell :doc) ,docstring)))

(defn- make-case
  [args body]
  (eval ~(fn ,args ,;body)))

(defmacro defmulti
  ````
  Define a multimethod based on all the arguments passed to the


@@ 585,7 585,8 @@
  multimethod has been imported.
  ```
  [name]
  ~(do (varfn ,name "Open multimethod." [] nil)
  ~(do
     (varfn ,name "Open multimethod." [] nil)
     (-> (in (dyn ',name) :ref)
         (,declare-varmulti))))


M test/fugue.janet => test/fugue.janet +8 -0
@@ 273,4 273,12 @@
(deftest multimethod-type-validation
  (is (thrown? (apply fugue/defmulti ['bongo ["ok"] ['x] :ok]))))

(def bare-table @{})
(def child (table/setproto @{} bare-table))
(fugue/defmulti match-on-table [bare-table] [_] :ok)

(deftest table-multimethod
  (is (= :ok (match-on-table child)))
  (is (thrown? (match-on-table @{}))))

(run-tests!)