init

parents
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-history
/.nrepl-port
.hgignore
.hg/
# Change Log
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
## [Unreleased]
### Changed
- Add a new arity to `make-widget-async` to provide a different widget shape.
## [0.1.1] - 2019-11-19
### Changed
- Documentation on how to make the widgets.
### Removed
- `make-widget-sync` - we're all async, all the time.
### Fixed
- Fixed widget maker to keep working when daylight savings switches over.
## 0.1.0 - 2019-11-19
### Added
- Files from the new template.
- Widget maker public API - `make-widget-sync`.
[Unreleased]: https://github.com/your-name/scg/compare/0.1.1...HEAD
[0.1.1]: https://github.com/your-name/scg/compare/0.1.0...0.1.1
This diff is collapsed.
# scg
A Clojure library designed to ... well, that part is up to you.
## Usage
FIXME
## License
Copyright © 2019 FIXME
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.
(def project 'scg)
(def version "0.1.0-SNAPSHOT")
(set-env! :resource-paths #{"resources" "src"}
:source-paths #{"test"}
:dependencies '[[org.clojure/clojure "RELEASE"]
[adzerk/boot-test "RELEASE" :scope "test"]])
(task-options!
pom {:project project
:version version
:description "FIXME: write description"
:url "http://example/FIXME"
:scm {:url "https://github.com/yourname/scg"}
:license {"Eclipse Public License"
"http://www.eclipse.org/legal/epl-v10.html"}})
(deftask build
"Build and install the project locally."
[]
(comp (pom) (jar) (install)))
(require '[adzerk.boot-test :refer [test]])
# Introduction to scg
TODO: write [great documentation](http://jacobian.org/writing/what-to-write/)
(ns scg.core
(:require [clojure.walk :as walk]))
(defrecord Variable [id name])
(defn ? [name]
(->Variable nil name))
(defn variable? [v]
(instance? Variable v))
(defn walk [u bindings]
(last (take-while some? (iterate bindings u))))
(defn unify [u v bindings]
(let [u (walk u bindings)
v (walk v bindings)]
(cond
(= u v) bindings
(variable? u) (assoc bindings u v)
(variable? v) (assoc bindings v u))))
(defn match [facts matchfacts]
(->>
{:success []
:work [{:facts facts :matchfacts matchfacts :bindings {}}]}
(iterate
(fn [{:keys [success work]}]
(let [{nsuccess true work false}
(->> work
(mapcat
(fn [{:keys [facts matchfacts bindings]}]
(let [[fu ff fv :as f] (first facts)
nfacts (disj facts f)]
(->> matchfacts
(map
(fn [[mu mf mv :as m]]
(when-let [bindings
(some->>
bindings
(unify mu fu)
(unify mf ff)
(unify mv fv))]
{:bindings bindings
:facts facts ; WHEN INJECTIVE IS OK USE NFACTS
:matchfacts (disj matchfacts m)})))
(filter some?)
(concat
(when (<= (count matchfacts) (count nfacts))
[{:bindings bindings
:facts nfacts
:matchfacts matchfacts}]))))))
(group-by (fn [s] (empty? (:facts s)))))]
{:success (into success nsuccess)
:work work})))
(drop-while (fn [s] (not (empty? (:work s)))))
first
:success
(map :bindings)))
(defn merge [facts mergefacts bindings]
(->> (concat facts mergefacts)
(walk/postwalk (fn [n] (walk n bindings)))
(into #{})))
(defn unify-variables-by-name [c]
(let [variable-ids (atom {})] ; Sadly walk doesn't have an accumulator.
(walk/postwalk
(fn [n]
(if (variable? n)
(let [name (:name n)]
(assoc n :id
(name (swap! variable-ids update
name
(fn [id]
(or id (java.util.UUID/randomUUID)))))))
n))
c)))
(defn apply-cxn [fs cxn constraints]
(let [cxa (unify-variables-by-name cxn)
bindings (match fs (:match cxa))]
(remove constraints (map (fn [b] (merge fs (:merge cxa) b)) bindings))))
(defn constrain-unique-unit-feature [is-unique-feature]
(fn constraint [facts]
(->> facts
(group-by (fn [[fu ff fv]] [fu ff]))
(some (fn [[[fu ff] v]]
(when (and (is-unique-feature ff) (< 1 (count v)))
[:error (str "Contradicting feature values:" v)]))))))
(defn constrain-no-variable-features []
(fn constraint [facts]
(->> facts
(some (fn [[fu ff fv :as f]]
(when (variable? ff)
[:error (str "Variable features may not occur: " f)]))))))
(def test-cxn {:merge #{[(? :a) :gen :masculin]}
:match #{[(? :a) :num :plural]}})
(def test-fs #{[#uuid "c9881173-2344-479a-a93d-558dd52d706f" :num :plural]})
(ns scg.core-test
(:require [clojure.test :refer :all]
[scg.core :refer :all]))
(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment