この文章は、 Lisp Advent Calendar 2014 の 12/11 担当分の記事として書かれました。
C系言語から Common Lisp に移行した時、「どうして Lisp はこんなに書き辛いんだ?」と思っていたことを記憶しています。
;; http://d.hatena.ne.jp/yarb/20110202/p1 | |
;; http://okajima.air-nifty.com/b/2011/01/2011-ffac.html | |
;;; solving time (19 chain) -- 1h26min :/ | |
;; -rw-r--r-- 1 y2q staff 4656 5 16 04:58 puyopuyo.lisp | |
;; -rw-r--r-- 1 y2q staff 22 5 16 03:32 puyopuyo.lisp~ | |
(ql:quickload "alexandria") | |
(in-package :cl-user) |
(in-package :cl-user) | |
#| | |
(ql:quickload :chirp) | |
(setf chirp:*oauth-api-key* "**************************" | |
chirp:*oauth-api-secret* "***************************" | |
chirp:*oauth-access-token* "*******************************" | |
chirp:*oauth-access-secret* "***************************") | |
|# |
(in-package :cl-user) | |
;; https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour | |
;; 1:00 | |
(defun problem1-for (numlist) | |
(let ((ret 0)) | |
(dolist (n numlist ret) | |
(incf ret n)))) |
この文章は、 Lisp Advent Calendar 2014 の 12/11 担当分の記事として書かれました。
C系言語から Common Lisp に移行した時、「どうして Lisp はこんなに書き辛いんだ?」と思っていたことを記憶しています。
;; 前置きとして… | |
;; どんな言語にもあると思いますが、 Common Lisp にも一般的なスタイルがあります。 | |
;; まずは、それに目を通すことをおすすめします。 | |
;; | |
;; Google Common Lisp Style Guide | |
;; en: https://google-styleguide.googlecode.com/svn/trunk/lispguide.xml | |
;; jp: http://lisphub.jp/doc/google-common-lisp-style-guide/ | |
;; | |
;; Tutorial on Good Lisp Programming Style | |
;; en: http://www.norvig.com/luv-slides.ps |
(defun join (lis &optional (sep " ")) | |
(reduce #'(lambda (x y) | |
(concatenate 'string | |
(princ-to-string x) sep (princ-to-string y))) | |
lis)) | |
#| | |
CL-USER> (defun join (lis &optional (sep " ")) | |
(reduce #'(lambda (x y) | |
(concatenate 'string |
;; Haskell の $ もどき in Common Lisp | |
;; http://practical-scheme.net/wiliki/wiliki.cgi?Gauche%3A%24 | |
;; (fn1 $ fn2 $ fn3 $ fn4 x) -> (fn1 (fn2 (fn3 (fn4 x)))) | |
(defun $-expand (forms) | |
(cond ((null forms) | |
nil) | |
((eq '$ (car forms)) | |
(list ($-expand (cdr forms)))) | |
(t |
(defun suffix-transpose1 (form terminal) | |
(if form | |
(suffix-transpose1 (cdr form) | |
(list (cons (car form) terminal))) | |
terminal)) | |
(defun suffix-transpose (form) | |
(car (suffix-transpose1 (cdr form) | |
(list (car form))))) |