ITPub博客

首页 > Linux操作系统 > Linux操作系统 > lisp 习题 our-union

lisp 习题 our-union

原创 Linux操作系统 作者:babyyellow 时间:2012-08-07 12:21:33 0 删除 编辑
            写一个保留原本列表中元素顺序的 union 版本:
 
  
> (new-union '(a b c) '(b a d))
(A B C D)


CL-USER> (defun our-union (fi la)
       (and (listp fi)
        (listp la)
        (let (( res (reverse fi)))
             (dolist (elt la)
               (pushnew elt res))
             (reverse res))))
STYLE-WARNING: redefining COMMON-LISP-USER::OUR-UNION in DEFUN
OUR-UNION
CL-USER> (our-union '(a b c) '(b a d))
(A B C D)
CL-USER> (our-union 'a '(b a d))
NIL
CL-USER> (our-union '(a b) 'a)
NIL
CL-USER> (our-union '(a b) 'a)
NIL


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/133735/viewspace-740221/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: PG 优化器的精彩
请登录后发表评论 登录
全部评论
oracle MySQL Postgresql 专职数据库dba。 系统架构师。 mysql 官方认知dba 。 15年专职dba 经验。 潜意识沟通实证者 心理咨询师。 禅修布道者, 禅修指导员。 禅定实证者。

注册时间:2010-12-02

  • 博文量
    367
  • 访问量
    1908852