0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【ひとりカレンダー】ClojureAdvent Calendar 2024

Day 5

Clojureの基本構文 - 関数の定義と呼び出し

Last updated at Posted at 2024-12-04

advent_calendar_2024.png

Advent Calendar 2024 Day 5

基本構文

3つの基本についてまとめていきます

  1. リテラル
  2. 関数の定義と呼び出し
  3. 特殊フォーム
    今日は 2.関数の定義と呼び出し についてまとめます

2. 関数の定義と呼び出し

  1. 関数の定義

    defn を使って関数を定義します。

    (defn greet [name]
      (str "Hello, " name "!"))
    
    (greet "Alice") ;=> "Hello, Alice!"
    
  2. 無名関数(匿名関数)

    短い関数には fn やシャープ記法 #() を使用します。

    ((fn [x] (* x x)) 3) ;=> 9
    (#(* % %) 3) ;=> 9
    
  3. 高階関数

    関数を引数として受け取る、または関数を返す関数。

    (map #(* % 2) [1 2 3]) ;=> (2 4 6)
    

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?