https://github.com/palisades-lakes/dynamic-functions
generic functions: more restricted but faster than Clojure multimethods
https://github.com/palisades-lakes/dynamic-functions
clojure clojure-multimethods generic-functions multimethods
Last synced: about 1 month ago
JSON representation
generic functions: more restricted but faster than Clojure multimethods
- Host: GitHub
- URL: https://github.com/palisades-lakes/dynamic-functions
- Owner: palisades-lakes
- License: apache-2.0
- Created: 2017-08-22T23:35:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-01T19:01:32.000Z (over 1 year ago)
- Last Synced: 2025-02-27T05:02:26.989Z (about 2 months ago)
- Topics: clojure, clojure-multimethods, generic-functions, multimethods
- Language: Java
- Homepage:
- Size: 173 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dynamic-functions
[](https://clojars.org/palisades-lakes/dynamic-functions)
This library is currently a vehicle for experimenting with
design and implementation alternatives for generic functions
(aka multimethods)
in Clojure.
It is therefore completely unstable
(I'm committed to nothing for now)
until at least version 0.1.0.Initial ideas:
- all functions are generic functions
- trade flexibility of Clojure multimethods for performance
- no hierarchies
- dispatch on class-based signatures only
- signature specified via arglist type hints
- only simple arglists (no destructuring)
- single method per arity equivalent to Clojure `defn`
- high performance with hinted primitives in and out
- Clojure functions are nearly opaque;
the only API is `clojure.lang.IFn/invoke().
Dynamic functions should be fully first class, with
an API exposing, at a minimum:
* the function name
* any hints on the return value
* the arglists, including type hints
* the relevant parts of the lexical environment in which it
was created, a list of bindings including names, values,
and type hints, possibly other hints as well.
* possibly also the dynamic environment
* the expressions that defined the bodies
* constructors that are functions, not just macros and special
forms.
For example, it should be possible to do something like
```
(defn compose ^IFn [^IFn f ^IFn g]
(assert (matches? (arglist f) (return-value g))
(function (str (name f) "-o-" (name g)) (arglist g)
`(f (g ~(arglist g)))))
```
It should be possible to examine the returned function object,
determine that it is the composition of `f` and `g`, and
generate a new function by supplying a modified environment,
say, by substituting something for 'f' or 'g'.
## Usage### Dependency
Available from
[Clojars](https://clojars.org/palisades-lakes/dynamic-functions):Maven:
```xml
palisades-lakes
dynamic-functions
0.0.x```
Leiningen/Boot:
```clojure
Leiningen/Boot
[palisades-lakes/dynamic-functions "0.0.x"]
```### Code examples
(require `[palisades.lakes.dynafn.api :as df])
(df/defn intersects?
[^IntegerInterval s0 ^java.util.Set s1]
(.intersects s0 s1))
## Acknowledgments### 
YourKit is kindly supporting open source projects with its full-featured Java
Profiler.YourKit, LLC is the creator of innovative and intelligent tools for profiling
Java and .NET applications. Take a look at YourKit's leading software products: