Clojure Basics Flashcards

Table of Contents

Clojure Basics Flashcards

Data Types   drill clojure_basics

Front: List the main data types in Clojure Back: - Numbers (integers, floats, ratios)

  • Strings
  • Characters
  • Symbols
  • Keywords
  • Booleans
  • Nil
  • Lists
  • Vectors
  • Maps
  • Sets

Function Definition   drill clojure_basics

Front: How do you define a function in Clojure? Back: Use the `defn` macro: (defn function-name [parameters] (function-body))

Immutability   drill clojure_basics

Front: What is immutability in Clojure? Back: In Clojure, data structures are immutable by default. This means that once created, they cannot be changed. Instead of modifying existing data, you create new data with the desired changes.

REPL   drill clojure_basics

Front: What does REPL stand for in Clojure? Back: REPL stands for Read-Eval-Print Loop. It's an interactive programming environment where you can enter Clojure expressions, have them evaluated immediately, and see the results.

Vectors   drill clojure_basics

Front: How do you create a vector in Clojure? Back: Use square brackets: [1 2 3 4 5] Or the vector function: (vector 1 2 3 4 5)

Maps   drill clojure_basics

Front: How do you create a map in Clojure? Back: Use curly braces: {:key1 "value1" :key2 "value2"} Or the hash-map function: (hash-map :key1 "value1" :key2 "value2")

Anonymous Functions   drill clojure_basics

Front: How do you create an anonymous function in Clojure? Back: Use the `fn` special form: (fn [x] (* x x)) Or use the shorthand syntax: #(* % %)

Prefix Notation   drill clojure_basics

Front: What is prefix notation in Clojure? Back: Prefix notation means that the function name comes before its arguments. Example: (+ 1 2 3) instead of 1 + 2 + 3

Namespace   drill clojure_basics

Front: How do you define a namespace in Clojure? Back: Use the `ns` macro at the beginning of your file: (ns my-project.core (:require [other-namespace :as on]))

Sequence Functions   drill clojure_basics

Front: Name three common sequence functions in Clojure Back: 1. map: Apply a function to each element in a sequence

  1. filter: Select elements from a sequence that satisfy a predicate
  2. reduce: Combine all elements of a sequence using a given function

Author: Jason Walsh

j@wal.sh

Last Updated: 2024-08-14 06:08:49