Skip to content

Instantly share code, notes, and snippets.

View shirok's full-sized avatar

Shiro Kawai shirok

View GitHub Profile
@shirok
shirok / tax.md
Last active July 14, 2018 07:10

消費税の計算

  • 原材料: A社
  • 製造: B社
  • 卸: C社
  • 小売: D社

消費税が無い状態で、小売売価100、卸値70、製造販売価50、原材料価格20とする。1個商品が売れた場合

| |売価|仕入れ値|粗利|

;; -*- coding:utf-8 -*-
(define-syntax 入 lambda)
(define-syntax 亼
(er-macro-transformer
(入 [f r c]
(quasirename r
(入 (,'_) ,@(cdr f))))))
#|
(define-library (d)
(import (scheme base))
(begin
(define-values (a$1 b$1 c$1 d$1 e$1 f$1 g$1 h$1
i$1 j$1 k$1 l$1 m$1 n$1 o$1 p$1
q$1 r$1 s$1)
(values 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19))
(define-values (a$2 b$2 c$2 d$2 e$2 f$2 g$2 h$2
i$2 j$2 k$2 l$2 m$2 n$2 o$2 p$2
q$2 r$2 s$2)
(define-library (a)
(import (scheme base))
(export a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19
a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38
a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57
a58 a59 a60 a61 a62 a63 a64 a65 a66 a67 a68 a69 a70 a71 a72 a73 a74 a75 a76
a77 a78 a79 a80 a81 a82 a83 a84 a85 a86 a87 a88 a89 a90 a91 a92 a93 a94 a95
a96 a97 a98 a99 a100 a101 a102 a103 a104 a105 a106 a107 a108 a109 a110 a111
a112 a113 a114 a115 a116 a117 a118 a119 a120 a121 a122 a123 a124 a125 a126
a127 a128 a129 a130 a131 a132 a133 a134 a135 a136 a137 a138 a139 a140 a141
[1]> (defvar a 0)
A
[2]> (defvar b 1)
B
[3]> (setf (if t a b) 10)
10
[4]> a
10
[5]> b
1
gosh> (describe 64)
64 is an instance of class <integer>
(#x40, #\@ as char, 1970-01-01T00:01:04Z as unix-time)
gosh> (describe 1234567890)
1234567890 is an instance of class <integer>
(#x499602d2, ~ 1.2Gi, 2009-02-13T23:31:30Z as unix-time)
;; objsは文字列のリストに限らず任意のオブジェクトのリスト
(defun join (separator objs)
(format nil "~{~a~#,1^~a~}" (mapcan (lambda (s) (list s separator)) objs)))
;; separatorが固定なら多少わかりやすい。というかこのケースならformatを直接書くだろう。
(defun join-by-comma (objs)
(format nil "~{~a~^, ~}" objs))
#|
[6]> (join "-" '(tic tac toe))
gosh> (define a '#0=(#1=(#0#)))
a
gosh> (define b (car a))
b
gosh> (eq? b (car a))
#t
gosh> (eq? a (car b))
#t
gosh> (equal? a b)
#t
@shirok
shirok / f.scm
Created September 17, 2017 12:33
(use math.prime)
(do ([p *primes* (cdr p)]
[n 1 (+ n 1)]
[sum 2 (+ sum (cadr p))])
[#f]
(when (integer? (/ sum n))
(format #t "f(~d) = ~d (~a)\n" n (/ sum n)
(if (bpsw-prime? (/ sum n)) "prime" "composite"))))
gosh> (define (foo ls)
(if (null? ls)
'(0)
(map + ls (append (foo (cdr ls)) '(0)))))
foo
gosh> (foo '(1 2 3))
(6 5 3)
;; 1 2 3
;; 2 3 0