tag:blogger.com,1999:blog-7225373.post975974350736025712..comments2024-02-29T03:34:23.190-05:00Comments on Who Were the Sea Peoples?: A common programming problem without a generic solution?gcallahhttp://www.blogger.com/profile/10065877215969589482noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-7225373.post-16558402829268125742016-03-03T15:55:30.678-05:002016-03-03T15:55:30.678-05:00In environments with higher-order functions there ...In environments with higher-order functions there will usually be a function for this case. In Scala, for example:<br /><br />names.reduceLeft[String] { (acc, n) => acc + ", " + n }<br /><br />I lifted the example from '<a href="http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-2" rel="nofollow">Scala Collections for the Easily Bored</a>' as I haven't done Scala in a while.Crosbiehttps://www.blogger.com/profile/02005295490663931940noreply@blogger.comtag:blogger.com,1999:blog-7225373.post-87451843196487753792016-03-03T12:58:47.316-05:002016-03-03T12:58:47.316-05:00Algebraic types in functional programming, eg Hask...Algebraic types in functional programming, eg Haskell. But that's a niche market.Ken Bhttps://www.blogger.com/profile/12976919713907046171noreply@blogger.comtag:blogger.com,1999:blog-7225373.post-54769517773772402132016-03-03T03:25:27.375-05:002016-03-03T03:25:27.375-05:00Python and Scala, among many, provide a case-speci...Python and Scala, among many, provide a case-specific solution for strings in the form of the `join` and `mkString` methods, respectively.<br /><br />In general, you are right: languages and standard libraries don't provide a way to special-case the last element in a generic collection when looping. Languages with pattern matching do provide a fairly minimal syntax for doing so, but you have to use recursion instead of looping. Even then, in those contexts using direct recursion is often frowned upon in favor of higher-order functions such as `fold`.<br /><br />Out of curiosity: do you have a case for doing this other than making a delimited string?Matthttps://www.blogger.com/profile/02470489293820651609noreply@blogger.com