Arc Forumnew | comments | leaders | submitlogin
Noisy-each bug ?
4 points by thaddeus 5772 days ago | 5 comments
I am under the impression noisy-each is to print a "." every n iterations.

so:

  (noisy-each 4 x "12341234" (pr x))

  should return: 1234.1234
  correct?

  however it seems to clip off an item during the first iteration. 

  arc> (noisy-each 4 x "12341234" (pr x))
  123.4123.4
  
That being said I am unsure if this is a bug or by design...?

seems easy to fix if a bug:

  (mac noisy-each (n var val . body)
    (w/uniq (gn gc)
      `(with (,gn ,n ,gc 0)
         (on ,var ,val
           (when (multiple index ,gn)
             (if (isnt index ,gc) (pr "."))
             (flushout)
             )
           ,@body)
         (prn)
         (flushout))))

T.


4 points by palsecam 5772 days ago | link

Thaddeus, with your fix I get:

   arc> (noisy-each 4 x "1234" (pr x))
   1234
   t
Shouldn't it have a dot at the end? 'pr is called 4 times. You said:

  (noisy-each 4 x "12341234" (pr x))
  should return: 1234.1234
  correct?
I would say it should print "1234.1234." actually.

But anyway, "123.4123" appears as a bug for me too.

The "problem" is that ,@body is executed after the 'when clause that prints (or not) a dot. In the case of 'pr, the order actually makes a difference.

A fix. Inverse 'when and ,@body in the 'each instruction:

   (each ,var ,val
     ,@body
     (when (multiple (++ ,gc) ,gn)
       (pr ".") 
       (flushout)))

Result:

   arc> (noisy-each 4 x "12341234" (pr x))
   1234.1234.  ; this I think is correct
   t

-----

2 points by thaddeus 5772 days ago | link

Agreed - thnx. I was hacking noisy-each to do an intersperse equivalent for a function I am writing -should have stuck to the macro at hand :) T.

-----

1 point by palsecam 5772 days ago | link

Hihi thanks I was going to ask you what you were doing when spotting this bug!

-----

3 points by rntz 5771 days ago | link

This isn't a bug per se. It just prints the dot before it evaluates your code. So the first iteration, it prints 1; the second, 2; the third, 3; the fourth, it prints a dot and THEN prints 4.

-----

1 point by pg 5765 days ago | link

Yes.

-----