Model matching using information from theorems

I have the following question, look in the code. (* Suppose we have type A *) Variable A: Type. (* Also we have a function that returns the type (option A) *) Definition f_opt x: option A := ... (* Then, I can prove that this function always returns

Recursive search function of patterns in vim

I have a text file with simple text lines. I want to create a function for vim (and gvim) text editor which can be sent a variable number of patterns and it should find lines will all patterns (in any order) and keep only these lines while deleting t

Understand the distribution of the classes of cases

If I have case class defined as below case class Calculator(brand: String, model: String) How does it's companion object's unapply method would look like? What type of arguments would it take? I am not able to emulate this by defining a class and the

How to prove a definition of proof in Coq

I am currently working with Coq and I am encountering a problem that I don't know how to solve. Let's say we are working with a given type, I'll take nat for the example, and I want to use a function f that might fail. To compensate the failure, we d

regular expression match _ beds

I have a string like this : 002_part1_part2_______________by_test and I would like to stop the match at the second underscore character, like this : 002_part1_part2_ How can I do that with a Regular expression ? ThanksCreate a pattern to match any ch

Count with a comparator

Is there a shorter way to write the following (QuizWord is a case class): list.count { case w: QuizWord => true; case _ => false} Sometimes using isInstanceOf can be more readable than pattern matching. And this will be as efficient. list.count(_.is

motif in Erlang

I am trying to learn some Erlang while I got stuck on these several Erlang pattern matching problems. Given the module here: -module(p1). -export([f2/1]). f2([A1, A2 | A1]) -> {A2, A1}; f2([A, true | B]) -> {A, B}; f2([A1, A2 | _]) -> {A1,A2}; f2

rename target files in GNU Makefile

the makefile below processes files matching the patterncontent/%.md and outputs the targets in the html directory. Source files are named with the convention of putting a leading number in front of them, like content/01.index.md or content/O2.second-

How to Fix the Comprehensive Pattern Matching Warning?

Some scala code: val list = List(Some("aaa"), Some("bbb"), None, ...) list.filter(_!=None).map { case Some(x) => x + "!!!" // I don't want to handle `None` case since they are not possible // case None } When I run it, the

Which model occurs the most in a matrix - R (UPDATE)

UPDATE 2 *I've added some code (and explanation) I wrote myself at the end of this question, this is however a suboptimal solution (both in coding efficiency as resulting output) but kind of manages to make a selection of items that adhere to the con

OCaml: pattern matching on variable length strings

I'm trying to write a program that accepts user input (one line at a time) and evaluates this user input in some ways. I have a function getline : unit -> string that reads a string from stdin and returns it. The commands have the following format: #

Left string, variable match in a DOS command?

Is it possible to do a string pattern match in DOS? For instance I want to do the following: if "%USERNAME" == "abc*" (echo 1) I know the asterisk doesn't work here and I can't find an alternative. Anyone have any ideas?Try if "%U

Creating a larger list of lists using a pattern

Let's say I have the following pattern: PATTERN = [[1, 2, 3],[4, 5, 6],[7, 8, 9]] and I want to use this to create the following: PATTERN | HORIZONTAL_MIRROR (PATTERN) VERTICAL_MIRROR(PATTERN) | HORIZONTAL_MIRROR(VERTICAL_MIRROR(PATTERN)) In other wo

Preg_Replace in a template

I am struggling with a way to make this more efficient. Is it possible to make the loop into a single line? Edit: looking to replace the loop. $template = "<div>[@ data]</div>"; $arrayData = array('hello', 'hi', 'hola'); foreach ($ar

KMP prefix table

I am reading about KMP for string matching. It needs a preprocessing of the pattern by building a prefix table. For example for the string ababaca the prefix table is: P = [0, 0, 1, 2, 3, 0, 1] But I am not clear on what does the numbers show. I read

How can I * exclude

I have a dataframe (data) which includes a lot of dates. I want to lop off everything from before 1970. I can create a list of indices that are before 1970: tmp <- which(data$data < '1970-01-01') [1] 13446 102876 141199 and I want to create a new ta

model matching using scanf in C

I have been stuck up with this issue. The requirement of the problem is very simple. All I want to do is check user input and allow the user to enter only lower case letters. The other constraint is I want to do it using only scanf(). I know I can us

Validation Regex grails date-like format

Im currently working in a grails project and I ended up to a problem regarding matches constraints in grails. My field should only accept a String with a date-like format exactly like this: 10-25-2012 5:00PM Is this possible in matches constraint usi

Why typeclasses instead of just the template match?

This is something of a philosophical question, but one I hope to have answered by official documentation or "word of god" (read: SPJ). Is there a specific reason that the Haskell committee chose to require explicit interfaces in the form of type

User input in the database

Suppose that, we're expecting just strings or numbers with the data send by a user. Is it safe enough to check the data with ereg and preg_match functions? Is there a way to fake them? Should we still use mysql_real_escape_string?safe enough is relat

Erlang pattern matching of a list of records on receive

I'm trying to create a generic receive for a part of my app that requires to wait for several updates at different times. This is the prototype that it is not working. receive_info([])->[]; receive_info([RequiredInfo|RestRequiredInfos]) -> receive R

How to model when something is NOT of a particular type

We're all used to pattern-matching for cases when something is a particular type, e.g., match x with | Y(x) :: tail -> ... // assumes List.head(x) is of type Y(x) But how can can I match the case when something is not of a particular type? E.g., matc