Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #54269
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | .Re: take a sequence of numbers 2 at a time, print numbers and their product? |
| Date | 2017-01-23 04:36 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <o6418g$pb4$1@gioia.aioe.org> (permalink) |
Lieven Marchand wrote:
> (Bob Felts) writes:
>
> > Kaz Kylheku <kkylh...@gmail.com> wrote:
> >
> >> On Dec 27, 2:34 pm, "livingcosmos.org" <metap...@gmail.com> wrote:
> >> > How would you take a sequence of numbers in groups of 2 and print out
> >> > the numbers and their product?
> >> >
> > [...]
> >>
> >> It's perhaps more useful to collect the results than print.
> >>
> >> State machine approach:
> >>
> >> (loop for x across nums
> >> with acc
> >> if (null acc) do
> >> (setf acc x)
> >> else
> >> collect (* x acc) and do
> >> (setf acc nil))
> >
> > Why not just:
> >
> > (loop
> > for x on nums by #'cddr
> > collect (* (first x) (second x)))
> >
> >
> > The original problem might then be:
> >
> > (loop
> > for x on nums by #'cddr
> > for a = (first x) and b = (second x)
> > do
> > (format t "~A * ~A = ~A~%" a b (* a b)))
>
> You can let loop do the destructuring:
>
> (loop for (a b nil) on nums by #'cddr ...)
Ruby:
[0,2,4,5,7,8].each_slice(2){|a,b| puts "#{a} * #{b} = #{a*b}"}
===>
0 * 2 = 0
4 * 5 = 20
7 * 8 = 56
In Forth?
--
Goyim were born only to serve us.... They will work, they will plow, they will
reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef
web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx?id=191782
archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsdwjezqi.ogv
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
.Re: take a sequence of numbers 2 at a time, print numbers and their product? "Robert L." <No_spamming@noWhere_7073.org> - 2017-01-23 04:36 +0000
csiph-web