• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    Clojure
  • Created over 11 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of documentation for Clojure symbols

thalia

A collection of documentation for Clojure functions, macros, and other vars. This extra documentation can easily be added to the doc strings in a running Clojure process, such that (doc ==) will show the standard doc string, plus the extra documentation. Here is the output of (doc ==) with unmodified Clojure 1.5.1:

user=> (doc ==)
-------------------------
clojure.core/==
([x] [x y] [x y & more])
  Returns non-nil if nums all have the equivalent
  value (type-independent), otherwise false

Here is the output of (doc ==) after loading thalia extended doc strings (no modification to Clojure source code is required):

user=> (doc ==)
-------------------------
clojure.core/==
([x] [x y] [x y & more])
  Returns non-nil if nums all have the equivalent
  value (type-independent), otherwise false
--------- ^^^ original docs --------- VVV unofficial extra docs ---------
(== x y) is true if x and y are both numbers, and represent
numerically equal values.  Unlike =, there are no separate
'categories' of numeric values that are treated as always unequal to
each other.  If you call == with more than two arguments, the result
will be true when all consecutive pairs are ==.  An exception is
thrown if any argument is not a numeric value.

Exceptions, or possible surprises:

* == is false for BigDecimal values with different scales, e.g. (==
  1.50M 1.500M) is false.  http://dev.clojure.org/jira/browse/CLJ-1118
* 'Not a Number' values Float/NaN and Double/NaN are not equal to any
  value, not even themselves.

Examples:

    user=> (= 2 2.0)   ; = has different categories integer and floating point
    false
    user=> (== 2 2.0)  ; but == sees same numeric value
    true
    user=> (== 5 5N (float 5.0) (double 5.0) (biginteger 5))
    true
    user=> (== 5 5.0M) ; this is likely a bug
    false
    user=> (== Double/NaN Double/NaN)  ; this is normal
    false
    user=> (== 2 "a")
    ClassCastException java.lang.String cannot be cast to java.lang.Number  clojure.lang.Numbers.equiv (Numbers.java:206)

This documentation is intended to describe the way things behave in particular versions of Clojure, including examples, bugs, and issues Clojure programmers should be cautious about. It has no official status as Clojure documentation. You should not rely on any of it as a promise that future Clojure versions will continue to behave in the ways documented.

Releases and dependency information

Latest stable release: 0.1.0

Leiningen dependency information:

[thalia "0.1.0"]

Maven dependency information:

<dependency>
  <groupId>thalia</groupId>
  <artifactId>thalia</artifactId>
  <version>0.1.0</version>
</dependency>

Usage

Add this to the dependencies of your Leiningen project:

[thalia "0.1.0"]

If you wish it to be part of the dependencies in all of your Leiningen projects at the REPL, add this to your $HOME/.lein/profiles.clj file:

{:repl {:dependencies [[thalia "0.1.0"]]}}

In the REPL, you can add the extra docs to the normal doc strings with these commands:

user=> (require 'thalia.doc)
user=> (thalia.doc/add-extra-docs!)  ; (thalia.doc/add-extra-docs! :language "en_US") if you get a locale related error

To test it, look at the output of (doc ==).

It is expected that this collection of documentation will grow slowly over time, as it is written.

Web docs

Here are links to some docs that were written in Markdown format for browsing on Github. I am not sure whether I will be enhancing these in the future. My current thinking is to focus on making enhanced doc strings for use in the REPL rather than web browsing.

Developer documentation

The basic flow is:

  • Create text files (in Github-flavored Markdown format) containing extended doc strings in a directory beneath the doc/project-docs directory. See 'Directory structure' below for the path names that should be used.

  • Create one file resource/<language>.clj per language for all extended doc strings written in that language. See 'Create language resource files' below.

  • Use Leiningen to create a JAR file containing a little bit of Clojure code and the files in the resource directory. This is deployed for others to use, e.g. on clojars.org. See 'Create JAR file' below.

  • Create tests in test/thalia/doc_test.clj, or some other test file. These should test all examples given in the extended doc strings, and perhaps more. See 'Run tests' below.

Directory structure

The path name of each text file should be of the following form, where / characters are used as on Mac OS X and Linux to separate directory names in the path.

doc/project-docs/<language>/<project-name>/<version>/<namespace>/<symbol>.md

Below are some example paths for the language US English, abbreviated en_US. Execute the expression (str (java.util.Locale/getDefault)) at the REPL to see the abbreviation for your language.

The project is clojure.core, version 1.5.1, namespace clojure.string, symbol replace:

doc/project-docs/en_US/clojure.core/1.5.1/clojure.string/replace.md

Below is an example for everything the same as above, except the namespace is clojure.core and the symbol is ==. The file name has been modified in a way similar to how special characters are modified when they appear in URLs. If you have a project, version, namespace, or symbol name with any characters that are not ASCII alphabetic, numeric, nor the - character, you can use the function thalia.core/encode-url-component to see what the file name should be.

doc/project-docs/en_US/clojure.core/1.5.1/clojure.core/%3D%3D.md

Create language resource files

Run this command:

lein run create-doc-rsrc en_US

Other languages besides US English may be supported in the future, if someone writes doc strings in those languages.

Create JAR file

Run one or more of the following commands.

# To install in your local Maven repo, usually in $HOME/.m2
lein install

# To create a JAR file locally
lein jar

# To deploy to clojars.org
lein deploy clojars

Run tests

There is definitely repetition involved here in having the same or similar code in both the doc string text files and the unit tests.

In their current form, running the tests is quite simple:

lein test-all

It would be preferable not to do so, e.g. by having an automated way to extract the examples from the doc strings and execute them, verifying the output is as shown in the example. If someone knows of a good way to do that, please let me know. Something like doctest in Python would be good.

Creating directory tree skeleton

These instructions have only been tested with Mac OS X and Linux, although they might work on Windows with Cygwin installed. They are not expected to work with Windows (without Cygwin) because of the bash shell scripts involved.

TBD: Flesh these instructions out. They involve using lein-clojuredocs.

Also these commands:

lein run json2edn
lein run create-empty-doc-files

For Clojure contrib libraries, the bash script scripts/gen-most.sh may be useful.

To do

Write extended doc strings for many more vars.

Create a function or macro (topic ) that can be used to show documentation about topics that are not necessarily about a particular var, similary to Python's 'topics' in its help system. There are already references to (topic Equality) and (topic Comparators) in existing doc strings.

Try to enable (optional) less-like pager behavior for long doc strings. The following StackOverflow page may lead to a solution:

http://stackoverflow.com/questions/19665348/send-clojure-doc-output-through-pager

If we ever have a lot of these, consider making a version of the tooltip-enabled Clojure cheat sheet with the longer doc strings, with a line limit much longer than the current 15 lines.

License

Copyright (c) 2013-2015 Andy Fingerhut

Distributed under the Eclipse Public License.

More Repositories

1

p4-guide

Guide to p4lang repositories and some other public info about P4
P4
524
star
2

jafingerhut.github.com

HTML
90
star
3

clojure-benchmarks

Benchmark programs in Clojure, Java, and several other languages, for performance comparison
Clojure
66
star
4

cljol

Experimental code using Java Object Layout (JOL) from Clojure
Clojure
49
star
5

funjible

Almost, but not quite, exactly like Clojure core libraries
Clojure
26
star
6

batman

Not A Number details, focused on Java and Clojure
Clojure
9
star
7

benchmarks

Some simple benchmark programs for testing CPU core, cache, and main memory performance
C
8
star
8

dolly

Clojure namespace cloner
Clojure
8
star
9

p4lang-tests

Some sample P4 programs and notes
P4
8
star
10

dontstop

Stopping evaluations of Clojure expressions, and potential consequences
Clojure
7
star
11

p4-namespaces

A public repo for discussion of adding namespaces to the P4 programming language
5
star
12

toylang-lsp

A Language Server Protocol (LSP) server for a toy programming language, implemented in Clojure
Clojure
3
star
13

core.btree-vector

B-Tree implementation of Clojure vectors with efficient subvec and concatenation operations
3
star
14

rebl-experiments

Try out several ways of starting Cognitect REBL to see which ones work, recording results
Shell
3
star
15

haironfire

Some code for examining some properties of published software projects that use Leiningen
Clojure
3
star
16

timegraphs

Experiments in code for creating interactive time-based graphs of numerical data
C
3
star
17

text.unicode

Some Clojure functions & macros for dealing with Unicode strings.
Clojure
3
star
18

approxsemver

Proposed mock serious description of approximate semantic versioning, the industry de facto standard
3
star
19

catch-bad-unit-test

A tiny test repository to exercise an incorrectly written Clojure unit test
Clojure
2
star
20

p4-todo

2
star
21

jdk-hsdis

How to compile hsdis library for at least some JDK versions
C
1
star
22

lpc10

An implementation in Fortran and C of the LPC-10 2400 bits-per-sec speech codec
C
1
star
23

cljs-3162-sample-project

A sample Clojure project to demonstrate the current behavior of clojure.test for clj and cljs
Clojure
1
star
24

data.rrbv

A vector implementation for Clojure using Relaxed Radix Balanced Trees
1
star
25

linux-perf-demo

Demo of running Linux perf tool on a tiny test program, and interpreting the perf report output
C
1
star
26

osx-spotlight-test

Some scripts to test the behavior of OS X Spotlight indexing
HTML
1
star
27

janus

Explorations in Clojure concurrency
1
star
28

tlaplus-learning

Resources I used to help me learn TLA+
HTML
1
star
29

clj-vector-performance

Some code to measure the performance of some operations on Clojure vectors
Clojure
1
star
30

clj-perls

Some Clojure functions & macros that operate similar to Perl functions
Clojure
1
star
31

cljol-jvm-support

Java Object Layout: Modified Core for use by cljol library
Java
1
star
32

clj-prescreen

Automated process to grab Clojure patches and find out which ones are ready to screen
Clojure
1
star
33

achilles

Very simple Java & Clojure performance tests
Java
1
star
34

vec-data-reader

Possibly unexpected behavior when one creates a Clojure tagged literal that returns a value that is a vector of primitives
Clojure
1
star
35

clojure-rte

Fork of Jim Newton's clojure-rte repository
Clojure
1
star
36

flokkun-pakka

Code related to the packet classification problem
TeX
1
star