Thứ Bảy, 20 tháng 10, 2012

Scheme vs. Common Lisp

Xem so sánh thú vị giữa scheme và common lisp, 2 dialect của Lisp nè
http://community.schemewiki.org/?scheme-vs-common-lisp

Dùng hàm trace để quan sát kết quả chạy đệ quy

CL-USER> (defun list-append (L1 L2)
    "Append L1 by L2."
    (if (null L1)
        L2
        (cons (first L1) (list-append (rest L1) L2))))
LIST-APPEND
CL-USER> (list-append '(a b c) '(c d e))
(A B C C D E)
CL-USER> (trace list-append)
(LIST-APPEND)
CL-USER> (list-append '(a b c) '(c d e))
  0: (LIST-APPEND (A B C) (C D E))
    1: (LIST-APPEND (B C) (C D E))
      2: (LIST-APPEND (C) (C D E))
        3: (LIST-APPEND NIL (C D E))
        3: LIST-APPEND returned (C D E)
      2: LIST-APPEND returned (C C D E)
    1: LIST-APPEND returned (B C C D E)
  0: LIST-APPEND returned (A B C C D E)
(A B C C D E)
CL-USER> 

Cấu hình emacs để chạy Common Lisp

Cấu hình emacs, slime, sbcl để chạy cùng nhau.

Tất cả đều nằm trong file .emacs, nội dung tham khảo như bên dưới:


;;; Common Lisp Mode
;(load (expand-file-name "~/quicklisp/slime-helper.el"))
(setq inferior-lisp-program "/usr/local/bin/sbcl --noinform")
(add-to-list 'load-path "/home/nvntung/softs/slime/")
(add-to-list 'auto-mode-alist '("\\.lisp$" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.cl$" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.asd$" . lisp-mode))
(setq slime-net-coding-system 'utf-8-unix)
(set-language-environment "utf-8")
(require 'slime)
(slime-setup '(slime-repl))
;; (eval-after-load "slime"
;;  '(progn
;;     (setq slime-complete-symbol*-fancy t
;;           slime-complete-symbol-function 'slime-fuzzy-complete-symbol
;;           slime-when-complete-filename-expand t
;;           slime-truncate-lines nil
;;           slime-autodoc-use-multiline-p t)
;;     (slime-setup '(slime-fancy slime-asdf))
;;     (define-key slime-repl-mode-map (kbd "C-c ;")
;;       'slime-insert-balanced-comments)
;;     (define-key slime-repl-mode-map (kbd "C-c M-;")
;;       'slime-remove-balanced-comments)
;;     (define-key slime-mode-map (kbd "C-c ;")
;;       'slime-insert-balanced-comments)
;;     (define-key slime-mode-map (kbd "C-c M-;")
;;       'slime-remove-balanced-comments)
;;     (define-key slime-mode-map (kbd "RET") 'newline-and-indent)
;;     (define-key slime-mode-map (kbd "C-j") 'newline)))
;; (add-hook 'lisp-mode-hook (lambda ()
;;                            (cond ((not (featurep 'slime))
;;                                   (require 'slime)
;;                                   (normal-mode)))
;;                            (indent-tabs-mode nil)
;;                            (pair-mode t)))

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(cua-mode t nil (cua-base))
 '(safe-local-variable-values (quote ((Package . ASDF)))))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

(defun kill-emacs-slime ()
  (interactive)
  (when (slime-connected-p)
    (if (equal (slime-machine-instance) "Gregory-Gelfonds-MacBook-Pro.local")
        (slime-quit-lisp)
      (slime-disconnect)))
  (slime-kill-all-buffers)
  (save-buffers-kill-emacs))

(global-set-key (kbd "C-x C-c") 'kill-emacs-slime)

;; highlight text selection (on by default since emacs 23.2)
(transient-mark-mode 1)

;; make typing overwrite text selection
(setq delete-selection-mode 1) ; this turns on transient-mark-mode automatically

;;; Mot so mode
;; turn on highlight matching parens when cursor is on one
(setq show-paren-style 'parenthesis) ; highlight just parens
;(setq show-paren-style 'expression)  ; highlight entire expression
(show-paren-mode 1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (defun toggle-fullscreen ()
;;   (interactive)
;;   (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
;;                  '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
;;   (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
;;                  '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
;; )
;; (toggle-fullscreen)

(defun set-frame-size-according-to-resolution ()
  (interactive)
  (if window-system
  (progn
    ;; use 120 char wide window for largeish displays
    ;; and smaller 80 column windows for smaller displays
    ;; pick whatever numbers make sense for you
    (if (> (x-display-pixel-width) 1280)
           (add-to-list 'default-frame-alist (cons 'width 120))
           (add-to-list 'default-frame-alist (cons 'width 80)))
    ;; for the height, subtract a couple hundred pixels
    ;; from the screen height (for panels, menubars and
    ;; whatnot), then divide by the height of a char to
    ;; get the height we want
    (add-to-list 'default-frame-alist 
         (cons 'height (/ (- (x-display-pixel-height) 200)
                             (frame-char-height)))))))

(set-frame-size-according-to-resolution)
;;;;; ess-emacs
;;(setq load-path (cons "/usr/share/emacs/site-lisp/ess-5.14/lisp" load-path))
;;(require 'ess-site)

;;http://jekyll.math.byuh.edu/other/howto/R/RE.shtml
(add-to-list 'load-path "/home/nvntung/softs/ess-5.14/lisp/")
(require 'ess-site)

;; (add-to-list 'load-path "/media/Elements/Doctorate/Emacs/")
;; (require 'php-mode)
;; (autoload 'php-mode "php-mode" "Major mode for editing php code." t)
;; (add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
;; (add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))

;; (add-to-list 'load-path "/media/Elements/Doctorate/Emacs/mmm-mode-0.4.8/")
;; (require 'mmm-mode)
;; (setq mmm-global-mode 'maybe)
;; (mmm-add-mode-ext-class nil "\\.php3?\\'" 'html-php)
;; (mmm-add-classes
;;  '((html-php
;;     :submode php-mode
;;     :front "<\\?\\(php\\)?"
;;     :back "\\?>")))
;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . sgml-html-mode))


Save done!

Huyền thoại trí tuệ nhân tạo John McCarthy qua đời ở tuổi 84 - PC World VN

Huyền thoại trí tuệ nhân tạo John McCarthy qua đời ở tuổi 84 - PC World VN
Tin này cũ đã hơn 1 năm rồi nhưng bây giờ mình mới đọc. Bỏ hẳn gần 2 năm không dùng Common Lisp, hôm nay ngó lại blog, tình cờ google xem tình hình bà con làm lisp ở mình thế nào.

Thêm một anh nữa đưa tin, xem và so sánh nội dung:
Cha đẻ của ngôn ngữ lập trình Lisp qua đời ở tuổi 84