Created
December 28, 2014 08:40
-
-
Save xuchunyang/7b346c1c76d63443dae8 to your computer and use it in GitHub Desktop.
elisp-demo-03.el
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; List -- car/cdr/nthcdr/nth | |
(defvar my-list '(a b c) "My demo LIST") | |
my-list | |
(car my-list) | |
a | |
(cdr my-list) | |
(b c) | |
(cons 'a '(b c)) | |
(a b c) | |
(length my-list) | |
3 | |
(length ()) | |
0 | |
(nthcdr 0 my-list) | |
(a b c) | |
(nthcdr 1 my-list) | |
(b c) | |
(nthcdr 2 my-list) | |
(c) | |
(nthcdr 3 my-list) | |
nil | |
(defun my-nthcdr (n a-list) | |
"Implement nthcdr" | |
(while (> n 0) | |
(setq n (1- n)) | |
(setq a-list (cdr a-list))) | |
(message "%S" a-list)) | |
(my-nthcdr 0 my-list) | |
(my-nthcdr 1 my-list) | |
(my-nthcdr 2 my-list) | |
(my-nthcdr 3 my-list) | |
(nth 0 my-list) | |
(nth 1 my-list) | |
(defun my-nth (n list) | |
"Return nth element of LIST" | |
(car (nthcdr n list))) | |
(my-nth 2 my-list) | |
;; How to use loop? | |
(let ((num 0)) | |
(while (< num 5) | |
(princ (format "%d\n" num)) | |
(setq num (1+ num)))) | |
(dotimes (i 5) | |
(princ (format "\n%d" i))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment