Scala: short form of pattern matching that returns Boolean

This is exactly why I wrote these functions, which are apparently impressively obscure since nobody has mentioned them. scala> import PartialFunction._ import PartialFunction._ scala> cond(“abc”) { case “def” => true } res0: Boolean = false scala> condOpt(“abc”) { case x if x.length == 3 => x + x } res1: Option[java.lang.String] = Some(abcabc) scala> condOpt(“abc”) … Read more

Haskell pattern matching – what is it?

In a nutshell, patterns are like defining piecewise functions in math. You can specify different function bodies for different arguments using patterns. When you call a function, the appropriate body is chosen by comparing the actual arguments with the various argument patterns. Read A Gentle Introduction to Haskell for more information. Compare: with the equivalent … Read more

Pattern matching of lists in Python

So far as I know there’s no way to make it a one-liner in current Python without introducing another function, e.g.: split_list = lambda lst: (lst[0], lst[1:]) head, rest = split_list(my_func()) However, in Python 3.0 the specialized syntax used for variadic argument signatures and argument unpacking will become available for this type of general sequence … Read more

How can I detect common substrings in a list of strings

I would start here: http://en.wikipedia.org/wiki/Longest_common_substring_problem There are links to supplemental information in the external links, including Perl implementations of the two algorithms explained in the article. Edited to add: Based on the discussion, I still think Longest Common Substring could be at the heart of this problem. Even in the Journal example you reference in … Read more

PostgreSQL Full Text Search and Trigram Confusion

They serve very different purposes. Full Text Search is used to return documents that match a search query of stemmed words. Trigrams give you a method for comparing two strings and determining how similar they look. Consider the following examples: SELECT ‘cat’ % ‘cats’; –true The above returns true because ‘cat’ is quite similar to … Read more