Hi David,
thanks for the reply and the link! :)
I have a list of sublist, which I want to process recursively.
Some sublists are empty, some are filled.
The typical pattern is (as far as I know)
(define (process-list lst)
(cons (do-somthing-with-sublist (car lst)) (process-lst (car lst))))
But this has the drawback, that empty sublists (via 'car lst') are
processed also. So I need a "kind of car" which returns not the next
sublist but the next not-empty sublist and skipping any empty sublist
without breaking the recursion.
Others on the list already posted some solutions for what I try to
acchieve and this is only to clearify things.
Is it now understandable, what I try to acchieve?
Cheers
Meino
David Storrs <[email protected]> [16-11-16 20:16]:
> 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, <[email protected]> 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)))))
> >
> >
> >
> >
> > 'John Clements' via Racket Users <[email protected]>
> > [16-11-16 18:26]:
> > >
> > > > On Nov 15, 2016, at 19:52, [email protected] 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 [email protected].
> > > > 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 [email protected].
> > > 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 [email protected].
> > 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 [email protected].
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.