~subsetpark/fugue

854d1d5cc876f889f1fed7e1c1ad107dac1c9647 — Zach Smith 3 years ago 66f804a matching-in-multis v0.5.0
Minor cleanup
2 files changed, 35 insertions(+), 25 deletions(-)

M README.md
M fugue.janet
M README.md => README.md +13 -13
@@ 83,7 83,7 @@ time that `some-field` is defined on `SomePrototype`; at runtime, checks that
`some-object` is a descendent of `SomePrototype` and if so, translates to
`(some-object :some-field)`.

[1]: fugue.janet#L851
[1]: fugue.janet#L861

## Root



@@ 134,7 134,7 @@ prototype for this key, then `fugue/allocate` will put `value` at `key` in
the appropriate prototype, and it will be inherited by all descendents of
that prototype.

[5]: fugue.janet#L386
[5]: fugue.janet#L387

## declare-open-multi



@@ 150,7 150,7 @@ Extending an open multimethod (see `extend-multi`) from any other
environment makes the case extension available wherever the
multimethod has been imported.

[6]: fugue.janet#L723
[6]: fugue.janet#L731

## defgeneric



@@ 164,7 164,7 @@ Define a generic function. When this function is called, if the first
argument has a method corresponding to the name of the function, call that
object 's method with the arguments. Otherwise, evaluate `body`.

[7]: fugue.janet#L426
[7]: fugue.janet#L427

## defmethod



@@ 182,7 182,7 @@ Defines a few symbols for reference in the body of the method.
- `__parent` - Bound to the parent of `proto`.
- `__super` - Bound to the method at `name` within `__parent`.

[8]: fugue.janet#L451
[8]: fugue.janet#L452

## defmulti



@@ 271,14 271,14 @@ repl:12:> (cat "hello" 100)
"hello #100"
```

[9]: fugue.janet#L629
[9]: fugue.janet#L637

## defproto

**macro**  | [source][10]

```janet
(defproto name parent-name & fields)
(defproto name parent-name & rest)
```

Object prototype definition.


@@ 370,7 370,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.

[11]: fugue.janet#L754
[11]: fugue.janet#L762

## fields



@@ 412,7 412,7 @@ Prototype-aware version of `match`. Introduces one new case form:
of `prototype-name`. Additionally, will validate at compile-time that every
key in `dictionary` is a field that's present on the specified prototype.

[14]: fugue.janet#L877
[14]: fugue.janet#L887

## multimethod-types-match?



@@ 426,7 426,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)

[15]: fugue.janet#L551
[15]: fugue.janet#L559

## new-Root



@@ 450,7 450,7 @@ Constructor for Root. Return a new object with Root as the prototype.

Is `obj` the result of a `defproto ` call?

[17]: fugue.janet#L378
[17]: fugue.janet#L379

## with-slots



@@ 491,7 491,7 @@ true
@Foo{:_meta @{:object-type :instance} :name "Cosmo Kramer"}
```

[18]: fugue.janet#L804
[18]: fugue.janet#L814

## with-slots-as



@@ 507,5 507,5 @@ Specifies `as` as the reference symbol for `with-slots`.

See `with-slots` documentation for more details.

[19]: fugue.janet#L840
[19]: fugue.janet#L850


M fugue.janet => fugue.janet +22 -12
@@ 354,13 354,14 @@
  "My name is Fido and I am Extremely Small"
  ```
  ````
  [name parent-name & fields]
  (let [has-proto-attributes (odd? (length fields))
        fields (partition 2 fields)
        defined-fields (map (comp keyword 0) (if has-proto-attributes (array/slice fields 0 -2) fields))
  [name parent-name & rest]
  (let [fields (partition 2 rest)
        [field-attrs [proto-attrs]] (if (odd? (length rest))
                                      [(array/slice fields 0 -2) (last fields)]
                                      [fields [{}]])
        defined-fields (map (comp keyword 0) field-attrs)
        field-definitions (field-definitions name fields defined-fields)
        [prototype-attributes-entry] (if has-proto-attributes (last fields) [{}])
        prototype-attributes (prototype-attributes name prototype-attributes-entry)]
        {:constructor-name constructor-name} (prototype-attributes name proto-attrs)]
    @[~(def ,name
         ,(proto-docstring name defined-fields)
         (->


@@ 372,7 373,7 @@
           (,put :new ,(init-form name (field-definitions :init-args)))))
      (pred-form name)
      (pred*-form name)
      (new-form name (prototype-attributes :constructor-name))
      (new-form name constructor-name)
      ;(getters name field-definitions)]))

(defn prototype?


@@ 499,8 500,15 @@
      (not (or (symbol? sym) (keyword? sym))) (compile-matcher sym)
      (let [evaled (eval sym)]
        (if (not (or (table? evaled) (keyword? evaled)))
          (errorf `Multimethod type error. Expected keyword, prototype, or match specification; got:
                   %q of type %q`
          (errorf `Multimethod type error.

                   Expected keyword, prototype, or match specification; got:

                   %q

                   of type

                   %q`
                  sym
                  (type sym))
          evaled))))


@@ 708,8 716,8 @@
  ```
  ````
  [name multi-types args & body]
  # Nominal case handling: group declared cases by concating the
  # current file with the name of the function.
  # Nominal case handling: group declared cases by concating the current file
  # with the name of the function.
  (let [cases-key (keyword (dyn :current-file) "-" name)]
    (set-multi-default cases-key)
    (put-multi-case cases-key multi-types (make-case multi-types args body))


@@ 783,7 791,9 @@
          (unless (index-of field-name fields)
            (errorf `Encountered field reference %q for prototype %q;

                     Expected one of: %q`
                     Expected one of:

                     %q`
                    sym
                    proto-name
                    fields))