yajis_narif Posted May 3, 2011 Posted May 3, 2011 hii !! my programme suppose to loop in 2 list (ptinslist and li )to applicate the translate function.. the first loop worked but the k one doesn't work plzz help (setq k 0) (setq j 0) (while ( (while ( (setq tran (translate (nth k ptinslist)(nth j li))) (setq nvlist (append nvlist (list tran))) (setq j (+ j 1)) ) (setq all (append all (list nvlist))) (setq k (+ k 1)) ) Quote
Tiger Posted May 3, 2011 Posted May 3, 2011 I have changed the title of your thread to something more descriptive, please use more descriptive titles in the futre, it helps. Quote
alanjt Posted May 3, 2011 Posted May 3, 2011 Your snippet is rather confusing, but I think you can accomplish what you are after with mapcar+lambda. eg. (mapcar '(lambda (a b) (translate a b)) ptinlist li ) BTW, translate is not a native function, so I'm assuming it's one you wrote. If it's trans you are trying for, then you'll need three arguments, not two. Quote
yajis_narif Posted May 3, 2011 Author Posted May 3, 2011 ok tiger i will thanks alanjit yes translate is a function : (defun translate (pt1 pt2 /) (mapcar' + pt1 pt2) but i need to loop in the two list (the length of the two list is 4 ) Quote
alanjt Posted May 3, 2011 Posted May 3, 2011 (mapcar '(lambda (a b) (apply 'mapcar (cons '+ (list a b)))) ptinlist li ) Quote
SOliver Posted May 3, 2011 Posted May 3, 2011 If you're intending on goin' with your original code I'd suggest it was written similar to below - for neatnes etc. (setq k -1) (while (< (setq k(1+ k)) Lins) (setq j -1) (while ( < (setq j(1+ j)) Lcord) (setq tran (translate (nth k ptinslist)(nth j li))) (setq nvlist (append nvlist (list tran))) ) (setq all (append all (list nvlist))) ) I'm with alanjt on this one since you're iterating through lists although I think it would need to be (mapcar '(lambda(x) (mapcar '(lambda(y) (translate x y)) Lcoord)) Lins) It depends on what you're trying to achieve: if you're trying to translate every point in Lcoord against every point in Lins then the above mapcar cluster is probably what you're looking for. If you're trying to run translate against each lists' respective coordinate e.g (setq lins (list 0 10 20)) (setq lCoord (list 5 60 80)) ;Example point (translate (nth 0 lins)(nth 0 lCoord)) (translate (nth 1 lins)(nth 1 lCoord)) (translate (nth 2 lins)(nth 2 lCoord)) then you want to go with alanjt's suggestion - which I believe is what you're looking for however; you're posted code is trying to do the solution I've provided. Hope that helps EDIT: Before someone shoots my foot off; all code was written in the respond to thread area and therefore hasn't been tested. Other than the possiblity of an extra right paren or syntax error the principle is sound. Quote
alanjt Posted May 3, 2011 Posted May 3, 2011 If using the subroutine, I think it should look like this: (mapcar '(lambda (a b) (translate a b)) ptinlist li) Quote
yajis_narif Posted May 3, 2011 Author Posted May 3, 2011 thanks every one i will try this and reply for the code i'm trying to do this : (setq lins (list 0 10 20)) (setq lCoord (list 5 60 80)) ;Example point (translate (nth 0 lins)(nth 0 lCoord)) (translate (nth 0 lins)(nth 1 lCoord)) (translate (nth 0 lins)(nth 2 lCoord)) (translate (nth 1 lins)(nth 0 lCoord)) (translate (nth 1 lins)(nth 1 lCoord)) (translate (nth 1 lins)(nth 2 lCoord)) (translate (nth 2 lins)(nth 0 lCoord)) (translate (nth 2 lins)(nth 1 lCoord)) (translate (nth 2 lins)(nth 2 lCoord)) Quote
alanjt Posted May 3, 2011 Posted May 3, 2011 I'm confused, is it a list of points or a list of integers? points: '( (0. 0. 0.) (0. 1. 1.) (1. 1. 1.)) integers: '(0 1 2 3 4 5 6) Quote
yajis_narif Posted May 3, 2011 Author Posted May 3, 2011 no i'ts a list of points actually they are coordinate Quote
SOliver Posted May 3, 2011 Posted May 3, 2011 thanks every one i will try this and reply for the code i'm trying to do this ................................ In that case use the above (and now below) (mapcar '(lambda(x) (mapcar '(lambda(y) (translate x y)) Lcoord)) Lins) Quote
SLW210 Posted May 3, 2011 Posted May 3, 2011 yajis_narif, Please place your codes between code tags. (Just hit the # symbol near the smilies). Thank you. Quote
yajis_narif Posted May 3, 2011 Author Posted May 3, 2011 In that case use the above (and now below) (mapcar '(lambda(x) (mapcar '(lambda(y) (translate x y)) Lcoord)) Lins) i'm not that good with the lambda function but doeas this loop into the list actually this code worked (while ( (setq j -1) (while ( (setq tran (translate (nth k ptinslist)(nth j li))) (setq nvlist (append nvlist (list tran))) ) (setq all (append all (list nvlist))) ) but it return one list of all coordinates actually the first list is a list of four coordinate and the second list is a list of four points too i want to add the first four coordinate to eatch points of the secons list and return a list of 4 list in it i'm sorry i'm not that good in english ^^ Quote
alanjt Posted May 3, 2011 Posted May 3, 2011 yajis_narif, Please place your codes between code tags. (Just hit the # symbol near the smilies). Thank you. Better do what he says; you won't like him when he's angry. Quote
yajis_narif Posted May 3, 2011 Author Posted May 3, 2011 Better do what he says; you won't like him when he's angry. ok i'm sorry i'm new here so... i will do what he says thanks Quote
alanjt Posted May 3, 2011 Posted May 3, 2011 ok i'm sorry i'm new here so... i will do what he says thanks Sorry, it's a reference to his avatar. I was joking. Quote
SOliver Posted May 3, 2011 Posted May 3, 2011 Better do what he says; you won't like him when he's angry. I see what you did there...... Quote
yajis_narif Posted May 3, 2011 Author Posted May 3, 2011 yes yes i know ... he is already angry i guess Quote
BlackBox Posted May 3, 2011 Posted May 3, 2011 Sorry, it's a reference to his avatar. I was joking. You big bully! Do your little girls know you're such a meany to new kids!? LoL Edit - (^^ I too am only joking with a friend ^^) Quote
alanjt Posted May 3, 2011 Posted May 3, 2011 I see what you did there...... Yes, yes, I'm a nerd. yes yes i know ... he is already angry i guess http://en.wikipedia.org/wiki/Hulk_%28comics%29 Quote
Recommended Posts
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.