Jump to content

failed to understand the error..


nila_joy

Recommended Posts

Hi.. as I told before, I am a beginner in LISP, trying to write something, but getting error.. "error: malformed list on input" . what it means?

 

I have list :- ((((1 . x ) (2 . y)) ((3 . z) (4 . a))) (((1 . m ) (2 . n)) ((3 . o) (4 . p)))))

 

I want this as :- (((x y) (z a)) ((m n) (o p)))

 

 

(defun test1 ()

(setq gb '((((1 . x ) (2 . y)) ((3 . z) (4 . a))) (((1 . m ) (2 . n)) ((3 . o) (4 . p)))))

 

(setq blanka '())

 

(setq blankb '())

 

(setq len1 (length gb))

 

(setq count1 0)

 

(while (

 

(setq data1 (nth count1 gb))

 

(setq len2 (length data1)

 

(setq count2 0)

 

(while (

 

(setq data2 (nth count2 data1))

 

(setq blankb (append blankb (list data2)))

 

(setq count2 (1+ count2))

 

) ; while

 

(setq blanka (append blanka (list data1)))

 

(setq count1 (1+ count2))

 

) ;while

 

)

 

 

 

:ouch:

Link to comment
Share on other sites

It means your parenthesis don't match. You have to have the same number of open parenthesis as closed. That's why LISP stands for "Lost in Stupid Parenthesis."

 

Also, you're new, so you get a pass, but you need to wrap any and all code your post here in the code tags (the button that looks like a pound sign).

 

Then your code will look like this. 

Link to comment
Share on other sites

Maybe this troubleshooter will help you in the future.

 

Also, as resullins states, enclose your code in code tags:

 

[noparse]

[/noparse][/color][color=darkgreen]Your code here[/color][color=red][noparse]

[/noparse]

Link to comment
Share on other sites

Hi.. as I told before, I am a beginner in LISP, trying to write something, but getting error.. "error: malformed list on input" . what it means?

 

I have list :- ((((1 . x ) (2 . y)) ((3 . z) (4 . a))) (((1 . m ) (2 . n)) ((3 . o) (4 . p)))))

 

I want this as :- (((x y) (z a)) ((m n) (o p)))

 

 

(defun test1 ()
 (setq gb '((((1 . x ) (2 . y)) ((3 . z) (4 . a))) (((1 . m ) (2 . n)) ((3 . o) (4 . p)))))

(setq blanka '())

(setq blankb '())

(setq len1 (length gb))

(setq count1 0)

(while (< count1 len1)

(setq data1 (nth count1 gb))

(setq len2 (length data1)

(setq count2 0)

(while (<count2 len2)

(setq data2 (nth count2 data1))

(setq blankb (append blankb (list data2)))

(setq count2 (1+ count2))

) ; while

(setq blanka (append blanka (list data1)))

(setq count1 (1+ count2))

) ;while

 )

Link to comment
Share on other sites

Consider this function:

 

(setq l '((((1 . x ) (2 . y)) ((3 . z) (4 . a))) (((1 . m ) (2 . n)) ((3 . o) (4 . p)))))

(mapcar
   (function
       (lambda ( a )
           (mapcar
               (function
                   (lambda ( b ) (mapcar 'cdr b))
               )
               a
           )
       )
   )
   l
)

Link to comment
Share on other sites

Consider this function:

 

(setq l '((((1 . x ) (2 . y)) ((3 . z) (4 . a))) (((1 . m ) (2 . n)) ((3 . o) (4 . p)))))

(mapcar
   (function
       (lambda ( a )
           (mapcar
               (function
                   (lambda ( b ) (mapcar 'cdr b))
               )
               a
           )
       )
   )
   l
)

HaHa, I was just about to post this:

 

(defun foo (lst)
 (mapcar '(lambda (a) (mapcar '(lambda (b) (mapcar 'cdr b)) a)) lst)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...