我爱lisp 发表于 2015-6-2 14:20:41

字符串列表按位置分割为两段的函数


(setq lst (list 1 2 3 4 5 6 7 8 9 ))
(setq num 4)

;;字符串表分割 左边部分
(defun list_left (lst num / new_list num2)
(setq num2 0)
(setq new_list (list))
(mapcar
    '(lambda (x)

       (if (< num2 num)

         (setq new_list (cons x new_list))
       )
       (setq num2 (1+ num2))
   )
    lst
)
(reverse new_list)
)
(list_left lst 1)
;;字符串表分割 右边边部分
(defun list_right (lst num / new_list num2)
(setq num2 0)
(setq new_list (list))
(mapcar
    '(lambda (x)

       (if (>= num2 num)

         (setq new_list (cons x new_list))
       )
       (setq num2 (1+ num2))
   )
lst
)
(reverse new_list)
)

(list_right lst 3)
刚写的,趁热分享一下。呵呵

ivde 发表于 2015-6-2 15:02:16

while更好   

我爱lisp 发表于 2015-6-3 18:18:41

没找到网上有,就自己写了个凑合一下

vladimirputin 发表于 2016-10-23 14:02:36

很好的程序,谢谢楼主分享啊。
页: [1]
查看完整版本: 字符串列表按位置分割为两段的函数