Subject: Re: Q: Function to convert 'abc+def = (abc def) From: Erik Naggum <email@example.com> Date: 2000/11/20 Newsgroups: comp.lang.lisp Message-ID: <firstname.lastname@example.org> * "Sandeep Koranne" <email@example.com> | I want a function that takes input a symbol and returns a list made up | of the two components of the input symbol separated by a character '+'. | We can safely assume that there will be one and only one of these special | characters embedded inside. | Also assume that the character is always there. | | I was hoping that | (defun split-on-plus (insym) | (ler ((ret-list nil) | (sym-name (symbol-name insym))) | (push (string-left-trim "+" sym-name) ret-list) | (push (string-right-trim "+" sym-name) ret-list) | ret-list)) Please make an effort to post both tested and readable code. | I hoped this would do the trick, but I found out that the example | given in CLt:L2 (for string-left-trim) dont work on CLISP and "cmucl". | I tried typing them in and all they were doing was throwing the input | string back at me. I highly doubt that. | E.g. (string-left-trim "abc" "labcabcabc") => "labcabc" | (It should give that according to the book) Really? Why do you believe that? Please note that the _left_ edge of this text is in this direction <---, while the _right_ edge of the text is in that direction --->. You need to read the specification of these functions, too. The first argument is not a _string_, but a _collection_ of characters. E.g,, string-right-trim applied to the same arguments would simply return "l". | So what am I doing wrong ???? You are _guessing_ and you fail to be aware of it. That's a cardinal epistemological _sin_, dude. Repent now. | I had to write 'split-on-plus' using (aref ) on the string. | I am sure there must be a better way of getting at sub-strings. Well, position will find the character for you. (defun silly-function-#398 (symbol) (let* ((symbol-name (symbol-name symbol)) (delimiter (position #\+ symbol-name))) (list (intern (subseq symbol-name 0 delimiter)) (intern (subseq symbol-name (1+ delimiter)))))) Not that this necessarily does what you expect, unless you never change which package is current in your system. #:Erik -- ALGORITHM: a procedure for solving a mathematical problem in a finite number of steps that frequently involves repetition of an operation. ALGOREISM: a procedure for solving an electoral problem in a finite number of steps that frequently involves repetition of an operation.