startermili.blogg.se

Lisp function to convert string to list
Lisp function to convert string to list













lisp function to convert string to list

).Data serialization format Tree data structure representing the S-expression (* 2 (+ 3 4)) And you have a universal solution that works for any data set written as a string (as red from a file or. If number of vars change you just have to change variable sequence.

lisp function to convert string to list

It produces a list lst (1000.0 2500.25 "Over the moon")Īnd then simply (mapcar 'set '(px py pd) lst) (setq lst (mapcar '(lambda (x) (if (numberp (read x)) (setq x (read x)) x)) (str_to_lst str))) (while (setq pos (vl-string-search "," str)) If we apply Lee Mac's str_to_lst that proposed then for example (setq str "1e3,2500.25,Over the moon") In a function you just have to make this variable names local. It assigns value 1250.25 to px and so on.

lisp function to convert string to list

If your data are correctly separated by delimiter, then after splitting string into a list, you may simply use something like: Your solution is ok for this particular set, but situation complicates if number of data in list rises, and using strcat become to complicated and asks for to many cond statements.

#Lisp function to convert string to list code#

Self written code that works is best code, no mater how simple or complicated. If that solution suites you then I agree with you. (princ "\nUsage example: (read_to_list str \",\" nil) or any applicable string delimiter.") (princ "\nFunction READ_TO_LST converts delimited string into a list.") (mapcar '(lambda (x) (if (numberp (read x)) (setq x (read x)) x))(reverse ret)) (cond ((and (numberp poz)(>= poz 0))(setq ret (cons (substr str 1 poz) ret) str (substr str (+ poz 2)))) (setq poz (vl-string-position (ascii delimiter) str)) (while (and str (> (strlen str) 0) (numberp poz)) (if clear_spaces (setq str (clear_empty_spaces str))) (while (vl-string-search " " str)(setq str (vl-string-subst "" " " str))) (defun *error* ( ) (princ "\nThere was some error") (princ)) this option may occur when reading strings from file or manually prepared data set if string includes unwanted empty spaces, they can be cleared by setting switch "clear_spaces" to true converts delimited string into a list and respects data types (defun read_to_lst (str delimiter clear_spaces / ret poz *error*) So here is my solution that takes into account data type of particular list element. It is a solution to what asked, but question is what is a final string in a list "B BOM" or "BOM". Here using "read" my create an error (mapcar 'read (LM:str->lst str "," )) It just have to be translated to meaningful data type.

lisp function to convert string to list

I need to convert string as a list in Lisp. Let we see which proposed solution produces correct for:















Lisp function to convert string to list