Hello Sir,

You are right. I missed that "in-paraller" function which is in Racket
documentation. Using "#:when" is fine since I am currently reporting failures only. In future I might add "debug" -mode which prints each success case too.

Anyways, the big problem is that I have lists of sections (each marked
as: low, high) in a text file I read from top to bottom. None of the sections should overlap:
the next section cannot start before the previous one has ended.

I decided against state-machine (i.e. I am currently reading in
"section1" so only valid next states are: "section1's end marker" or "plain line") because adding all possible error states and messages was tedious.

Therefore I read first the whole file line by line (into vector) and
collect only (section-starts, seaction-ends) -markers into lists.
Then I check with those for*/fold -functions whether sections overlap.
Naturally, this leads looping thru several section -lists and comparison
of each section marker against all other markers because
different sections can be in any relative order. I could reduce the looping by starting the search from the smallest of all section-start markers in any lists but I am not that far yet.

When all section "ranges" are validated I can start processing the
vector of lines one section at a time.

-pekka-


On 7/11/15 12:54 AM, Stephen Chang wrote:
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:

L    V    H

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.

Reply via email to