他の言語をある程度知っている人はこれを読めばD言語の基礎をマスターでき,D言語の氷山の一角くらいは知ることができると思います.対象バージョンはdmd 2.059です.
ASCIIかUTFしか受け付けません.それ以外の文字コードで書くとコンパイルエラーになります.
D言語のmainはCとは違い以下のようなシグネチャです.
| // 初期値とstepを指定して永遠にカウントするItrator | |
| class Counter[T:Numeric](init:T = 0,step:T = 1) extends Iterator[T] { | |
| var cnt = init | |
| def hasNext = true | |
| def next = { | |
| cnt = implicitly[Numeric[T]].plus(cnt, step) | |
| cnt | |
| } | |
| // 自分をStreamにする | |
| def asStream = Stream.continually( next ) |
| $ find path_to_sourcedir/ -name '*.php' > cscope.files | |
| $ cscope -b | |
| $ cat ~/.vimrc | |
| ... | |
| if has('cscope') | |
| nnoremap <Leader>s :<C-u>scs find s <C-R>=expand("<cword>")<CR><CR> | |
| nnoremap <Leader>g :<C-u>scs find g <C-R>=expand("<cword>")<CR><CR> | |
| nnoremap <Leader>c :<C-u>scs find c <C-R>=expand("<cword>")<CR><CR> | |
| nnoremap <Leader>t :<C-u>scs find t <C-R>=expand("<cword>")<CR><CR> |
| function Klass(x) | |
| { | |
| this.member = { | |
| x: x, | |
| }; | |
| } | |
| Klass.prototype = { | |
| get x() { | |
| return this.member.x; |
| // Written in the D programming language. | |
| /** | |
| * High peformance downloader | |
| * | |
| * Implemented according to <a href="http://yusukebe.com/archives/20120229/072808.html">this implementation</a>. | |
| * | |
| * Example: | |
| * ----- | |
| * dmd -L-lcurl -run downloader.d |
| // Inversefizzbuzz | |
| // http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html | |
| // | |
| object InverseFizzbuzz extends App { | |
| type E = (String,Int) | |
| def zzubzzif(pattern:Seq[String]) = { | |
| val fizzbuzz = (n:Int) => (n%3, n%5) match{ | |
| case (0,0) => ("fizzbuzz", n) | |
| case (0,_) => ("fizz", n) |
| -- -*- coding: utf-8 -*- | |
| import Test.HUnit | |
| deal :: Int -> String -> [String] | |
| deal n s = deal_ 0 (take n $ repeat "") (take ((length s) - (length s `mod` n)) s) | |
| where deal_ _ ys [] = ys | |
| deal_ m ys (x:xs) = deal_ ((m + 1) `mod` n) ((take m ys) ++ [(ys!!m) ++ [x]] ++ (drop (m + 1) ys)) xs | |
| tests = test [ | |
| ["111", "222", "333"] ~=? deal 3 "123123123", |
| ;; zone-pgm-rainbow | |
| (defun decimal->hex (n) | |
| (format "%02X" n)) | |
| (defun hsv->rgb (h s v) | |
| (let ((h (max 0 (min 360 h))) | |
| (s (/ (max 0 (min 100 s)) 100.0)) | |
| (v (/ (max 0 (min 100 v)) 100.0))) | |
| (if (= 0 s) |