Search Results

Search found 1037 results on 42 pages for 'lambda calculus'.

Page 34/42 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • Haskell: Problems with overloading: Interpreter can´t tell which + to use

    - by Ben
    Hi, I want to make functions Double - Double an instance of the Num typeclass. I want to define the sum of two functions as sum of their images. So I wrote instance Num Function where f + g = (\ x - (f x) + (g x)) Here the compiler complains he can´t tell whether I´m using Prelude.+ or Module.+ in the lambda expression. So I imported Prelude qualified as P and wrote instance Num Function where f + g = (\ x - (f x) P.+ (g x)) This compiles just fine, but when I try to add two functions in GHCi the interpreter complains again he can´t tell whether I´m using Prelude.+ or Module.+. Is there any way I can solve this problem?

    Read the article

  • Using Where method in Linq 2 Entities with OR clause.

    - by Dani
    I want to use Where method in Linq 2 entities that will be equal to this userRepository.Users.Where(u=>u.RoleID == 1 || u=>u.RoldID == 2).Select(o => new SelectListItem { Text = o.Role.RoleName, Value = o.RoleID.ToString() }).ToList(); The problem of course is in Where(u=u.RoleID == 1 || u=u.RoldID == 2) The problem is that I don't know how to use WHERE method with OR inside the WHERE clause. any ideas (the code above will not compile of-course b/c of the lambda expression. userRepository.Users returns an list of Users entities. I guess that and can be done using concatenation of .Where().Where() but I need an OR.

    Read the article

  • Python sort 2-D list by time string

    - by Mark Kennedy
    How do I sort a multi dimensional list like this based on a time string? The sublists can be of different sizes (i.e. 4 and 5, here) I want to sort by comparing the first time string in each sublist (sublist[-4]) x = (['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['0690', '07:25AM', '09:19AM', 1, 4], ['0201', '08:50AM', '10:50AM', 1, 4], ['1166', '04:35PM', '06:36PM', 1, 4], ['0845', '05:40PM', '07:44PM', 1, 4], ['1267', '07:05PM', '09:07PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['8772', '0159', '12:33PM', '02:43PM', 1, 5], ['0888', '0570', '09:42PM', '12:20AM', 1, 5], ['2086', '2231', '04:10PM', '06:20PM', 1, 5]) The sorted result would be sortedX = (['0690', '07:25AM', '09:19AM', 1, 4], ['0201', '08:50AM', '10:50AM', 1, 4], ['1166', '04:35PM', '06:36PM', 1, 4], ['0845', '05:40PM', '07:44PM', 1, 4], ['1267', '07:05PM', '09:07PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['8772', '0159', '12:33PM', '02:43PM', 1, 5], ['2086', '2231', '04:10PM', '06:20PM', 1, 5], ['0888', '0570', '09:42PM', '12:20AM', 1, 5]) I tried the following: sortedX = sorted(x, key=lambda k : k[-4]) #k[-4] is the first time string and it works but it doesn't respect the sublist size ordering

    Read the article

  • mootools: $ not defined

    - by eaigner
    I've strange error i don't understand. I'm just moving my code from jQuery over to Mootools because it's much cleaner than the jQuery mess. Now when i use the $$('div.canvas') in mootools i get the correct element. When i try $(document).getElement('div.canvas') it tells me that $ is not defined. How can $$ and all helper functions like $lambda etc. be defined but not $? Has something changed there from 1.1 to 1.2 and the docs are not updated yet?

    Read the article

  • mysterious difference between rake test and ruby

    - by standup75
    Here is the mysterious: I have a scope which looks like this (in Image.rb) scope :moderate_all, delegates.where("moderation_flag = #{$moderation_flags[:not_moderated]}") Note that delegates is another scope that I am defining before moderate_all When I leave it like this, I can run my test that checks if an image has been "checked-out" it is not available anymore. I don't put the code of the test, because it does not matter actually. With this code, when I run "rake test" it fails, but if I do "ruby test/unit/image_test.rb" it works! I was thinking I am starting to have a bad day. Then I tried scope :moderate_all, lambda { delegates.where("moderation_flag = #{$moderation_flags[:not_moderated]}") } And "rake test" passes! So my problem is solved, but why?

    Read the article

  • Adding items to dictionary if condition is true, else dont - python

    - by CodeTalk
    I'm trying to take an existing process: if self.path_object is not None: dictpath = {} for path in self.path_object: self.params = path.pathval.split("?")[0] self.params = path.pathval.split("&", 2) if path.pathval.contains(self.params): out = list(map(lambda v: v.split("=")[0] +"=" + str(self.fuzz_vectors), self.params)) else: pass dictpath[path] = out print dictpath I added the sub-if/else block in, but it is failing, stating: AttributeError: 'unicode' object has no attribute 'contains' on the if block . How can I fix it? I'm simply trying to do: if the path.pathval has either ? or & in it: add to dictionary else: pass #forget about it. Thanks!

    Read the article

  • How do I delete an object from an Entity Framework model without first loading it?

    - by Tomas Lycken
    I am quite sure I've seen the answer to this question somewhere, but as I couldn't find it with a couple of searches on SO or google, I ask it again anyway... In Entity Framework, the only way to delete a data object seems to be MyEntityModel ent = new MyEntityModel(); ent.DeleteObject(theObjectToDelete); ent.SaveChanges(); However, this approach requires the object to be loaded to, in this case, the Controller first, just to delete it. Is there a way to delete a business object referencing only for instance its ID? If there is a smarter way using Linq or Lambda expressions, that is fine too. The main objective, though, is to avoid loading data just to delete it.

    Read the article

  • How to compare two lists with duplicated items in one list?

    - by eladc
    I need to compare list_a against many others. my problem starts when there's a duplicated item in the other lists (two k's in other_b). my goal is to filter out all the lists with the same items (up to three matching items). list_a = ['j','k','a','7'] other_b = ['k', 'j', 'k', 'q'] other_c = ['k','k','9','k'] >>>filter(lambda x: not x in list_a,other_b) ['q'] I need a way that would return ['k', 'q'], because 'k' appears only once in list_a. comparing list_a and other_c with set() isn't good for my purpose since it will return only one element: k. while I need ['k','9','k'] I hope I was clear enough. Thank you

    Read the article

  • Text in gtk.ComboBox without active item

    - by Yotam
    The following PyGTk code, gives a combo-box without an active item. This serves a case where we do not want to have a default, and force the user to select. Still, is there a way to have the empty combo-bar show something like: "Select an item..." without adding a dummy item? import gtk import sys say = sys.stdout.write def cb_changed(w): say("Active index=%d\n" % w.get_active()) topwin = gtk.Window() topwin.set_title("No Default") topwin.set_size_request(0x100, 0x20) topwin.connect('delete-event', gtk.main_quit) vbox = gtk.VBox() ls = gtk.ListStore(str, str) combo = gtk.ComboBox(ls) cell = gtk.CellRendererText() combo.pack_start(cell) combo.add_attribute(cell, 'text', 0) combo.connect('changed', cb_changed) ls.clear() map(lambda i: ls.append(["Item-%d" % i, "Id%d" % i]), range(3)) vbox.pack_start(combo, padding=2) topwin.add(vbox) topwin.show_all() gtk.main() say("%s Exiting\n" % sys.argv[0]) sys.exit(0)

    Read the article

  • Syntax errors on Heroku, but not on local server

    - by Phil_Ken_Sebben
    I'm trying to deploy my first app on Heroku (rails 3). It works fine on my local server, but when I pushed it to Heroku and ran it, it crashes, giving a number of syntax errors. These are related to a collection of scopes I use like the one below: scope :scored, lambda { |score = nil| score.nil? ? {} : where('products.votes_count >= ?', score) } it produces errors of this form: "syntax error, unexpected '=', expecting '|' " "syntax error, unexpected '}', expecting kEND" Why is this syntax making Heroku choke and how can I correct it? Thanks!

    Read the article

  • pass parameter from controller to models condition

    - by Alex
    I'm trying to bind a param to a join via a named scope., but I'm getting an error. What is the correct way to do that? has_one :has_voted, :class_name => 'Vote', :conditions => ['ip = :userIp'] # named scopes scope :with_vote, lambda {|ip| { :include => [:has_voted], # like this ?? :conditions => [:has_voted => {:conditions => {:userIp => ip}} ] }} Idea.with_vote(request.ip).all I believe I need the condition definition in the model for it to appear in the ON clause of a JOIN, rather then in the WHERE one. Edit I'm trying to get the following query select Ideas.*, Votes.* from Ideas left outer join Votes on Votes.Idea_id = Idea.id AND Votes.ip = {request.ip}

    Read the article

  • Create an Action<T> to "set" a property, when I am provided with the LINQ Expression for the "get"

    - by Alex
    I'd like to be able to generate a compiled expression to set a property, given the lambda expression that provides the "get" method for a property. Here's what I'm looking for: public Action<int> CreateSetter<T>(Expression<Func<T, int>> getter) { // returns a compiled action using the details of the getter expression tree, or null // if the write property is not defined. } I'm still trying to understand the various types of Expression classes, so if you can point me in the right direction that would be great.

    Read the article

  • Image equivalent of ActionLink in ASP.NET MVC

    - by Jason Whitehorn
    In ASP.NET MVC is there an equivalent of the Html.ActionLink helper for Img tags? I have a controller action that outputs a dynamically generated JPEG and I wanted to use the same Lambda expressions to link to it as I do HREFs using ActionLink. Alternatively, a helper that just gives the URL to a route (again specified using Lambdas) would also be acceptable. EDIT: I had originally specified that I was using Preview 5, however I see that a Beta has been released. So all-in-all the version number was an unneeded piece of info as I may be upgrading soon :-)

    Read the article

  • How to understand the functional programming code for converting IP string to a number?

    - by zfz
    In a python discusion, I saw a way to convert IP string to a integer in functional progamming way. Here is the Link . The function is implemented in a single line. def ipnumber(ip): return reduce(lambda sum, chunk: sum <<8 | chunk, map(int, ip.split("."))) However, I have few ideas of funcional programming. Could anybody explain the function in detail? I've some knowledg of "map" and "reduce". But I don't konw what "|" and "chunk" mean here? Thanks.

    Read the article

  • How to rewrite the following?(C#3.0)

    - by Newbie
    I am trying to write the following double sum_res = 0.0; double yhat = 0; double res = 0; int n = 0; for(int i=0;i<x.Count;i++) { yhat = inter + (slp*x[i]); res = yhat - y[i]; n++; } using lambda but somehow not able to get it work(compile time error) Enumerable.Range(0, x.Count).Select(i => { yhat = inter + (slp * x[i]); res = yhat - y[i]; sum_res += res * res; n++; }); Error: The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Help needed. Thanks

    Read the article

  • python equivalent of filter() getting two output lists

    - by FX
    Let's say I have a list, and a filtering function. Using something like >>> filter(lambda x: x > 10, [1,4,12,7,42]) [12, 42] I can get the elements matching the criterion. Is there a function I could use that would output two lists, one of elements matching, one of the remaining elements? I could call the filter() function twice, but that's kinda ugly :) Edit: the order of elements should be conserved, and I may have identical elements multiple times.

    Read the article

  • Getting list of key values from app config with same name

    - by NoviceMe
    I have follwing in app.config file: <appSettings> <add key="Name" value="Office"/> ... <add key="Name" value="HotSpot"/> ... <add key="Name" value="Home"/> </appSettings> I tried ConfigurationManager.AppSettings["Name"] But it only gives me one Value? How can i get list of all values? I am using c# 3.5. Is there lambda expression or something i can use to get that?

    Read the article

  • Definition of "lisp form"?

    - by josh
    Hi, What exactly the definition of a "Lisp form"? As far as I know, it's "either an atom or a list that has a symbol as its first element". But then, this (in Scheme) would not be a form: ((lambda () 42)) ;; The answer to Life, the Universe and Everything. Because the first element of the list is itself another list. And after it's evaluated it will be a procedure (not a symbol). I can find several different websites and tutorials talking about Lisp forms, but none which gives a complete and detailed definition. Where can I find one?

    Read the article

  • ruby on rails named scopes (searching)

    - by houlahan
    I have a named scope (name) combination of first and last name and I'm wanting to use this in a search box. I have the code below: named_scope :full_name, lambda { |fn| {:joins => :actor, :conditions => ['first_name LIKE ? OR second_name LIKE ?', "%#{fn}%", "%#{fn}%"]} } def self.search(search) if search self.find(:all, :conditions => [ 'full_name LIKE ?', "%#{search}%"]) else find(:all) end end but this doesn't work as it gives the following error: SQLite3::SQLException: no such column: full_name: SELECT * FROM "actors" WHERE (full_name LIKE '%eli dooley%') Thanks in advance Houlahan

    Read the article

  • If item not in the lst in scheme

    - by ms. sakura
    I'm working on context-free grammars, and I have a function that returns the (terminal values of grammar) for example: i have non-terminal function that results in (A B) , from calling say ((A cat) (B happy np) (A B sad)) so technically A and B are non terminals of the grammar. Now I want to be able to get the terminals (cat happy np sad) (define terminals (lambda (lsts) (cond ((null? lsts) lsts) ((not(member? (car(car lsts)) (n-terminals lsts))) (cons (car(car lsts)) (terminals (car (cdr lsts))))) (else (terminals (cdr lsts)))))) PS: functionality of n-terminals is described above. member? is a boolean function that returns true if an item is a member of the list, false otherwise. My function returns an empty lst. What am I missing here?

    Read the article

  • Rails 3 many-to-many query on includes or joins

    - by Myat
    I have three models User, Activity and ActivityRecord. class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :first_name, :last_name, :email, :gender, :password, :password_confirmation, :remember_me # attr_accessible :title, :body has_many :activities has_many :activity_records , :through=> :activities end class Activity < ActiveRecord::Base attr_accessible :point, :title belongs_to :user has_many :activity_records end class ActivityRecord < ActiveRecord::Base attr_accessible :activity_id belongs_to :activity scope :today, lambda { where("DATE(#{'activity_records'}.created_at) = '#{Date.today.to_s(:db)}'")} end I would like to query all activities for a user together with the count for their respective activity records for today. For example, after querying and converting to json format, I would like to have something like below [ { id: 23 title: "jogging", point: "5", today_activity_records_count: 1, }, { id: 12 title: "diet dinner", point: "2", today_activity_records_count: 0, }, ] Please kindly guide me how I can achieve that. Thanks

    Read the article

  • No such file or directory python in linux only (coming from windows)

    - by user1804633
    I have the same exact directory structure within a folder in Windows & in Linux (Debian) - where the script is along the static + dataoutput folders How come the following code works fine in Windows, but gives a no such file or directory path error in linux? @app.route('/_getdataoutputfilelisting') def getdataoutputfilelisting(): listoffilesindataouput = getfiles('static/dataoutput') return jsonify(listoffiles = listoffilesindataouput) def getfiles(dirpath): a = [s for s in os.listdir(dirpath) if os.path.isfile(os.path.join(dirpath, s))] a.sort(key=lambda s: os.path.getmtime(os.path.join(dirpath, s))) a.reverse() return a Is there a way to make it universal such that it works in both OSs? Thanks

    Read the article

  • mysqldb python escaping ? or %s?

    - by asldkncvas
    Dear Everyone, I am currently using mysqldb. What is the correct way to escape strings in mysqldb arguments? Note that E = lambda x: x.encode('utf-8') 1) so my connection is set with charset='utf8'. These are the errors I am getting for these arguments: w1, w2 = u'??', u'??' 1) self.cur.execute("SELECT dist FROM distance WHERE w1=? AND w2=?", (E(w1), E(w2))) ret = self.cur.execute("SELECT dist FROM distance WHERE w1=? AND w2=?", (E(w1), E(w2)) ) File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 158, in execute TypeError: not all arguments converted during string formatting 2) self.cur.execute("SELECT dist FROM distance WHERE w1=%s AND w2=%s", (E(w1), E(w2))) This works fine, but when w1 or w2 has \ inside, then the escaping obviously failed. I personally know that %s is not a good method to pass in arguemnts due to injection attacks etc.

    Read the article

  • Dynamic Paging and Sorting

    - by Ricardo Peres
    Since .NET 3.5 brought us LINQ and expressions, I became a great fan of these technologies. There are times, however, when strong typing cannot be used - for example, when you are developing an ObjectDataSource and you need to do paging having just a column name, a page index and a page size, so I set out to fix this. Yes, I know about Dynamic LINQ, and even talked on it previously, but there's no need to add this extra assembly. So, without further delay, here's the code, in both generic and non-generic versions: public static IList ApplyPagingAndSorting(IEnumerable enumerable, Type elementType, Int32 pageSize, Int32 pageIndex, params String [] orderByColumns) { MethodInfo asQueryableMethod = typeof(Queryable).GetMethods(BindingFlags.Static | BindingFlags.Public).Where(m = (m.Name == "AsQueryable") && (m.ContainsGenericParameters == false)).Single(); IQueryable query = (enumerable is IQueryable) ? (enumerable as IQueryable) : asQueryableMethod.Invoke(null, new Object [] { enumerable }) as IQueryable; if ((orderByColumns != null) && (orderByColumns.Length 0)) { PropertyInfo orderByProperty = elementType.GetProperty(orderByColumns [ 0 ]); MemberExpression member = Expression.MakeMemberAccess(Expression.Parameter(elementType, "n"), orderByProperty); LambdaExpression orderBy = Expression.Lambda(member, member.Expression as ParameterExpression); MethodInfo orderByMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static).Where(m = m.Name == "OrderBy").ToArray() [ 0 ].MakeGenericMethod(elementType, orderByProperty.PropertyType); query = orderByMethod.Invoke(null, new Object [] { query, orderBy }) as IQueryable; if (orderByColumns.Length 1) { MethodInfo thenByMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static).Where(m = m.Name == "ThenBy").ToArray() [ 0 ].MakeGenericMethod(elementType, orderByProperty.PropertyType); PropertyInfo thenByProperty = null; MemberExpression thenByMember = null; LambdaExpression thenBy = null; for (Int32 i = 1; i 0) { MethodInfo takeMethod = typeof(Queryable).GetMethod("Take", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(elementType); MethodInfo skipMethod = typeof(Queryable).GetMethod("Skip", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(elementType); query = skipMethod.Invoke(null, new Object [] { query, pageSize * pageIndex }) as IQueryable; query = takeMethod.Invoke(null, new Object [] { query, pageSize }) as IQueryable; } MethodInfo toListMethod = typeof(Enumerable).GetMethod("ToList", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(elementType); IList list = toListMethod.Invoke(null, new Object [] { query }) as IList; return (list); } public static List ApplyPagingAndSorting(IEnumerable enumerable, Int32 pageSize, Int32 pageIndex, params String [] orderByColumns) { return (ApplyPagingAndSorting(enumerable, typeof(T), pageSize, pageIndex, orderByColumns) as List); } List list = new List { new DateTime(2010, 1, 1), new DateTime(1999, 1, 12), new DateTime(1900, 10, 10), new DateTime(1900, 2, 20), new DateTime(2012, 5, 5), new DateTime(2012, 1, 20) }; List sortedList = ApplyPagingAndSorting(list, 3, 0, "Year", "Month", "Day"); SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.0.320/scripts/clipboard.swf'; SyntaxHighlighter.brushes.CSharp.aliases = ['c#', 'c-sharp', 'csharp']; SyntaxHighlighter.all();

    Read the article

  • JCP.Next - Early Adopters of JCP 2.8

    - by Heather VanCura
    JCP.Next is a series of three JSRs (JSR 348, JSR 355 and JSR 358), to be defined through the JCP process itself, with the JCP Executive Committee serving as the Expert Group. The proposed JSRs will modify the JCP's processes  - the Process Document and Java Specification Participation Agreement (JSPA) and will apply to all new JSRs for all Java platforms.   The first - JCP.next.1, or more formally JSR 348, Towards a new version of the Java Community Process - was completed and put into effect in October 2011 as JCP 2.8. This focused on a small number of simple but important changes to make our process more transparent and to enable broader participation. We're already seeing the benefits of these changes as new and existing JSRs adopt the new requirements. The second - JSR 355, Executive Committee Merge, is also Final. You can read the JCP 2.9 Process Document .  As part of the JSR 355 Final Release, the JCP Executive Committee published revisions to the JCP Process Document (version 2.9) and the EC Standing Rules (version 2.2).  The changes went into effect following the 2012 EC Elections in November. The third JSR 358, A major revision of the Java Community Process was submitted in June 2012.  This JSR will modify the Java Specification Participation Agreement (JSPA) as well as the Process Document, and will tackle a large number of complex issues, many of them postponed from JSR 348. For these reasons, the JCP EC (acting as the Expert Group for this JSR), expects to spend a considerable amount of time working on. The JSPA is defined by the JCP as "a one-year, renewable agreement between the Member and Oracle. The success of the Java community depends upon an open and transparent JCP program.  JSR 358, A major revision of the Java Community Process, is now in process and can be followed on java.net. The following JSRs and Spec Leads were the early adopters of JCP 2.8, who voluntarily migrated their JSRs from JCP 2.x to JCP 2.8 or above.  More candidates for 2012 JCP Star Spec Leads! JSR 236, Concurrency Utilities for Java EE (Anthony Lai/Oracle), migrated April 2012 JSR 308, Annotations on Java Types (Michael Ernst, Alex Buckley/Oracle), migrated September 2012 JSR 335, Lambda Expressions for the Java Programming Language (Brian Goetz/Oracle), migrated October 2012 JSR 337, Java SE 8 Release Contents (Mark Reinhold/Oracle) – EG Formation, migrated September 2012 JSR 338, Java Persistence 2.1 (Linda DeMichiel/Oracle), migrated January 2012 JSR 339, JAX-RS 2.0: The Java API for RESTful Web Services (Santiago Pericas-Geertsen, Marek Potociar/Oracle), migrated July 2012 JSR 340, Java Servlet 3.1 Specification (Shing Wai Chan, Rajiv Mordani/Oracle), migrated August 2012 JSR 341, Expression Language 3.0 (Kin-man Chung/Oracle), migrated August 2012 JSR 343, Java Message Service 2.0 (Nigel Deakin/Oracle), migrated March 2012 JSR 344, JavaServer Faces 2.2 (Ed Burns/Oracle), migrated September 2012 JSR 345, Enterprise JavaBeans 3.2 (Marina Vatkina/Oracle), migrated February 2012 JSR 346, Contexts and Dependency Injection for Java EE 1.1 (Pete Muir/RedHat) – migrated December 2011

    Read the article

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >