From ... From: Erik Naggum Subject: Re: Q: Function to convert 'abc+def = (abc def) Date: 2000/11/20 Message-ID: <3183715001067568@naggum.net>#1/1 X-Deja-AN: 695742076 References: <8vb4cj$evi$1@porthos.nl.uu.net> mail-copies-to: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 974726222 9231 195.0.192.66 (20 Nov 2000 13:17:02 GMT) Organization: Naggum Software; vox: +47 800 35477; gsm: +47 93 256 360; fax: +47 93 270 868; http://naggum.no; http://naggum.net User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 Mime-Version: 1.0 NNTP-Posting-Date: 20 Nov 2000 13:17:02 GMT Newsgroups: comp.lang.lisp * "Sandeep Koranne" | 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.