Re:Why Is Python Growing So Quickly?
by falsedan on Thursday September 14, 2017 @01:22PM
(#15250214)
The python equivalent is
lambda *lst: ''.join([str(lst[0]), str(lst[0]).join([str(_) for _ in lst])])
Which is uh… begging for an initial line of "lst = map(str, lst)"
Re:Why Is Python Growing So Quickly?
by RodgerTheGreat on Friday September 15, 2017 @11:55AM
(#15258159)
If I follow correctly, the equivalent in K would be
{,/(*t),/:t:$x}
Flatten (,/) the first element of the list (*t) joined with each element of the list (a,/:b), where t is the input x cast to a list of strings (t:$x). Curly braces make the expression an anonymous function, and since no argument names are specified explicitly the name x is the single input argument.A more idiomatic solution:
lambda *lst: ''.join(['{}{}'.format(lst[0], _) for _ in lst])
Re:Why Is Python Growing So Quickly?
by AlexCoventry on Thursday September 14, 2017 @02:02PM
(#15250715)
Wow, that was a journey. Thanks.
Prototypes are mostly for giving hints to the compiler on how to unambiguously parse calls to your function later. For an anonymous sub, it's pointless because you assign its value to a variable, and then brackets are required when calling it.
It returns the result of the map (this default in perl is to return the result of the last expression & everything is an expression though) same as python map(code, list) This is a particular perl goof for interpolating array lookups into a string. Usually, perl's sigils let variables be interpolated without any issue, but since we're using $_[0] to use the first element of the @_ array, it's ambiguous with $_ . '[0]'.The @{} dereferences the contents of the braces as an array, and [] creates a new arrayref. The arrayref has one element, and perl's default stringification of an array (join them all with no separator) means that it… iterpolates the thing inside the @{[]} into the surrounding string.
This is pointless though, since it's the only thing in the string. The author might have been trying to give a string context to force stringification of the thing, but the dot operator already provides that context.
This is a string of the first element of … hmm. Not of the currently-mapped element (that's $_). $_[0] refers to the first element of @_. This makes a new value which is the concatenation of the first element with the current element. This is a short way of writing @{ $_ }: dereference the arrayref that's stored in $_. But $_ is not set anywhere, so I assume this is a typo of @_I would have written this as:
And it would work like this: The 'best' way to write it would have been: