motee-z Posted August 19, 2014 Share Posted August 19, 2014 please help how to convert this list (setq a'("1 2.33 6.45 8.46" "2 8.98 4.78 1.58" "3 4.51 7.12 2.35" "4 6.95 5.64 7.82")) to this list (setq a '((1 2.33 6.45 8.46)(2 8.98 4.78 1.58)(3 4.51 7.12 2.35)(4 6.95 5.64 7.82))) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 20, 2014 Share Posted August 20, 2014 split list? Quote Link to comment Share on other sites More sharing options...
7o7 Posted August 20, 2014 Share Posted August 20, 2014 (edited) You use this: (mapcar '(lambda(x) (read (strcat "(" x ")"))) a) Edited August 20, 2014 by SLW210 Code Tags Quote Link to comment Share on other sites More sharing options...
motee-z Posted August 20, 2014 Author Share Posted August 20, 2014 Thank you very much Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 20, 2014 Share Posted August 20, 2014 Another . (defun 2->list (l) (if l (setq l (cons (read (strcat "(" (car l) ")")) (2->list (cdr l))))) ) Quote Link to comment Share on other sites More sharing options...
7o7 Posted August 20, 2014 Share Posted August 20, 2014 (edited) You are welcome motee-z. @Tharwat : Thanks for the alternative, but in this case I think using mapcar is easier to understand than recursive. Edited August 20, 2014 by 7o7 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 20, 2014 Share Posted August 20, 2014 @Tharwat : Thanks for the alternative, but in this case I think using mapcar is easier to understand than recursive. I do agree with you . Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2014 Share Posted August 21, 2014 (defun 2->list (l) (if l (setq l (cons (read (strcat "(" (car l) ")")) (2->list (cdr l))))) ) Note that there is no need for the setq expression to redefine the variable 'l' - The list will be constructed and returned as a consequence of the cons expression being the last expression evaluated. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 21, 2014 Share Posted August 21, 2014 Note that there is no need for the setq expression to redefine the variable 'l' - The list will be constructed and returned as a consequence of the cons expression being the last expression evaluated. You are right , thank you Lee for taking the time to correct me . Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2014 Share Posted August 21, 2014 You're welcome Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 22, 2014 Share Posted August 22, 2014 You use this: (mapcar '(lambda(x) (read (strcat "(" x ")"))) a) 7o7. i noted your idea as good tips, thanks i didn't notice it was string list by OP, luckily gurus are always here Tharwat alternative idea & Lee simple yet useful advise. Thank you guys Quote Link to comment Share on other sites More sharing options...
7o7 Posted August 22, 2014 Share Posted August 22, 2014 7o7. i noted your idea as good tips, thanks i didn't notice it was string list by OP, luckily gurus are always here Tharwat alternative idea & Lee simple yet useful advise. Thank you guys You are guru too, my friend Quote Link to comment Share on other sites More sharing options...
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.