Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #59639
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Loops/Nested |
| Date | 2017-05-21 09:43 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ofrnfl$11ad$1@gioia.aioe.org> (permalink) |
> Show a nested loop which searches a two-dimensional array
> filled with random numbers uniformly distributed over
> [1 , ... , 20].
>
> The loops iterate rows and columns of the array printing the
> elements until the value 20 is met.
>
> Specifically, this task also shows how to break out of nested loops.
(use gauche.array)
(use gauche.generator)
(use srfi-27)
(define (array->generator ary)
(generate
(lambda (yield)
(array-for-each-index ary
(lambda(i j) (yield (array-ref ary i j)))))))
(define data
(tabulate-array (shape 0 10 0 10) (lambda _ (random-integer 30))))
(generator-find
(lambda (x) (format #t "~a " x) (= 20 x))
(array->generator data))
===>
4 27 23 13 9 25 15 18 4 3 18 14 7 10 19 15 20 20
In Forth?
--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Rosetta: Loops/Nested "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-21 09:43 +0000
Re: Rosetta: Loops/Nested Bruno Gauthier <bgauthier@free.fr> - 2017-05-21 17:13 +0200
Re: Rosetta: Loops/Nested Julian Fondren <julian.fondren@gmail.com> - 2017-05-21 08:29 -0700
Re: Rosetta: Loops/Nested Bruno Gauthier <bgauthier@free.fr> - 2017-05-21 17:47 +0200
csiph-web