[ extra module from newlisp forum ]
Posted: Tue Mar 02, 2004 11:03 pm
A nice enhancement?
if you have more, lets combine them in a new module? forum.lsp
Here is my contribution:
;;
;; The idea is not original but very handy and more readable
;; works on both lists and strings.
;;
;; first, last and rest exist already numbered upto ten for more use.
;;
(define (second x) ( unless (>= 1 (length x)) (nth 1 x) 'nil ))
(define (third x) ( unless (>= 2 (length x)) (nth 2 x) 'nil ))
(define (fourth x) ( unless (>= 3 (length x)) (nth 3 x) 'nil ))
(define (fifth x) ( unless (>= 4 (length x)) (nth 4 x) 'nil ))
(define (sixth x) ( unless (>= 5 (length x)) (nth 5 x) 'nil ))
(define (seventh x) ( unless (>= 6 (length x)) (nth 6 x) 'nil ))
(define (eigth x) ( unless (>= 7 (length x)) (nth 7 x) 'nil ))
(define (ninth x) ( unless (>= 8 (length x)) (nth 8 x) 'nil ))
(define (tenth x) ( unless (>= 9 (length x)) (nth 9 x) 'nil ))
if you have more, lets combine them in a new module? forum.lsp
Here is my contribution:
;;
;; The idea is not original but very handy and more readable
;; works on both lists and strings.
;;
;; first, last and rest exist already numbered upto ten for more use.
;;
(define (second x) ( unless (>= 1 (length x)) (nth 1 x) 'nil ))
(define (third x) ( unless (>= 2 (length x)) (nth 2 x) 'nil ))
(define (fourth x) ( unless (>= 3 (length x)) (nth 3 x) 'nil ))
(define (fifth x) ( unless (>= 4 (length x)) (nth 4 x) 'nil ))
(define (sixth x) ( unless (>= 5 (length x)) (nth 5 x) 'nil ))
(define (seventh x) ( unless (>= 6 (length x)) (nth 6 x) 'nil ))
(define (eigth x) ( unless (>= 7 (length x)) (nth 7 x) 'nil ))
(define (ninth x) ( unless (>= 8 (length x)) (nth 8 x) 'nil ))
(define (tenth x) ( unless (>= 9 (length x)) (nth 9 x) 'nil ))