pattern-matching

How to INCLUDE lib files inside [/Libs/x64/Release] folder in a Git repository

泪湿孤枕 提交于 2019-12-10 09:50:12
问题 I have a Git repository that contains a Libs directory in the root. This directory contains all the compiled .lib files that I want to include in the repository and push to main repo. The structure of Libs directory is: Libs ...--| x64 ........--| Release ........--| Debug The problem is that I am unable to make Git include LIB files inside Release and Debug folders. I think its because Release and Debug folders are excluded by gitignore: # Build results [Dd]ebug/ [Rr]elease/ x64/ build/ [Bb

Regex to match Image Url

自古美人都是妖i 提交于 2019-12-10 07:50:04
问题 I am trying to get a simple regex to verify that a URL contains the ending figures var testRegex = /^https?:\/\/(?:[a-z\-]+\.)+[a-z]{2,6}(?:\/[^\/#?]+)+\.(?:jpe?g|gif|png)$/; var imageUrl = "http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-jquery"; if (testRegex.test(imageUrl)) { alert('Not Match'); } And this should trigger alert('Not Match'); and it doesn't ? See http://jsfiddle.net/UgfKn/ What's going on ? 回答1: do you mean: if (!testRegex.test(imageUrl)) { alert('Not

modifying a field while pattern matching on it

梦想的初衷 提交于 2019-12-10 06:45:22
问题 I tried my hands at Rust for the first time today (writing a XML tokenizer), and naturally don’t understand everything: I have a struct with field that can take an enum value: enum State { Outside, InATag(~str) } struct Tokenizer { state: State } In a impl Tokenizer , I want to match on the current state, and change it in some cases, however this always gives a use of moved value error. H to access and/or declare the state field so that I can match on it and change its value inside a match

Search pattern in string using wildcard in Delphi?

▼魔方 西西 提交于 2019-12-10 04:22:58
问题 I used to use HYPERSTR library for string processing routine. Now I use newer Delphi. I need to search a pattern in a string, for example the old function is function IsMatchEx(const Source, Search:AnsiString; var Start:integer) : Integer; . Actually I don't need the result value, I just wanna know if the pattern match with the string or not. My old code (returns TRUE): var StartPos: integer; FoundPos: integer; begin StartPos := 1; FoundPos := IsMatchEx('abcdef', 'abcd?f', StartPos); if

Matching binary patterns in C

隐身守侯 提交于 2019-12-10 04:17:00
问题 I'm currently developing a C program that needs to parse some bespoke data structures, fortunately I know how they are structured, however I'm not sure of how to implement my parser in C. Each of the structures are 32-bits in length, and each structure can be identified by it's binary signature. As an example, there are two particular structures that I'm interested in, and they have the following binary patterns (x means either 0 or 1) 0000-00xx-xxxx-xxx0 0000-10xx-10xx-xxx0 Within these

Pattern matching on List[T] and Set[T] in Scala vs. Haskell: effects of type erasure

試著忘記壹切 提交于 2019-12-10 03:44:16
问题 Would the Haskell equivalent of the code below produce correct answers? Can this Scala code be fixed to produce correct answers ? If yes, how ? object TypeErasurePatternMatchQuestion extends App { val li=List(1,2,3) val ls=List("1","2","3") val si=Set(1,2,3) val ss=Set("1","2","3") def whatIsIt(o:Any)=o match{ case o:List[Int] => "List[Int]" case o:List[String] => "List[String]" case o:Set[Int] => "Set[Int]" case o:Set[String] => "Set[String]" } println(whatIsIt(li)) println(whatIsIt(ls))

Scala, partial functions

拈花ヽ惹草 提交于 2019-12-10 03:24:15
问题 Is there any way to create a PartialFunction except through the case statement? I'm curious, because I'd like to express the following (scala pseudo ahead!)... val bi = BigInt(_) if (bi.isValidInt) bi.intValue ... as a partial function, and doing val toInt : PartialFunction[String, Int] = { case s if BigInt(s).isValidInt => BigInt(s).intValue } seems redundant since I create a BigInt twice. 回答1: Not sure I understand the question. But here's my attempt: Why not create an extractor? object

R Extract a word from a character string using pattern matching

血红的双手。 提交于 2019-12-10 00:50:05
问题 I need some help with pattern matching in R. I need to extract a whole word that starts with a common prefix, from a long character string. The word I want to extract always starts with the same prefix (AA), but the word is not the same length, and does not occur in the same location of the string. mytext1 <- as.character("HORSE MONKEY LIZARD AA12345 SWORDFISH") # Return AA12345 mytext2 <- as.character("ELEPHANT AA100 KOALA POLAR.BEAR") # Want to return AA100 mytext3 <- as.character(

Emulating Prolog backtracking in F#

≯℡__Kan透↙ 提交于 2019-12-09 18:15:20
问题 I am currently involved in a project to develop an application able to consider a set of nodes and connections and find the shortest path (a common and well-known issue) between two nodes (on allowed connections). Well I don't really have to build an application from zero, but just need to "convert" a Prolog pre-existing application in f#. I thought I bit about it and finally asked myself one question: "Instead of developing a special purpose solution and implementing new algorithms

Scala getting field and type of field of a case class

二次信任 提交于 2019-12-09 16:01:19
问题 So I'm trying to get the field and their types in a case class. At the moment I am doing it like so typeOf[CaseClass].members.filter(!_.isMethod).foreach{ x => x.typeSignature match { case _:TypeOfFieldInCaseClass => do something case _:AnotherTypeOfFieldInCaseClass => do something } } the problem is x.typeSignature is of type reflect.runtime.universe.Type which cannot match on any of the types that reside in the case class. Is there some way to do this? 回答1: Let's say you have the following