Felipe
Felipe

Reputation: 17181

What does the @ (at sign) mean in Clojure?

I found this line of Clojure code: @(d/transact conn schema-tx). It's a Datomic statement that creates a database schema. I couldn't find anything relevant on Google due to difficulties searching for characters like "@".

What does the 'at' sign mean before the first parenthesis?

Upvotes: 19

Views: 5124

Answers (3)

peter_the_oak
peter_the_oak

Reputation: 3710

Here is a useful overview of Clojure default syntax and "sugar" (i.e. macro definitions).

http://java.ociweb.com/mark/clojure/article.html#Overview

You'll find explained the number sign #, which indicates regex or hash map, the caret ^, which is for meta data, and among many more the "at sign" @. It is a sugar form for dereferencing, which means you get the real value the reference is pointing to.

Clojure has three reference types: Refs, Atoms and Agents.

http://clojure-doc.org/articles/language/concurrency_and_parallelism.html#clojure-reference-types

Your term @(d/transact conn schema-tx) seems to deliver a reference to an atom, and by the at sign @ you defer and thus get the value this reference points to.

BTW, you'll find results with search engines if you look e.g. for "Clojure at sign". But it needs some patience ;-)

Upvotes: 9

Ben Kamphaus
Ben Kamphaus

Reputation: 1665

This is the deref macro character. What you're looking for in the context of Datomic is at:

http://docs.datomic.com/transactions.html

under Processing Transactions:

In Clojure, you can also use the deref method or @ to get a transaction's result.

For more on deref in Clojure, see:

http://clojuredocs.org/clojure_core/clojure.core/deref

Upvotes: 14

mac
mac

Reputation: 10075

The @ is equivalent to deref in Clojure. transact returns a future which you deref to get the result. deref/@ will block until the the transaction completes/aborts/times out.

Upvotes: 2

Related Questions