First off, I'm not going to say RTFM or anything, but seriously the docs are you friend ;-) If you take a look at the documentation for zip: "zip(p, q, ...): Returns an array where the n-th element is an array of the n-th elements from each of the arrays p, q, ..."
The last words are the most significant: "the arrays p, q,". So zip needs arrays. But are your two arguments arrays? Let's use the Firebug plug-in for Firefox (basically the best JS development tool in existence) to find out. If you don't have Firebug you can use alert or using the Mochikit logger instead. // From the Firebug console >>> "This\nis\na\ntest".split("\n") ["This", "is", "a", "test"] >>> isArrayLike("This\nis\na\ntest".split("\n")) true So far so good, now on to argument #2: >>> repeat(BR()) HTMLBRElement >>> repr(repeat(BR())) "repeat([object HTMLBRElement])" >>> isArrayLike(repeat(BR())) false And you see your problem. But what is this HTMLBRElement thing? It's an iterator, and we can see how it works by again using Firebug: >>> keys(repeat(BR())) ["repr", "toString", "next"] toString and repr we've already seen (both just result in "repeat([object HTMLBRElement])"), but next() is more interesting: >>> repeat(BR()).next() <br> There's the <br> you've been trying to get at this whole time. So what's the moral of the story? Well first off, don't use the Iter library functions with non-Iter functions unless they were specifically designed to do so; instead, use them with other Iter library functions like "list": >>> zip(text, list(repeat(BR(), text.length))); [["This", br], ["is", br], ["a", br], ["test", br]] I think appendChildNodes handles flattening that mess for you, but if not just use the function. Also, note "text.length" in that code; without it you script will take an infinite loop (list will keep calling repeat(BR()).next() over and over expecting it to stop, but it won't because you didn't define a limit). Hope that helped. Jeremy On Apr 26, 3:35 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: > I'm somewhat at a loss with the following. > Why does Test 1 display the newlines, but Test 2 does not? > > ------ > > <html><head><title>MochiKit Test</title> > <script src="MochiKit.js" type="text/javascript"></script> > </head><body> > <h2>Test 1</h2><p id="test1"/> > <h2>Test 2</h2><p id="test2"/> > <script type="text/javascript"> > text ="This\nis\na\ntest"; > text = text.split('\n'); > test1 = zip(text, [BR(), BR(), BR(), BR()]); > appendChildNodes("test1", test1); > test2 = zip(text, repeat(BR())); > appendChildNodes("test2", test2); > </script> > </body></html> > > ------ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "MochiKit" group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~----------~----~----~----~------~----~------~--~---