pattern-matching

Expression Evaluation in C++

Hi, I'm writing some excel-like C++ console app for homework. My app should be able to accept formulas for it's cells, for example it should evaluate something like this: Sum(tablename\fieldname[recordnumber], fieldname[recordnumber], ...) tablename\fieldname[recordnumber] points to a cell in another table, fieldname[recordnumber] poi...

How do I properly match Regular Expressions?

I have a list of objects output from ldapsearch as follows: dn: cn=HPOTTER,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=HGRANGER,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=RWEASLEY,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=DMALFOY,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=SSNAPE,ou=FACULTY,ou=HOGWARTS,o=SCHOOL dn: cn=ADUMBLED,ou=FACULTY,ou=HOGWARTS...

F# matching with two values

I'm fairly new to F# and I wanted to compare two values with the (match ... with ...) syntax The problem arises when I attempt to compare two values like this: let value1 = 19 let isValue1 y = match y with | value1 -> y + 1 | _ -> y I get a warning that the "| _ -> y" portion of the code will never be reached. Why is thi...

How to find similar patterns in lists/arrays of strings

I am looking for ways to find matching patterns in lists or arrays of strings, specifically in .NET, but algorithms or logic from other languages would be helpful. Say I have 3 arrays (or in this specific case List(Of String)) Array1 "Do" "Re" "Mi" "Fa" "So" "La" "Ti" Array2 "Mi" "Fa" "Jim" "Bob" "So" Array3 "Jim" "Bob" "So" "La" "...

Levenshtein algorithm: How do I meet this text editing requirements?

Hi, I'm using levenshtein algorithm to meet these requirements: When finding a word of N characters, the words to suggest as correction in my dictionary database are: Every dictionary word of N characters that has 1 character of difference with the found word. Example: found word:bearn, dictionary word: bears Every dictionary word ...

T-SQL Pattern matching

I am trying to find a way to query rows of data by using a "multivalue" pipe delimited column in another table as a WHERE clause. SQL SERVER 2005 This is my best description of the problem: Imagine a pipe delimited column set to a variable like @LIST = 'Bob|Mary|Joe' then I am trying to find a match like this Select * from Users...

PHP way to execute SQL LIKE matching without a database query?

I want to match an input string to my PHP page the same way a match done by the LIKE command in SQL (MySQL) for consistency of other searches. Since (I have seen but don't comprehend) some of the PHP syntax includes SQL commands I am wondering if this is possible? The reason for this is I am now implementing a search of a keyword versu...

Does Scala's pattern matching violate the Open/Closed Principle?

If I add a new case class, does that mean I need to search through all of the pattern matching code and find out where the new class needs to be handled? I've been learning the language recently, and as I read about some of the arguments for and against pattern matching, I've been confused about where it should be used. See the followi...

Simpler way of pattern matching against start of list in F#

I'm trying to write a string processing function in F#, which looks like this: let rec Process html = match html with | '-' :: '-' :: '>' :: tail -> ("→" |> List.of_seq) @ Process tail | head :: tail -> head :: Process tail | [] -> [] My pattern matching expression against several elements is a bit ugly (the whole '-' :: ...

pattern matching - implementation

hello Im wondering how pattern matching is usually implemented. for example in Erlang do you think its implemented at the byte-code level(there's a bytecode for it so that its done efficiently) or is it generated as a series of instructions(series of bytecodes) by the compiler? it is such a useful thing that I just have to put it into a...

detecting an object on the image based on geometrical form

i have a basic understanding in image processing and now studying in-depth the "digital image processing" by Gonzales, but have an urgent task and will appreciate help from somebody experienced in this area when image given and object of interest approximated form is known (e.g. circle, triangle), what is the best algorithm / method to ...

Determining type on the fly in OCaml's OOP construct

I am learning about OCaml's OOP constructs and partially implemented this today until I realized I have no idea how to represent a polymorphic match statement without using the type keyword outside of the object. class bar (param:string) = object (code) end;; class foo param = object (code) initializer match param with string -...

Why don't Haskell list comprehensions cause an error when pattern match fails?

I'm trying to understand how Haskell list comprehensions work "under the hood" in regards to pattern matching. The following ghci output illustrates my point: Prelude> let myList = [Just 1, Just 2, Nothing, Just 3] Prelude> let xs = [x | Just x <- myList] Prelude> xs [1,2,3] Prelude> As you can see, it is able to skip the "Nothing" an...

Determining if two or more summaries are similar

The problem is as follows: I have one summary, usually between 20 to 50 words, that I'd like to compare to other relatively similar summaries. The general category and the geographical location to which the summary refers to are already known. For instance, if people from the same area are writing about building a house, I'd like to be...

Ruby regular expression help using match to extract pieces of html doc

I have an HTML document of this format: <tr><td colspan="4"><span class="fullName">Bill Gussio</span></td></tr> <tr> <td class="sectionHeader">Contact</td> <td class="sectionHeader">Phone</td> <td class="sectionHeader">Home</td> <td class="sectionHeader">Work</td> </tr> <tr valign="top"> ...

What is currently considered the "best" algorithm for 2D point-matching?

I have two lists containing x-y coordinates (of stars). I could also have magnitudes (brightnesses) attached to each star. Now each star has random position jiggles and there can be a few extra or missing points in each image. My question is, "What is the best 2D point matching algorithm for such a dataset?" I guess both for a simple lin...

Looking for a clean, efficient way to match a set of data against known patterns.

Using php5.2 and MySQL 4.1.22 I've come across something that, at first, appeared simple but has since evaded me in regards to a simple, clean solution. We have pre-defined "packages" of product. Package 1 may have products A, B and C in it. Package 2 may have A, C, D and G in it, etc. The packages range in size from 3 to 5 products. ...

Pattern matching a String as Seq[Char]

In Scala it is possible formulate patterns based on the invididual characters of a string by treating it as a Seq[Char]. An example of this feature is mentioned in A Tour of Scala This is the example code used there: object RegExpTest1 extends Application { def containsScala(x: String): Boolean = { val z: Seq[Char] = x z match...

Why does the empty string not match as Seq.empty?

During some experimentation around question Pattern matching a String as Seq[Char], I ran across another weird matching phenomenon. Consider the following code that treats a string as a sequence of characters: def %%&#(input: String) : String = { val uha : Seq[Char] = input uha match { case Seq() => "Empty" case...

How is pattern matching in Scala implemented at bytecode level?

How is pattern matching in Scala implemented at bytecode level? Is it like a series of if (x instanceof Foo) constructs, or something else? What are its performance implications? For example, given the following code (from Scala By Example pages 46-48), how would the equivalent Java code for the eval method look like? abstract class Ex...