[racket-users] Re: How to return summary from the inner loop?

2015-07-10 Thread Pekka Niiranen

Thanks Sir,

This was exactly what I tried to reason.
It never occured to me that parameter failure can be used
in both for/fold -constructs.

About the problem (Stephen):

value-list: '(5, 15, 25)
low-list:   '(1, 11, 21)
high-list:  '(10, 20, 30)

I need to check the following 9 cases:

LVH

1   5  10  BS
1  15  10
1  25  10

11   5  20
11  15  20 BS
11  25  20

21   5  30
21  15  30
21  25  30 BS

-pekka-

On 7/10/15 11:48 PM, Pierpaolo Bernardi wrote:

On Fri, Jul 10, 2015 at 10:45 PM, Pierpaolo Bernardi
olopie...@gmail.com wrote:

If I understand correctly the spec, this should do what you ask?


which, fixing the typo, becomes:

(define (validate-ranges value-list low-list high-list)
   (for/fold ((failures 0))
 ((low (in-list low-list))
  (high (in-list high-list)))
 (for/fold ((failures 0))
   ((value (in-list value-list)))
   (if (= low value high)
 failures
 (add1 failures)




--
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] Re: How to return summary from the inner loop?

2015-07-10 Thread Stephen Chang
I understand now. I still claim that an (explicit) inner loop is not needed:

(define (validate-ranges5 value-list low-list high-list)
  (for*/fold ([failures 0])
 ([(lo hi) (in-parallel low-list high-list)]
  [v value-list]
  #:when ( lo v hi))
(printf \n*** Faulty!: ~a  ~a  ~a\n lo v hi)
(add1 failures)))

(validate-ranges5 '(5 15 25) '(1 11 21) '(10 20 30))

=

*** Faulty!: 1  5  10

*** Faulty!: 11  15  20

*** Faulty!: 21  25  30
3

On Fri, Jul 10, 2015 at 5:40 PM, Pekka Niiranen
pekka.niira...@pp5.inet.fi wrote:
 Thanks Sir,

 This was exactly what I tried to reason.
 It never occured to me that parameter failure can be used
 in both for/fold -constructs.

 About the problem (Stephen):

 value-list: '(5, 15, 25)
 low-list:   '(1, 11, 21)
 high-list:  '(10, 20, 30)

 I need to check the following 9 cases:

 LVH

 1   5  10  BS
 1  15  10
 1  25  10

 11   5  20
 11  15  20 BS
 11  25  20

 21   5  30
 21  15  30
 21  25  30 BS

 -pekka-


 On 7/10/15 11:48 PM, Pierpaolo Bernardi wrote:

 On Fri, Jul 10, 2015 at 10:45 PM, Pierpaolo Bernardi
 olopie...@gmail.com wrote:

 If I understand correctly the spec, this should do what you ask?


 which, fixing the typo, becomes:

 (define (validate-ranges value-list low-list high-list)
(for/fold ((failures 0))
  ((low (in-list low-list))
   (high (in-list high-list)))
  (for/fold ((failures 0))
((value (in-list value-list)))
(if (= low value high)
  failures
  (add1 failures)



 --
 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] Re: How to return summary from the inner loop?

2015-07-10 Thread Pierpaolo Bernardi
On Fri, Jul 10, 2015 at 11:40 PM, Pekka Niiranen
pekka.niira...@pp5.inet.fi wrote:
 Thanks Sir,

 This was exactly what I tried to reason.
 It never occured to me that parameter failure can be used
 in both for/fold -constructs.

I must fix once again my code. Sigh. I fixed a mistake, and renamed
one of the two failures accumulators, so as to avoid possible
confusion. What I should have written in the first place is:

(define (validate-ranges value-list low-list high-list)
  (for/fold ((failures 0))
((low (in-list low-list))
 (high (in-list high-list)))
(for/fold ((failures2 failures))
  ((value (in-list value-list)))
  (if (= low value high)
failures2
(add1 failures2)

Cheers
P.

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