Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
racket言語解説
Search
yuyays
July 23, 2025
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
racket言語解説
yuyays
July 23, 2025
More Decks by yuyays
See All by yuyays
akarenga_june.pdf
yuyays
0
93
LLMでBang( バング)検索
yuyays
0
120
快適なWeb体験を
yuyays
0
13
Vibe codingと私はバイブするん?
yuyays
0
24
Webレンダリングの変化とどれ使うん
yuyays
0
110
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
930
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
490
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.3k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Building AI with AI
inesmontani
PRO
1
1.1k
Side Projects
sachag
455
43k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
440
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
490
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Transcript
Racket 言語かんたん解説 Akarenga35 LT by @yuyays
話すこと • racket 言語の説明 • 大切なコンセプト (list, match, cond) •
その他のトピック
背景 • 前回関数型で刺激を受けたのと • racket 言語の復習してみようを思った
racket 言語 • 関数型 • 静的型付けも利用可能(Typed Racket) • DrRacket と呼ばれる開発環境
• lisp 系統 ( カギカッコ ) • Parser, interpreter( パ ー サ ー インタプリタも書ける )
Linked list での比較 class Node: def __init__(self, data, next=None): self.data
= data self.next = next Node(8, Node(4,None)) (struct Node ([data: real) [ next: numlist] (define-type Numlist(U Node `mt)) Node(8, Node(4,`mt)) cons(8 (cons 4 `())
大切なコンセプト (list, match, cond)
List • 基本的にすべてのデ ー タは Immutable(変更不可)なので再起で回してアクセスして料理する • Cons, `( バッククォ
ー ト ) を使用 • `() 空のリスト • 例) • (cons 1 '()) ; => '(1) • (cons 1 (cons 2 '())) ; => '(1 2) • (cons 'a (cons 'b '())) ; => '(a b) • (cons 1 (cons (list 2 3) (cons 4 '()))) ; => '(1 (2 3) 4) • `(1 2 3) ; => '(1 2 3) • `(a b c) ; => '(a b c) • (list 1 2 3)
Match • リスト構造体その他のデ ー タ型を分解するためのパタ ー ンマッ チ • 例)文字列の逆順にして連結を求める関数
• [“ball”, juice”] -> “juiceball (define (rev-str-app [L : (Listof String)]) : String (match L [`() ""] [(cons f r) (string-append(rev-str-app r) f)]))
(define (rev-str-app [L : (Listof String)]) : String (match L
[`() ""] [(cons f r) (string-append(rev-str-app r) f)])) [`() ""] -> もしリストが空なら , からのリストを返す [(cons f r) (string-append(rev-str-app r) f)])) cons(f r) では与えられたリスト L が最初のアイテム fと残りのアイテム r に destructure(取り出されている) それで cons(f r) でリストがそのような形にあてはまるなら , string-append というライブラリ関数に rev-str-app にrを与えたものをfに連結する
python と比較 def rev_str_app(L: list[str]) -> str: if L ==
[]: return "" else: f, *r = L return rev_str_app(r) + f
condition • 条件 (if, else, when 等 ) • 例)リストと数値
n を受け取り 、 リストの最初の n 個の要素を返す関数 • `(`a `b `c `d) 2) -> `(`a `b)) (define (my-take [L : (Listof Any)] [n : Real]) : (Listof Any) (cond [(empty? L) `()] [(= n 0) `()] [(< (length L) n ) L] [else (cons (first L) (my-take (rest L) (- n 1)))]))
• (check-equal? (my-take `(11 22 33 44) 2) `(11 22))
• (check-equal? (my-take `(`a `b `c `d) 2) `(`a `b)) • (check-equal? (my-take `(`a `b `c `d) 100) `(`a `b `c `d)) • (check-equal? (my-take `() 21) `())
関連トピック • AST(abtact sysntax tree) • S-expression(sエクスプレッション ) • scope(
スコ ー プ ) • Box type(mutable 可 ) • Higher order fucntion( 高級関数 ) • Clousure( クロ ー ジャ ) • Function as a value( 関数としての値 ) • binding( バインディング )
参照 • https://racket-lang.org/