Querying Definitions

Calcit provides a powerful query subcommand to inspect code, find definitions, and analyze usages directly from the command line.

Core Query Commands

List Namespaces (ns)

# List all loaded namespaces
cr query ns

# Show definitions in a specific namespace
cr query ns calcit.core

Read Code (def)

# Show full source code of a definition
cr query def calcit.core/assoc

Peek Signature (peek)

# Show documentation and examples without the full body
cr query peek calcit.core/map

Check Examples (examples)

# Extract only the examples section
cr query examples calcit.core/let

Find Symbol (find)

# Search for a symbol across ALL loaded namespaces
cr query find assoc

Analyze Usages (usages)

# Find where a specific definition is used
cr query usages app.main/main!
# Search for raw text (leaf values) across project
cr query search hello

# Limit to one definition
cr query search hello -f app.main/main!

Search Expressions (search-expr)

# Search structural expressions (Cirru pattern)
cr query search-expr "fn (x)"

# Limit to one definition
cr query search-expr "fn (x)" -f app.main/main!

Quick Recipes (for fast locating)

Locate a symbol and jump to definition

cr query find assoc
cr query def calcit.core/assoc

Locate all call sites before refactor

cr query usages app.main/main!

Locate by text when you only remember a fragment

cr query search "reload"

Runtime Code Inspection

You can also use built-in functions to inspect live data and definitions:

let
    Point $ defstruct Point (:x :number) (:y :number)
    p (%{} Point (:x 1) (:y 2))
  do
    ; Get all methods/traits implemented by a value
    println $ &methods-of p
    ; Get tag name of a record or enum
    println $ &record:get-name p
    ; Describe any value's internal type
    println $ &inspect-type p

Getting Help

Use cr query --help for the full list of available query subcommands.