Skip to content

Instantly share code, notes, and snippets.

View hk220's full-sized avatar

kazuki hk220

View GitHub Profile

2.3 記号データ

任意の記号をデータとして扱う能力をつかって、言語の表現能力を拡張

2.3.1 クォート

クォート = 記号を操作するための要素

(a b) とすると、 a と b の値を要素としたリストを作ってしまう。 ここでつくりたいのは、a と b という記号のリスト。

;; 2.53
(list 'a 'b 'c)
; (a b c)
(list (list 'george ))
; ((george))
(cdr '((x1 x2) (y1 y2)))
; ((y1 y2))
;; ((1 2) 3 4)
(cons (list 1 2) (list 3 4))
;; count-leaves
(define x (cons (list 1 2) (list 3 4)))
(length x)
;; 3
(count-leaves x)
;; 4
(list x x)
;; リストに対するマップ
(define (scale-list items factor)
(if (null? items)
nil
(cons (* (car items) factor)
(scale-list (cdr items)
factor))))
;; (scale-list (list 2 3 4 5) 10)
;; (10 20 30 40 50)
@hk220
hk220 / test_gist.md
Created June 23, 2017 02:11
Test Gitst

Test

Test1

  • hoge
  • huga
  • foo
  • bar
  1. hello
;; others
(define (average x y)
(/ (+ x y) 2))
(define (gcd a b)
(if (= b 0)
a
(gcd d (remainder a b))))
;; 2.1
@hk220
hk220 / exp_ptr_call_cxx
Created July 11, 2016 13:36
Experimental program to call by pointer on C++
#include <iostream>
#include <cstdio>
int main(int argc, char* argv[]) {
int a = 10;
int* b = &a;
std::fprintf(stdout, "%p\n", &a);
std::fprintf(stdout, "%p\n", b);
std::fprintf(stdout, "%p\n", &b);
@hk220
hk220 / exp_ref_call_cxx
Created July 11, 2016 13:30
Experimental program to call by reference on C++
#include <iostream>
#include <string>
#include <cstdio>
int main(int argc, char* argv[]) {
int a = 10;
int& b = a;
std::fprintf(stdout, "%p\n", &a);
std::fprintf(stdout, "%p\n", &b);