I want to make a string "3*3000,2500,2*2000" become a list (3000 3000 3000 2500 2000 2000). I wrote the above code, but get the result: (("3000" "3000" "3000") ("2500" "3000" "3000" "3000") ("2000" "2000" "2500" "3000" "3000" "3000")) Anyone can help me edit my code, so that it only get the result I wanted ?
Title: Re: Delimited string to list, what goes wrong with my code ?
Post by: Tharwat on November 27, 2020, 02:49:00 AM
Title: Re: Delimited string to list, what goes wrong with my code ?
Post by: Lee Mac on November 27, 2020, 05:03:05 AM
You are very close: you just need to declare the list that you are building within the lambda function as local to the lambda function so that the value it holds is reset for every item in the list supplied to mapcar, and then apply the append function to the result in order to acquire a single list.
Title: Re: Delimited string to list, what goes wrong with my code ?
Post by: drawdraw on November 29, 2020, 07:16:33 PM
Thank you very much for all replies ! :smitten: :smitten: :smitten:
Tqvm Lee Mac, now I realised that I should not use (setq lst2 (cons x lst2)) (in line 13), and then add apply 'append. And you show me to reduce the use of variable.
After many times trying, I found a simpler way using foreach: