Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

clojure
communitycreator

What is the with-meta method in Clojure?

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

A meta is data about other data, which makes working with the data easier.

Note: A metadata is not the content of a data.

What is the with-meta method?

The with-meta method is used to add or attach metadata to an object in Clojure.

Syntax

(with-meta obj mapentry)
with-meta method syntax

Parameters

  • obj: The object we attach a metadata to.
  • mapentry: The metadata we add.

Return value

This method returns an object of same value type with the attached metadata.

Example

(ns clojure.examples.example
   (:gen-class))
(defn metta []
   (def d-map (with-meta [1 2 3] {:prop "values"}))
   (println (meta d-map)))
(metta)
Example of the with-meta method

Explanation

  • Line 3: We define a function metta.
  • Line 4: We define an object and attach a meta data, {:prop values}, using the with-meta method.
  • Line 5: We print the output using println. We use the meta method to get metadata of the object.
  • Line 6: We call the metta function.

RELATED TAGS

clojure
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring