pattern-matching

Why no dynamic bit pattern in function argument?

I am experimenting with bit pattern matching in Erlang: -module(test). -export([test/2]). %test(P,<<X:P,0:1>>) -> % X. test(P,X) -> <<Y:P,0:1>> = X, Y. when compiling the commented out version of test/2 i get a complaint that "variable 'P' is unbound". Is there any good reason for not allowing the first version to work th...

Can 2 or more equations defining a function in Haskell share the same where / let block?

Can 2 or more equations defining a function in Haskell share the same where / let block? Let me present a contrived example to illustrate the question. First, consider the following code as a starting point: someFunction v1 v2 v3 = difference ^ v3 where difference = v1 - v2 So far, so good. But then, imagine I need to deal...

How do I assign many values to a particular Perl variable?

I am writing a script in Perl which searches for a motif(substring) in protein sequence(string). The motif sequence to be searched (or substring) is hhhDDDssEExD, where: h is any hydrophobic amino acid s is any small amino acid x is any amino acid h,s,x can have more than one value separately Can more than one value be assigned to o...

Is it recommended to always have exhaustive pattern matches in Haskell, even for "impossible" cases?

Is it recommended to always have exhaustive pattern matches in Haskell, even for "impossible" cases? For example, in the following code, I am pattern matching on the "accumulator" of a foldr. I am in complete control of the contents of the accumulator, because I create it (it is not passed to me as input, but rather built within my func...

Best match between two strings when the order or number of times a word appears is not important?

What is the best algorithm to match or compute the distance between two strings in C# when the order or number of times a word appears is not important? Best means: Would mostly agree with a human match Elegant Efficient Scalable, so that an input string could be matched to a potentially large collection of other strings Related que...

Algorithm for Comparing Words (Not Alphabetically)

Hello, I need to code a solution for a certain requirement, and I wanted to know if anyone is either familiar with an off-the-shelf library that can achieve it, or can direct me at the best practice. Description: The user inputs a word that is supposed to be one of several fixed options (I hold the options in a list). I know the input ...

XSL Rookie -Can I make an XSL that matches "this phrase" also match "ths fraze" without repeating the entire "if test" block?

I'm a complete XSL novice, writing an XSL file to format lots of different error messages that can appear in the output log created by an application into CSV format. Slight variations might occur in the matchable tags in these output logs. For example, one sentence in the log might contain the phrase "Service Month/Year:" but anothe...

Variable substitution in pattern matching?

I'm developing an inference engine, this means that basically I have a certain number of "facts" which are basically the representation of the world in a certain moment. Together with the facts (that usually are only two, the starting state and the goal state) I have many rules (could literally be hundreds for certain problems). The aim ...

simple text matching alogritm for use in stored procedure

I have a table with two fields in an sql server database and my asp.net application calls a stored procedure with a '@SearchString' parameter and the stored procedure finds all records where the @Searchstring value is found in the concatenation of two fields in the table, call them 'Field1' and 'Field2' So the logic looks like this(I ha...

ETS matching probem

I am new to Erlang, and I am learning ETS. I have run into a weird problem. I did: Sometab = ets:new(sometable, [bag]). ets:insert(Sometab, {109, ash, 8}). Then I typed: ets:match(Sometab, {109, ash, '$1'}). However instead of getting 8 - I am getting: ["\b"] as output! What am I doing wrongly? ...

Matching records based on Person Name

Are there any tools or methods that can be used for matching by a person's name between two different data sources? The systems have no other common information and the names have been entered differently in many cases. Examples of non-exact matches: King Jr., Martin Luther = King, Martin (exclude suffix) Erving, Dr. J. = Erving, J. ...

How is this case class match pattern working?

I've just seen this case class in the Scala actors package: case class ! [a](ch: Channel[a], msg: a) And in the JavaDoc it describes usage in the following form: receive { case Chan1 ! msg1 => ... case Chan2 ! msg2 => ... } Why is this not: receive { case !(Chan1, msg1) => ... case !(Chan2, msg2) => ... } Is the bang ope...

jQuery filter through IDs and then capture matches

Hi, I find myself doing this repeatedy. $jq("button").filter(function(){ return this.id.match(/^user_(\d+)_edit$/); }).click(function(){ var matches = this.id.match(/^user_(\d+)_edit$/); var user_id = matches[1]; alert('click on user edit button with ID ' + user_id); }); So I want to apply a click event to some butto...

Fast string matching algorithm with simple wildcards support

I need to match input strings (URLs) against a large set (anywhere from 1k-250k) of string rules with simple wildcard support. Requirements for wildcard support are as follows: Wildcard (*) can only substitute a "part" of a URL. That is fragments of a domain, path, and parameters. For example, "*.part.part/*/part?part=part&part=*". The...

Performant techniques for finding similar values in SQL?

So I've got a column in a table that contains a string values (keywords populated from a 3rd party tool). I'm working on an automated tool to identify clusters of similar values that could probably be normalized to a single value. For example, "Firemen"/"Fireman", "Isotope"/"Asotope" or "Canine"/"Canines". An approach that calculates th...

String matching technique(s) by converting to number?

I have various length strings which are full of Base64 chars. Actualy they are audio recognition datas differs by song-to-song. For easily comparing parts of those strings i divide them into 16-char sub-strings. (which is about 1 second of a song) But in some cases, i just can't compare these ones head to head.. i should be measuring t...

Pattern matching trick for identical values

I just wondered whether it's possible to match against the same values for multiple times with the pattern matching facilities of functional programming languages (Haskell/F#/Caml). Just think of the following example: plus a a = 2 * a plus a b = a + b The first variant would be called when the function is invoked with two similar va...

Haskell Parsing Error

So I have finished creating my own complex number data type in haskell. I've also, thanks to another question on here, got a function that will solve a quadratic equation. The only problem now is that the code generates a parsing error in hugs, when trying to solve a quadratic with complex roots. i.e. In hugs... Main> solve (Q 1 2 1)...

Algorithm for linear pattern matching?

I have a linear list of zeros and ones and I need to match multiple simple patterns and find the first occurrence. For example, I might need to find 0001101101, 01010100100, OR 10100100010 within a list of length 8 million. I only need to find the first occurrence of either, and then return the index at which it occurs. However, doing...

Scala list recursion performance

This question is about the way that Scala does pattern matching and recursion with lists and the performance thereof. If I have a function that recurses over a list and I do it with matching on a cons, for example something like: def myFunction(xs) = xs match { case Nil => Nil case x :: xs => «something» myFunction(xs) } in Hask...