practicalli / practicalli/clojure

Understanding require and ns macro

Open
#8 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Makefile
Stars
117
Forks
36
PR merge metrics
No merged PRs in 30d

Description

In a REPL di
(require '[clojure.set :refer :as set])
(set union #{:a} #{:a :b :c})

' means "don't evaluate this form"
so symbols are used as is and are not resolved, and function calls are just lists
it prevents an error as clojure.set isn't bound
it's the symbolic name of something you want to load
you'd get a syntax error if you used it unquoted

The ' is not needed when used in ns as this is a macro
(ns my-namespace
(:require [clojure.set :refer :set]))

As the ns form is a macro it doesn't try to evaluate the symbols in the require form. A macro can decide whether something should be evaluated
(elaborate)

When calling a function (eg. require) the arguments are evaluated first, then passed to the function

when you call a macro (eg. ns) the args are passed as a list of symbols and input literals and the macro decides what to do with them

I mean a macro usually does evaluate things (clojure macros can use the entire clojure language as needed), but they usually just turn one list (form) into another then return it to be compiled

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the REPL examples in the issue, especially the require call and ns form, and compare their explanation with the existing project documentation. Done means the distinction between quoting, function argument evaluation, and macro expansion is documented accurately, but the issue does not identify a target file or test.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.