newLISP Fan Club

Forum => newLISP in the real world => Topic started by: HPW on March 21, 2005, 04:34:11 AM

Title: append with first argument optional nil
Post by: HPW on March 21, 2005, 04:34:11 AM
Attempt to made a more alisp compatibel append:



(define (append-nil alist )
(if alist
(begin
(setq _nlst alist)
(dolist (_lst (args))(setq _nlst(append _nlst _lst))))
(begin
(setq _nlst (list ))
(dolist (_lst (args))(setq _nlst(append _nlst _lst))))
))



> (setq a '(1 2))
(1 2)
> (append-nil a '(3)'(4)'(5))
(1 2 3 4 5)
> (append-nil b '(3)'(4)'(5))
(3 4 5)
>


Any better solution?
Title:
Post by: Lutz on March 21, 2005, 05:31:36 AM
Use 'apply append' instead of 'dolist':

(define (append-nil alist)
  (if alist (append alist (apply append (args)))
            (apply append (args))))


Lutz
Title:
Post by: HPW on March 21, 2005, 06:33:53 AM
Thanks a lot. I have still the problem, to get the brain more lispisch.

;-)
Title:
Post by: Lutz on March 21, 2005, 07:51:46 AM
we can make it even shorter:

(define (append-nil alist)
  (append (if alist alist '()) (apply append (args))))


Lutz