help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: list conversion


From: Barry Margolin
Subject: Re: list conversion
Date: Tue, 06 May 2003 20:04:36 GMT

In article <address@hidden>,
Z. Huang <address@hidden> wrote:
>(defun list-conversion (arg)
>  (let ((l arg) (new-list ()))
>    (while l
>      (append new-list (list "" . (car l))))
>      (setq l (cdr l))))

(defun list-conversion (list)
  (mapcar '(lambda (item) (cons "" item)) list))

Here's a version more like your original attempt:

(defun list-conversion (list)
  (let ((l arg) (new-list '()))
    (while l
      (setq new-list (cons (cons "" (car l))))
      (setq l (cdr l)))
    (nreverse new-list)))

Note that you need to re-assign new-list each time through the loop; append
creates a new list, but it doesn't change what new-list refers to.  Also,
you need to use cons, not list, to create something of the form (x . y).

-- 
Barry Margolin, address@hidden
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]