On 6/3/07, Jonathan Lang <[EMAIL PROTECTED]> wrote:
Chas Owens wrote:
> Jonathan Lang wrote:
> > Is there any reason why we can't simply define '$a x $n' as being
> > shorthand for 'cat($a xx $n)'?  In what way does the former differ
> > from the latter, other than the use of a Whatever in place of $n?
>
> "$a x $n" is equivalent to "join '', $a xx $n", but that isn't an apt
> description of its behavior.  "cat($a xx *)" is an attempt to provide
> an infinite string since 'a' x Inf would result in memory overflow
> (but the cat trick works since lists are evaluated lazily).

Then it looks to me like 'cat($a xx $n)' is more flexible than "join
'', $a xx $n", and would work better as the baseline definition for
'$a x $n'.  Is there any reason to prefer a join-based definition to a
cat-based one?  AFAICT, the only thing that 'join' can do that 'cat'
can't is to provide a delimiter when stitching the component strings
together; in the case of 'x', this feature is (rightfully) not being
used.

--
Jonathan "Dataweaver" Lang


Okay, maybe my understanding of the cat function is flawed, but I
thought it walked through each array handed to it in a serial fashion
(as opposed to zip which walks the arrays in a parallel fashion).  If
that is the case then ("a" x 5) ne cat("a" xx 5).  The former produces
a scalar string value of five characters and the other produces a list
of one character scalar string values.  My understanding is that the
cat function and the xx operator are being used in  the documentation
to mimic what an _infinite_ string (not a normal string) would look
like.  Since you cannot have an infinite string with the current
implementation of scalars (memory would give out), a list with lazy
evaluation is used; however, you could not just drop cat("a" xx *)
into a spot where you you were using "a" x 5.

Reply via email to