On Wed, Nov 16, 2016 at 11:10 AM, David Storrs <david.sto...@gmail.com>
wrote:

> Hi Meino,
>
> As a suggestions, you might want to read through this page on Stack
> Overflow about how to ask technical questions:
> http://stackoverflow.com/help/how-to-ask   The summary is:  tell us what
> you're trying to achieve, what you've tried, and what *specifically* is not
> working.
>
> The question you're asking here (about walk-lists) is hard to help with,
> because it's not clear what the context is.  I'll take my best shot, though:
>
> On Wed, Nov 16, 2016 at 10:04 AM, <meino.cra...@gmx.de> wrote:
>
>> Hi John,
>>
>> thank you for your reply ! :)
>>
>> ...no, not a homework...
>> I want to teach myself some racket and hope 'to get it' finally...
>> Since I am no native speaker I have the deficulty to search for
>> things, which names I dont know...
>>
>> One example of my code is:
>>
>> (define (trim-list lst)
>>   (if (empty? lst)
>>     lst
>>     (cons (string-trim (car lst)) (trim-list (cdr lst)))))
>>
>>
>> (define (walk-sublists lst)
>>   (if (empty? lst)
>>     lst
>>     (cons (trim-list (car lst)) (walk-sublists (cdr lst)))))
>>
>> I want to avoid to call trim-list, if 'car lst' returns an empty list.
>> Instead 'car lst' sghould return the next non-empty list...
>>
>> I will take a look in the reference manual for 'filter' and 'compose'.
>>
>> Cheers
>> Meino
>>
>>
>>
> You might try something like this:
>
> (define (trim-list lst)
>   (if (empty? lst)
>     lst
>     (cons (string-trim (car lst))
> (trim-list (cdr lst)))))
>


Dangit, GMail, hitting 'tab, space' does not necessarily mean I want to
send, it might just mean I want to indent some code.  Sorry for that, all.


(define (trim-list lst) ...)

;;  process a list, but skip any element of the list that is null
(define (walk-sublists lst)
   (cond    [(null? lst) null]
                [(null? (car lst)) (walk-lists (cdr lst))]
                [else (cons (trim-list (car lst))
                                  (walk-sublists (cdr lst))))]))

Code not tested, but let me know if it makes sense.


Dave


>>
>>
>> 'John Clements' via Racket Users <racket-users@googlegroups.com>
>> [16-11-16 18:26]:
>> >
>> > > On Nov 15, 2016, at 19:52, meino.cra...@gmx.de wrote:
>> > >
>> > > Hi,
>> > >
>> > > I have a list of sublists. Some of the sublists are empty.
>> > > The list should be processed recursevly and the resulting
>> > > list should no longer contain empty sublists.
>> >
>> > Is this homework?
>> >
>> > if so: can you show your test cases?
>> >
>> > if not: (filter (compose not null?) l).
>> >
>> >
>> > John Clements
>> >
>> > >
>> > > The code I have so far looks like:
>> > >
>> > > (define (step-through-list lst)
>> > >    (if (empty? lst)
>> > >    lst
>> > >    (cons (process-sublist (car lst)) (step-through-list (cdr lst)))
>> > >
>> > > ....but "car" would feed empty sublists to process-sublist as any
>> other
>> > > sublist. How can I "silently" skip empty sublists and even get out of
>> > > the recursion without harm (if the last sublist is empty) without
>> > > switching to iteration?
>> > > Is there something like "car-not-empty" ? ;)
>> > > Or do I oversee the obvious here...? ;)))
>> > >
>> > > Thank you vary much for any help in advance!
>> > > Cheers
>> > > Meino
>> > >
>> > >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups "Racket Users" group.
>> > > To unsubscribe from this group and stop receiving emails from it,
>> send an email to racket-users+unsubscr...@googlegroups.com.
>> > > For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to racket-users+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to