• Stars
    star
    356
  • Rank 119,446 (Top 3 %)
  • Language
    Common Lisp
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Clojure in Common Lisp

Cloture

Cloture is an implementation of Clojure in Common Lisp. It is designed above all to interoperate well with Common Lisp; Clojure is read by the Lisp reader and Clojure namespaces are Lisp packages.

Cloture is in very early (pre-alpha) stages, but it has progressed far enough to load clojure.test, allowing the test suite to actually be written in Clojure.

Work so far has been focused on the critical path to get real Clojure code working in CL. But if there is interest from Clojurists I may work toward making it a more complete Clojure implementation.

Clojure vs. ClojureScript

Cloture is closer to Clojure than to ClojureScript. Among other things, the plan is to support Clojure’s concurrency primitives (atom, ref, agent, future, promise). However, Cloture follows ClojureScript in making exclusive use of protocols - interfaces are not used or supported. Protocol names are also derived from ClojureScript.

Like ClojureScript, Cloture supports (catch :default) to catch everything.

A note about FSet

Cloture uses FSet seqs, maps, and sets to implement Clojure vectors, maps, and sets, respectively. This involves a few hacks to FSet that might possibly affect other programs using FSet.

Starting a REPL

Use (cloture:repl) to start a Clojure REPL. You can exit the REPL with (quit) or (exit).

Note that not much work has been done yet on Clojure-style printing, so the “Print” in REPL is still mostly the Common Lisp printer.

Interoperation

Using Clojure from Lisp

The design goal of Cloture is to keep things as close to Common Lisp as possible: Clojure is read by the Lisp reader and Clojure namespaces are just packages. Clojure packages and functions, however, usually have lower-case names, so to call them from Lisp you will need to quote them with pipe characters:

(|clojure.core|:|cons| 1 '(2))
=> '(1 2)

Lisp’s nil is used only as the empty list; Clojure nil, true, and false are singletons. To use Clojure predicates from Lisp, you can use cloture:truthy? to translate.

(cloture:truthy? (|clojure.core|:|=| '(1 2 3) #(1 2 3)))
=> T

In this case, however, you should use cloture:egal, which tells you if two objects are equal according to Clojure’s idea of equality.

Cloture exports Iterate drivers for working with collections that satisfy Clojure protocols:

  • cloture:in-seq iterates over ISeq.
  • cloture:on-seq iterates over the rests of ISeq.
  • cloture:in-indexed iterates over IIndexed.
  • cloture:index-of-indexed iterates over the indices of IIndexed.

Clojure files can be integrated into Lisp systems by making the system definition depend on Cloture (:defsystem-depends-on ("cloture") and using "cloture:cljc" as the file type.

(defsystem ...
  :defsystem-depends-on ("cloture")
  :components ((:file "cloture:cljc" "my-clojure-code")))

You can also use "cloture:clj" or "cloture:cljs" to load straight Clojure or ClojureScript files. Using .cljc is recommended, however.

Using Lisp from Clojure

Since Clojure uses the Lisp reader, you can call Lisp functions just by uppercasing them.

(letfn [(fst [xs] (CL:FIRST xs))]
  (fst '(1 2 3)))

You will also need to spell out CL:QUOTE and CL:FUNCTION (or refer them), as Clojure quote is not the same thing as CL quote and sharp-quote is used in Clojure for a different purpose.

(ns ...
  (:require [CL :refer [QUOTE FUNCTION]]))

Cloture defines a Clojure namespace, cloture, with exports whose names (and keyword arguments!) are already conveniently lowercased and otherwise follow Clojure conventions:

(ns ...
  (:require [cloture:refer [parse-integer]]))

(parse-integer "1234x" :start 1 :junk-allowed true)
=> 234

All Lisp sequences (lists, vectors, and extensible sequences on implementations that support them) implement ISeq.

Reader conditionals

In reader conditionals in .cljc files (and at the REPL), Cloture looks for a :cl key.

License

Eclipse Public License.

Why?

I would like to be able to use Clojure libraries from Common Lisp.

Why “Cloture”?

Beside the obvious: cloture is a parliamentary procedure to end debate on a subject, and I would like to end certain debates. Yes, Common Lisp is “modern.” Yes, Clojure is a Lisp.

More Repositories

1

serapeum

Utilities beyond Alexandria
Common Lisp
377
star
2

spinneret

Common Lisp HTML5 generator
Common Lisp
263
star
3

vernacular

Module system for languages that compile to Common Lisp
Common Lisp
54
star
4

cl-yesql

Common Lisp library for using SQL
Common Lisp
54
star
5

cmd

Utility for running external programs
Common Lisp
53
star
6

overlord

Build system in Common Lisp
Common Lisp
53
star
7

FXML

Secure-by-default, error-recovering XML parser and serializer in Common Lisp
Common Lisp
28
star
8

moira

Monitor and restart background threads.
Common Lisp
25
star
9

cl-feedparser

Common Lisp feed parser
Common Lisp
24
star
10

infix-math

An extensible infix syntax for math in Common Lisp.
Common Lisp
23
star
11

core-lisp

Hygiene-compatible Lisp dialect embedded in CL
Common Lisp
19
star
12

cl-bloom

Simple Bloom filters in Common Lisp with efficient hashing.
Common Lisp
16
star
13

cl-murmurhash

The 32-bit version of Murmurhash3 for Common Lisp.
Common Lisp
15
star
14

trivial-file-size

Stat a file's size in Common Lisp.
Common Lisp
15
star
15

lisp-magick-wand

ImageMagick bindings (fork)
Common Lisp
11
star
16

cl-strftime

Common Lisp compiler for the strftime language
Common Lisp
11
star
17

cl-https-everywhere

Use HTTPS Everywhere rules from Lisp
Common Lisp
9
star
18

dpans2texi

Convert the ANSI Common Lisp draft to Texinfo
Emacs Lisp
8
star
19

cl-boilerpipe

Extract main content from articles and blog posts.
Common Lisp
6
star
20

bosom-serpent

Import Python modules into Lisp
Common Lisp
6
star
21

cl-stripe-client

Common Lisp client for the Stripe payment system
Common Lisp
6
star
22

cl-shlex

Simple lexical analyzer for shell-like syntaxes
Common Lisp
6
star
23

org-velocity

Development version of org-velocity
Emacs Lisp
6
star
24

media-types

Query and compare media types
Common Lisp
6
star
25

cl-lc

List comprehensions and friends
Common Lisp
5
star
26

yuri

Defused URIs.
Common Lisp
4
star
27

horner

Inline polynomial evaluation using Horner's rule
Common Lisp
4
star
28

winlock

File locking on Windows for Common Lisp
Common Lisp
3
star
29

floating-point-contractions

Numerically stable contractions (expm1 and friends).
Common Lisp
3
star
30

cl-textcat

Language detector
Common Lisp
3
star
31

random-sample

Take a random sample from a sequence
Common Lisp
3
star
32

date-calc

Maintenance fork of the Date-Calc library
Common Lisp
3
star
33

utopian

Record Lisp compilation warnings and generate reports.
Common Lisp
2
star
34

html5-sax

Bridge HTML5 and CXML
Common Lisp
2
star
35

metering

Lightly modernized Metering System.
Common Lisp
2
star
36

tiro

Modal shorthand for Emacs
Emacs Lisp
1
star
37

projector

Project-oriented Emacs
Emacs Lisp
1
star
38

cxml

Closure XML (fork)
Common Lisp
1
star
39

cl-libstemmer

Snowball stemming algorithms (FFI)
C
1
star
40

birds-of-paradise

Emacs port of Joe Bergantine's Birds of Paradise theme
Emacs Lisp
1
star
41

trivial-float-bits

Convert floats to integers at low level.
Common Lisp
1
star
42

cl-textteaser

Common Lisp port of the textteaser algorithm
Common Lisp
1
star
43

numwin

Generalized window numbering for Emacs
Emacs Lisp
1
star