What do people mean with "reified"?

In the home page of clojure.org, there is a “Features” section, which includes “Dynamic Development”.

It explains “Dynamic Development” in terms of “reified constructs”:

Almost all of the language constructs are reified, and thus can be examined and changed.

It is redacted as if just by mentioning “reified” you should get the idea… But I don’t get it.

What does that mean?

2 Likes

The dictionary definition of reify is “to consider or make some abstraction more concrete or real”.

The usage in the features section is meant to convey that everything in a Clojure program can be manipulated in the REPL with Clojure itself: we can look at the source, at the metadata, at the types behind any object, at all aspects of the data itself – and we can modify definitions on the fly, changing or building the program up dynamically, live in the REPL.

Many (most?) other languages don’t provide all of this dynamically in a way that you can inspect and modify it all, in a running program, using the same language and semantics that you are writing your program in. If they provide it at all, you often need to use additional tools or additional semantics that are outside of the core programming language.

Stu Halloway has a great slide in his REPL-Driven Development talk, about six minutes in, where he compares the Clojure REPL to the interactive Java shell as an example of the dynamic aspects of Clojure compared to the “pour concrete” of many other languages.

See talk-transcripts/REPLDrivenDevelopment.md at master · matthiasn/talk-transcripts (github.com)

3 Likes

As always, much of the confusion while learning is language related.

I have to remember to go to the source: the dictionary.

(In this case, for some reason I was thinking it was something related with the reify function and such which link to the idea I was simply missing).

Thank you very much.

1 Like

A good way to think of reified is that it means that the program is aware of its programming and can change it, or you might say it is aware of itself and has the ability to modify itself.

To map it to the dictionary definition, you would think of source code for example as the abstraction, and the running program of that compiled source as the concrete representation of it. If the program can access its source code, and can generate more running program from it, such as how you can in Clojure call source on a function, get the source back, and then you can call eval on that source to get back a new running concrete version of that source, then the program source is reifiable, and reifying a function would be the act of taking its source (the abstraction) at runtime and evaluating it again at runtime into a new concretion.

Similarly, a spec is an abstraction, and a concrete value that is valid to the spec would be its concrete realization.

Similarly a type is an abstraction, and a concrete value of that type in memory is its concrete realization.

Similarly an interface or a protocol is an abstraction, and an object or map implementing that interface or protocol is its concrete realization.

Whenever the abstraction for some thing still exists, and can be used to generate more concrete realization of itself, or regenerate/replace existing concrete realization of itself with new ones, we say that the thing can be reified.

That’s why the reify function is called reify, because it can take an abstraction such as an interface or protocol, and generate a new concrete implementation of it.

Two things are needed for something to be reifiable, you need the abstraction to be available, and you need the ability to generate new concretions from it, and optionally replace existing concretions with new ones.

So let’s say you had a regex matcher, and if at runtime you still have the abstraction for it, it means you’d still have access to the regex string for it. And if you could generate more matchers from that regex string, or modify the regex string and generate more matchers from it, you could say that your regex is reifiable. On the other hand, if you no longer have access to the regex string that was used to compile the matcher, or if you have access to it, but cannot use it to create more matchers from it, then your regex would not be reifiable.

4 Likes

I blogged about this a few years back: Advent 2019 part 1, Clojure Vocab: to Reify

3 Likes