scheme - Reading and recreating a list based on its values -


i want create subset of list based on values. example:

list (aa ab ba dc ad) 

i want list has values of atoms in starting 'a' answer should be:

(aa ab ad) 

i can traversing through whole list , converting each value list , reading first value , recreating list.

this awfully complex solution.

is there method in scheme can read first character of string in list , remove element?

check if scheme implementation has procedure called filter or that. if not can define 1 yourself:

(define (filter p lst)   (let loop ((lst lst) (res ()))     (if (null? lst)         (reverse res)         (if (p (car lst))             (loop (cdr lst) (cons (car lst) res))             (loop (cdr lst) res))))) 

using filter atoms start 'a':

> (filter (lambda (x) (char=? (string-ref (symbol->string x) 0) #\a))            '(aa ab ba dc ad)) => (aa ab ad) 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -