pattern-matching

Advice for algorithm choice

梦想的初衷 提交于 2019-12-05 06:04:13
I have to do a project that tries to scan the shape of the vehicles and detect what type of vehicle it is , the scanning will performed with a sensors called “vehicle scanner” they are just 50 beams of lights, each beam with receptor and emission as it is shown in the picture: I get from the sensors the raw sate of each beam (block or unblock) and with that continuous scanning we can create a probably very low res image of the vehicle. My question is what algorithms/technique I can use to detect and identify the shape of the vehicle, we want to count the wheels, and if we can, try to identify

Haskell type and pattern matching question: extracting fields from a data type

て烟熏妆下的殇ゞ 提交于 2019-12-05 05:56:04
I'm new to Haskell and working my way through the Write Yourself a Scheme in 48 Hours project and I came upon an instance where I wanted to get the underlying type out of a data type and I'm not sure how to do it without writing conversions for each variant in the type. For example, in the data type data LispVal = Atom String | List [LispVal] | DottedList [LispVal] LispVal | Number Integer | String String | Bool Bool | Double Double I want to write something like: (I know this doesn't work) extractLispVal :: LispVal -> a extractLispVal (a val) = val or even extractLispVal :: LispVal -> a

How to pattern match head and tail types of a scala list?

让人想犯罪 __ 提交于 2019-12-05 05:47:28
I would like to pattern match on different segments of a list in scala on the types of the head and tail : class Solution07 extends FlatSpec with ShouldMatchers { "plain recursive flatten" should "flatten a list" in { val list1 = List(List(1, 1), 2, List(3, List(5, 8))) val list1Flattened = List(1, 1, 2, 3, 5, 8) flattenRecur(list1) should be (list1Flattened) } def flattenRecur(ls: List[Any]): List[Int] = ls match { case (head: Int) :: (tail: List[Any]) => head :: flattenRecur(tail) case (head: List[Int]) :: (tail: List[Any]) => head.head :: flattenRecur(head.tail :: tail) case (head: List[Any

Tuple bang patterns

谁说我不能喝 提交于 2019-12-05 05:45:25
I understand that in: f x = x + 1 where !y = undefined the meaning of the bang pattern is that y is to be evaluated before f . Similarly: f x = x + 1 where !(!a, !b) = (undefined, undefined) the meaning is the same, w.r.t x and y . But what do the bang patterns mean in: f x = x + 1 where (!a, !b) = (undefined, undefined) It doesn't seem to cause undefined to be evaluated. When do in-tuple bang patterns come into effect? If the pattern's tuple is forced? Can anyone give an example where (!a, !b) = (..) differs from (a, b) = (..) ? A bang pattern on the tuple itself will force evaluation of the

Why does _ destroy at the end of statement?

此生再无相见时 提交于 2019-12-05 04:11:58
I've seen a few other questions and answers stating that let _ = foo() destroys the result at the end of the statement rather than at scope exit, which is what let _a = foo() does. I am unable to find any official description of this, nor any rationale for this syntax. I'm interested in a few inter-twined things: Is there even a mention of it in the official documentation? What is the history behind this choice? Is it simply natural fall-out from Rust's binding / destructuring rules? Is it something inherited from another language? Or does it have some other origin? Is there some use-case this

PatternTest not optimized?

妖精的绣舞 提交于 2019-12-05 03:51:55
In preparing a response to An unexpected behavior of PatternTest in Mathematica I came across an unexpected Mathematica behavior of my own. Please consider: test = (Print[##]; False) &; MatchQ[{1, 2, 3, 4, 5}, {x__?test, y__}] During evaluation of In[1]:= 1 During evaluation of In[1]:= 1 During evaluation of In[1]:= 1 During evaluation of In[1]:= 1 False Since, as Simon's quote of the documentation concisely states: In a form such as __?test every element in the sequence matched by __ must yield True when test is applied. I am wondering why Mathematica is testing the first element of the list

Scala, partial functions

自古美人都是妖i 提交于 2019-12-05 03:32:00
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. Not sure I understand the question. But here's my attempt: Why not create an extractor? object ValidBigInt { def unapply(s: String): Option[Int] = { val bi = BigInt(s) if (bi.isValidInt) Some(bi.intValue)

Given mixed accented and normal characters in string not working in java when searching

為{幸葍}努か 提交于 2019-12-05 02:03:48
String text = "Cámélan discovered ônte red aleŕt \n Como se extingue la deuda"; If I give the input Ca, it should highlight from the given string Cá but it's not highlighting. Below is what I tried. Pattern mPattern; String filterTerm; //this is the input which I give from input filter. Say for eg: Ca String regex = createFilterRegex(filterTerm); mPattern = Pattern.compile(regex); private String createFilterRegex(String filterTerm) { filterTerm = Normalizer.normalize(filterTerm, Normalizer.Form.NFD); filterTerm = filterTerm.replaceAll("[\\p{InCombiningDiacriticalMarks}]", ""); return

Can I make Pattern Password Screen Locker android app

偶尔善良 提交于 2019-12-05 01:58:38
问题 Has anyone got experience with developing an application to replace the default lock screen? I've been told it is not possible, however this application manages it. Any tutorials or guidance you know of would be appreciated. 回答1: 100% possible. Here are some links to get you started. Android App and Pattern Lock Screen Android Lock Screen Widget Developing a custom lock screen 回答2: Try this one: lockscreenswitchwidget 回答3: You can implement deviceAdminReciever to use device locks and all

Perl - regex - Position of first nonmatching character

柔情痞子 提交于 2019-12-05 01:43:19
问题 I want to find the position in a string, where a regular expression stops matching. Simple example: my $x = 'abcdefghijklmnopqrstuvwxyz'; $x =~ /gho/; This example shall give me the position of the character 'h' because 'h' matches and 'o' is the first nonmatching character. I thought of using pos or $- but it is not written on unsuccessful match. Another solution would be to iteratively shorten the regex pattern until it matches but that's very ugly and doesn't work on complex patterns. EDIT