Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-16 Thread Meino . Cramer
Hi Justin,

thanks for reply and the code! :)

Cheers
Meino


Justin Zamora  [16-11-17 04:02]:
> I think you are looking for something like this:
> 
> #lang racket
> 
> (require test-engine/racket-tests)
> 
> (define (remove-empty-lists lst)
>   (cond
> [(null? lst) '()] ; Check for end of list
> [(null? (first lst)) (remove-empty-lists (rest lst))] ; Skip null
> sublist
> [(not (list? (first lst))) ; Leave non-lists alone
>  (cons (first lst) (remove-empty-lists (rest lst)))]
> [else ; Process the sublists recursively
>  (cons (remove-empty-lists (first lst))
>(remove-empty-lists (rest lst)))]))
> 
> (check-expect (remove-empty-lists '()) '())
> (check-expect (remove-empty-lists '(a)) '(a))
> (check-expect (remove-empty-lists '(a b c)) '(a b c))
> (check-expect (remove-empty-lists '(())) '())
> (check-expect (remove-empty-lists '(() a)) '(a))
> (check-expect (remove-empty-lists '(a ())) '(a))
> (check-expect (remove-empty-lists '(a (b () c) d)) '(a (b c) d))
> (check-expect (remove-empty-lists '((a) (b c) () (e () f (g ())) h (() i
> j)))
>   '((a) (b c) (e f (g)) h (i j)))
> (test)
> 
> Justin
> 
> On Tue, Nov 15, 2016 at 10:52 PM,  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.
> >
> > 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.


Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-16 Thread Justin Zamora
I think you are looking for something like this:

#lang racket

(require test-engine/racket-tests)

(define (remove-empty-lists lst)
  (cond
[(null? lst) '()] ; Check for end of list
[(null? (first lst)) (remove-empty-lists (rest lst))] ; Skip null
sublist
[(not (list? (first lst))) ; Leave non-lists alone
 (cons (first lst) (remove-empty-lists (rest lst)))]
[else ; Process the sublists recursively
 (cons (remove-empty-lists (first lst))
   (remove-empty-lists (rest lst)))]))

(check-expect (remove-empty-lists '()) '())
(check-expect (remove-empty-lists '(a)) '(a))
(check-expect (remove-empty-lists '(a b c)) '(a b c))
(check-expect (remove-empty-lists '(())) '())
(check-expect (remove-empty-lists '(() a)) '(a))
(check-expect (remove-empty-lists '(a ())) '(a))
(check-expect (remove-empty-lists '(a (b () c) d)) '(a (b c) d))
(check-expect (remove-empty-lists '((a) (b c) () (e () f (g ())) h (() i
j)))
  '((a) (b c) (e f (g)) h (i j)))
(test)

Justin

On Tue, Nov 15, 2016 at 10:52 PM,  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.
>
> 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.


Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-16 Thread Meino . Cramer
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  [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,  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 
> > [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.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails 

Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-16 Thread David Storrs
On Wed, Nov 16, 2016 at 11:10 AM, David Storrs 
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,  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 
>> [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.


Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-16 Thread David Storrs
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,  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 
> [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.


Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-16 Thread Matthias Felleisen

> On Nov 16, 2016, at 1:04 PM, meino.cra...@gmx.de wrote:
> 
> ...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...


Meino, have you considered reading 'Die Macht der Abstraktion?’ (This is a 
guess based on your high-level domain.) — Matthias

-- 
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.


Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-16 Thread Meino . Cramer
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





'John Clements' via Racket Users  [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.


Re: [racket-users] Recursevly processing a list with "wholes"

2016-11-15 Thread 'John Clements' via Racket Users

> 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.


[racket-users] Recursevly processing a list with "wholes"

2016-11-15 Thread Meino . Cramer
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.

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.