Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Scheme > Spliting a list...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 4540 of 4716
Post > Topic >>

Spliting a list of symbols

by BastiL2001@[EMAIL PROTECTED] Jun 6, 2008 at 01:35 PM

Dear group,

I have a list of symbols which may look like this:
(define list1 '(pref_1 justsomething pref_2 interface_1 pref_3
interface_2 pre_1))
(define list2 '(pref_1 something pref_2 interface_1 pref_3 interface_2
pre_1 we you))

I have to sort them into differnet lists depending on their prefixes:
symbols starting with "pre_" go in one list, starting with "pref_" in
another, on more for "interface_" and another one for all the other
symbols... I tried the following code:


(define pref '())
(define pre '())
(define interface '())
(define other '())

(for-each
  (lambda loop
   (cond
      ((string-ci=? (substring (symbol->string (car loop)) 0 4 )
"pre_") (set! pre (cons (car loop) pre)))
      ((string-ci=? (substring (symbol->string (car loop)) 0 5 )
"pref_") (set! pref (cons (car loop) pref)))
      ((string-ci=? (substring (symbol->string (car loop)) 0 10 )
"interface_") (set! interface (cons (car loop) interface)))
      (else (set! other (cons (car loop) other)))))
list1)

(display list1)(newline)
(display pre)(newline)
(display pref)(newline)
(display interface)(newline)
(display other)(newline)

This obviously works for list1 but not for list2. I tried to add an
additional "if" statement, however this fails the "else" to work. How
could this be done? Thanks.

BastiL
 




 5 Posts in Topic:
Spliting a list of symbols
BastiL2001@[EMAIL PROTECT  2008-06-06 13:35:22 
Re: Spliting a list of symbols
Max Hailperin <max@[EM  2008-06-06 21:21:24 
Re: Spliting a list of symbols
BastiL2001@[EMAIL PROTECT  2008-06-07 00:53:24 
Re: Spliting a list of symbols
Filipe Cabecinhas <fil  2008-06-07 12:04:41 
Re: Spliting a list of symbols
Max Hailperin <max@[EM  2008-06-07 08:26:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 15:40:06 CDT 2008.