Content-Length: 37435 | pFad | https://ufo23.hatenadiary.org/entry/20060804/1154672591

nth - 主にアルゴリズムの実験日誌

nth

http://www.bookshelf.jp/texi/elisp-intro/jp/emacs-lisp-intro_9.html

(nth 0 '("one" "two" "three"))
    => "one"

(nth 1 '("one" "two" "three"))
    => "two"

http://www5a.biglobe.ne.jp/~sasagawa/MLEdit/Scheme/scheme9.html

(define nth
  (lambda (n ls)
    (if (= n 1)
        (car ls)
        (nth (- n 1) (cdr ls)))))

CLISPのnthではリストを0から数え始める。

[1]> (nth 1 '(a b))
B
[2]> (nth 0 '(a b))
A

schemeのリストも以下のように配列同様0から数える仕様に変更

(define nth
  (lambda (n ls)
    (if (= n 0)
        (car ls)
        (nth (- n 1) (cdr ls)))))








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://ufo23.hatenadiary.org/entry/20060804/1154672591

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy