pattern-matching

Pattern Matching framework?

夙愿已清 提交于 2019-12-11 03:22:22
问题 I will be tackling a Java (GWT) project soon (related question). Maybe I am trying to stretch things here but I was wondering if there is any "pattern matching framework" (don't really know if there is a term for this) written in Java? (maybe it is my prolonged exposure to Erlang that twists my thoughts around patterns all the time :-) I will be using a "message passing" architecture to communicate between my Java components and I'd like to efficiently "match" messages to actions. Maybe I

Why do I get an infinite loop when using implicit conversions?

限于喜欢 提交于 2019-12-11 03:11:08
问题 Context object Fibonacci { final val Threshold = 30 def fibonacci(n: Int)(implicit implementation: Fibonacci): Int = implementation match { case f: functional.type if n > Threshold => fibonacci(n)(imperativeWithLoop) case f: imperativeWithRecursion.type => f(n) case f: imperativeWithLoop.type => f(n) case f: functional.type => f(n) } sealed abstract class Fibonacci extends (Int => Int) object functional extends Fibonacci { def apply(n: Int): Int = if (n <= 1) n else apply(n - 1) + apply(n - 2

“Iterating” over an async method

谁都会走 提交于 2019-12-11 02:49:33
问题 A few related questions about the async CTP: I can iterate over an Iterator Block (an IEnumerable<T> yield-returning T ) using GetEnumerator() and then enumerator methods MoveNext() , and Current() . What is the analog for async methods? How can a non- async calling method to receive and process any await ed items and then ContinueWith() ? Can you provide a short example? I'm just not seeing it. Also, in this following example async method, MyAwaitable has a GetAwaiter() method. If GetAwaiter

Extract a specific key word from a string in R

南楼画角 提交于 2019-12-11 02:40:45
问题 I have a column "place" in my table which contains data about a place that looks like: { "id" : "94965b2c45386f87", "name" : "New York", "boundingBoxCoordinates" : [ [ { "longitude" : -79.76259, "latitude" : 40.477383 }, { "longitude" : -79.76259, "latitude" : 45.015851 }, { "longitude" : -71.777492, "latitude" : 45.015851 }, { "longitude" : -71.777492, "latitude" : 40.477383 } ] ], "countryCode" : "US", "fullName" : "New York, USA", "boundingBoxType" : "Polygon", "URL" : "https://api.twitter

python regexp for a few thousand words

人走茶凉 提交于 2019-12-11 02:21:38
问题 I'm trying to find certain keywords in a string with python. The string is something like this: A was changed from B to C all I'm trying to find is the "to C" part , where C is one of many thousand words . This code builds the regexp string: pre_pad = 'to ' regex_string = None for i in words: if regex_string == None: regex_string = '\\b%s%s(?!-)(?!_)\\b' %(pre_pad, i) else: regex_string = regex_string + '|\\b%s%s(?!-)(?!_)\\b' %(pre_pad, i) And later on I do: matches = [] for match in re

php regex named groups

六眼飞鱼酱① 提交于 2019-12-11 01:35:31
问题 can someone tell me how to use named groups syntax in PHP? I'm trying to parse a simple math equation, for example someVariable!=someValue . I'd like to get 3 values from matching operation, stored in 3 variable variable , operator , value . 回答1: Is this basically what you're looking for? $equation = 'someVariable!=someValue'; $matches = array(); preg_match('~^(\w+)([!=]+)(\w+)$~', $equation, $matches); $variable = $matches[1]; $operator = $matches[2]; $value = $matches[3]; The actual regular

get common lines from two text files [closed]

给你一囗甜甜゛ 提交于 2019-12-11 01:34:38
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I've got two files. The first ( file1 ) is like so: (there is always a headerline before a 'text'line) >random header name1 wonderfulstringwhatsoevergoeson >random header 2 someotherline ... The other file ( file2 ) is a modifed file of file1 like: (the header have been removed and the lines are shuffled, a new

F#: Can someone explain my compiler error?

那年仲夏 提交于 2019-12-11 01:05:38
问题 Anyone know what the problem with this code is? let rec Foo(a,b) = match a () with | None -> Some(b) | Some(c) -> Some(Foo(c,b)) Here's the compiler error: "Type mismatch. Expecting a 'a but given a 'a option The resulting type would be infinite when unifying ''a' and ''a option'" 回答1: Let's try to reproduce how the compiler tries to infer types here. let rec Foo(a,b) = match a () with | None -> Some(b) | Some(c) -> Some(Foo(c,b)) "Ok, so I see a () . a must be a function from unit to some

Lua string.gsub() by '%s' or '\n' pattern

不羁的心 提交于 2019-12-11 01:04:15
问题 English isn't my mother tongue,so it's a little hard to describe the question. I wanna to get 'd=40' in str by lua string.gsub(),but there's some problem. ------code below--- local str = [==[ -- a=10 - -b=20 --c=30 d=40 ]==] local pat1 = [=[%s[%s]]=] local pat2 = [=[\n[%s]]=] str:gsub(pat1, function(s) print("pat1>>" .. s) end) --pat1>>d=40 str:gsub(pat2, function(s) print("pat2<<" .. s) end) --not match local re1,_ = str:gsub("\n","$") local re2,_ = str:gsub("%s","$") print(re1) --a=10$- -b

C# pattern matching

荒凉一梦 提交于 2019-12-10 23:33:42
问题 I am bit new to c#, i am looking for a string matching pattern to do the following, I have a string like this The book will be showcased at a reception in Number 11 Downing Street and will be attended by key healthcare i need to create a span tag to highlight some text fragments using startIndex and length, for an example, startIndex = 3, Length = 10 startIndex = 8, Length = 8 i need to create a span tag dynamically and also create a separate span tag for intersections in this case, The <