predicate

Implementing nth1 list operation in SWI prolog

故事扮演 提交于 2019-12-11 03:58:25
问题 How would you code your own predicate in Prolog, to do exactly what the nth1 function does? For those not familiar with that function, its power is best displayed through an example: ?- nth1(2, [a,b,c], E, R). E = b R = [a, c] When the nth1 function is called, and is passed the following: - an index of an element, of which is to be removed from the list (note that it is not zero-indexed, and that here, we are passing index 2) - the list (in this case, it is [a,b,c]) - E, which will be

breeze.Predicate for Decimal Type

假装没事ソ 提交于 2019-12-11 02:58:14
问题 is there a way to create a breeze predicate for a property that its type is Edm.Decimal? because the datatype in next expression is always double and I don't find a way to say to breeze that I just need create a predicate for a decimal type and not double type, because in final url request I got '10.53 d ' value instead '10.53 m ' value, then the server answer me with an error. var p = new breeze.Predicate( 'UnitPrice' , '>=', 10.53); Thanks in advance. 回答1: You can always explicitly state

Associative list in Prolog

半世苍凉 提交于 2019-12-11 01:13:37
问题 i m doing associative list in prolog i seen this topic but i dont understand the code. Associative Lists in Prolog For checking list is associative isn't enough do this: lists([_X, _Y]). lists([[H|_T]|L],[H|T]):- lists(L,T). Because for first /1 i check if have element in this way [a,3] and /2 take list of list [[a,4],[a,3]] in this way. so first pass call list/2 on [a,3], and check true for base case, and after call [a,4] and call true for base case too. I wrong something, but i don't see,

Need lambda expression OrderBy with DateTime conversion

与世无争的帅哥 提交于 2019-12-10 17:25:50
问题 I am trying to create a lambda expression (Linq, C# 3.5) that can perform a OrderBy on a value that is of data type String but which actually contains a parse-able DateTime. For example, typical values may be "5/12/2009" , "1/14/2008", etc. The OrderBy clause below works correctly for ordering (as if string data), but I actually want to treat the values as DateTimes, and perform the sort by Date. (The sortColumn would be something like "dateCreated".) List<MyObject> orderedList =

Filtering query in Realm by NSDate throws NSInvalidArgumentException

孤街醉人 提交于 2019-12-10 17:21:28
问题 I've looked everywhere, even hitting some dubious sites with virus warning messages that never goes away, and I can't figure this out. I'm simply trying to filter Results<T> object by date: let messages = realm.objects(RMChatMessage).filter("timestamp > \(date)) AND (timestamp <= \(to))")) And whenever this line is run, it raises the following: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "timestamp > 1970-01-01 00:00

Element appears exactly once in the list in Prolog

不羁的心 提交于 2019-12-10 16:48:29
问题 I want to write a predicate which check if the Element appeares exactly once in the List. once(Element, List). My code: once(X, [H | T]) :- \+ X = H, once(X, T). once(X, [X | T]) :- \+ member(X, T). ?- once(c, [b,a,a,c,b,a]). true ?- once(b, [b,a,a,c,b,a]). false. But if I ask: once(X, [b,a,a,c,b,a]). Prolog answers: false Why? Prolog should find X = c solution. Where is bug? 回答1: Running a trace in prolog can be very helpful in determining the answer to this sort of question. We'll do the

CoreData Predicate get every sentence that contains any word in array

此生再无相见时 提交于 2019-12-10 15:53:41
问题 In Swift 4 I have a CoreData "Sentence" model that has a String attribute "englishsentence". I also have an array of "words" and would like to fetch all sentences for which the "englishsentence" attribute contains one or more of the words in the array. var words = ["today", "yesterday", "tomorrow"] This array is just an example. It is supposed to change at runtime and can have any length. and in the fetch request I am trying to do something like this: let fetchRequest = NSFetchRequest

How to pass a predicate as parameter c#

梦想的初衷 提交于 2019-12-10 15:33:52
问题 How can I pass a predicate into a method but also have it work if no predicate is passed? I thought maybe something like this, but it doesn't seem to be correct. private bool NoFilter() { return true; } private List<thing> GetItems(Predicate<thing> filter = new Predicate<thing>(NoFilter)) { return rawList.Where(filter).ToList(); } 回答1: private List<thing> GetItems(Func<thing, bool> filter = null) { return rawList.Where(filter ?? (s => true)).ToList(); } In this expression s => true is the

PredicateBuilder returning zero records

狂风中的少年 提交于 2019-12-10 15:21:09
问题 I'm using PredicateBuilder to create a dynamic Where clause to query data from a DataTable. I have a Dictionary that contains my column names and values I need to search for. I'm simply iterating over the dictionary, if the key matches a column name, then add that key and value to the predicate. Everything seems to work fine until the actual query is run against the datatable, I get zero records back:( But if I replace the dynamic predicate with something like p => p["Year"] == "2010", I get

Linq - Creating Expression<T1> from Expression<T2>

对着背影说爱祢 提交于 2019-12-10 14:29:42
问题 I have a predicate Expression<Func<T1, bool>> I need to use it as a predicate Expression<Func<T2, bool>> using the T1 property of T2 I was trying to think about several approches, probably using Expression.Invoke but couln;t get my head around it. For reference: class T2 { public T1 T1; } And Expression<Func<T1, bool>> ConvertPredicates(Expression<Func<T2, bool>> predicate) { //what to do here... } Thanks a lot in advance. 回答1: Try to find the solution with normal lambdas before you think