~subsetpark/fugue

fugue/project.janet -rw-r--r-- 2.5 KiB
55567281 — Zach Smith fix #14 - eval symbol when processing match 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(declare-project
 :name "fugue"
 :description "A CLOS-style object system based on Janet tables"
 :author "Z. D. Smith <zd@zdsmith.com>"
 :license "BSD3"
 :url "https://git.sr.ht/~subsetpark/fugue/"
 :repo "https://git.sr.ht/~subsetpark/fugue/"
 :dependencies ["https://github.com/pyrmont/testament"]
 :doc ```
An object system for Janet, inspired by CLOS.

---

## background

The Janet language provides a simple form of object orientation using
tables and prototypes:

### methods

Janet tables can have *methods* by storing functions at a keyword on
the table. When called with method syntax `(:method-name object)`,
the call is translated into a function call to that function with the
object itself as the first argument.

### inheritance

Janet provides prototypal inheritance. Any table may have a prototype
set, whereupon any value access at that table that returns `nil` will
recurse upwards to the table's prototype.

# fugue

`fugue` provides a more powerful set of commands that extend the
existing OO dynamics of Janet with a more elaborate interface and set
of features.

## `fugue/defproto`

`defproto` is the main entrypoint to fugue, allowing users to define
*Prototypes*. These are Janet tables with some additional metadata
included, as well as a constructor method added at `:new`. `defproto`
takes arguments that govern how new instances are created, as well as
allocation rules, ie, the configuration determining which object
fields should be populated at the instance level and which at the
prototype level.

## `fugue/defgeneric` / `fugue/defmethod`

`defgeneric` provides the interface for creating and managing *Generic
Functions*---functions which can be extended for additional
Prototypes. Generic functions may have a default behaviour, which is
then specialized for Prototypes via `defmethod`. Methods can be
specialized for a single argument---the first argument---and child
prototypes can inherit methods from their ancestors. They can also
call ancestor methods by invoking `(prototype-method)` within their
own method bodies.

## `fugue/defmulti`

`defmulti` allows the creation of *Multimethods*. Unlike Generic
Functions/Single Methods, Multimethods can be defined for the types of
all of their arguments, not just the first one. They are also not
limited to fugue Prototypes, being definable over any Janet type or a
fugue Prototype. Also unlike Single Methods, they are *not*
inheritable; a multimethod defined for an ancestor Prototype will not
be selected for any descendent prototype instances.```)

(declare-source
  :source ["fugue.janet"])