Common Lisp から、 NCURSES を触りたくなった。早速、Quicklisp で、 cl-charms をインストールしてみよう:
* (ql:quickload "cl-charms") To load "cl-charms":
(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))))) |
;; 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 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 |
(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)))) |
(in-package :cl-user) | |
;; 表示してまわったり | |
(dolist (p '(1 2 3)) | |
(print p)) | |
;; 和をとってみたり | |
(let ((accum 0)) | |
(dolist (p '(1 2 3 4 5)) | |
(incf accum p)) |
(in-package :cl-user) | |
(destructuring-bind (a b c) | |
'(1 2 3) | |
(print a) ; 1 | |
(print b) ; 2 | |
(print c)) ; 3 | |
(terpri) |
(in-package :cl-user) | |
(setf lis1 (list 1 2 3)) | |
(print lis1) ; (1 2 3) | |
(setf lis2 (list 1 (list 2 3) (list 4 5))) | |
(print lis2) ; (1 (2 3) (4 5)) |
#include <iostream> | |
#include <cassert> | |
#include <cstring> | |
#include <iterator> | |
class Cons; | |
enum class Tag { int_, cons, string }; | |
class Lisp_ptr { |
#include <iostream> | |
#include <cassert> | |
#include <cstring> | |
#include <iterator> | |
class Cons; | |
enum class Tag { int_, cons, string }; | |
class Lisp_ptr { |