Search Results

Search found 1103 results on 45 pages for 'eager evaluation'.

Page 6/45 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Python style: if statements vs. boolean evaluation

    - by mkscrg
    One of the ideas of Python's design philosophy is "There should be one ... obvious way to do it." (PEP 20), but that can't always be true. I'm specifically referring to (simple) if statements versus boolean evaluation. Consider the following: if words: self.words = words else: self.words = {} versus self.words = words or {} With such a simple situation, which is preferable, stylistically speaking? With more complicated situations one would choose the if statement for readability, right?

    Read the article

  • Lazy evaluation in Ruby

    - by fifigyuri
    I have a situation for Ruby, where an object is possibly necessary to be created, but it is not sure. And as the creation of the object might be costly I am not too eager creating it. I think this is a clear case for lazy loading. How can I define an object which is not created only when someone sends a message to it? The object would be created in a block. Is there a way for simple lazy loading/initialisation in Ruby? Are these things supported by some gems, which provide different solutions for various cases of lazy initialisation of objects? Thanks for your suggestions!

    Read the article

  • Lucene's nested query evaluation regarding negation

    - by ponzao
    Hi, I am adding Apache Lucene support to Querydsl (which offers type-safe queries for Java) and I am having problems understanding how Lucene evaluates queries especially regarding negation in nested queries. For instance the following two queries in my opinion are semantically the same, but only the first one returns results. +year:1990 -title:"Jurassic Park" +year:1990 +(-title:"Jurassic Park") The simplified object tree in the second example is shown below. query : Query clauses : ArrayList [0] : BooleanClause "MUST" occur : BooleanClause.Occur "year:1990" query : TermQuery [1] : BooleanClause "MUST" occur : BooleanClause.Occur query : BooleanQuery clauses : ArrayList [0] : BooleanClause "MUST_NOT" occur : BooleanClause.Occur "title:"Jurassic Park"" query : TermQuery Lucene's own QueryParser seems to evaluate "AND (NOT" into the same kind of object trees. Is this a bug in Lucene or have I misunderstood Lucene's query evaluation? I am happy to give more information if necessary.

    Read the article

  • Static Evaluation Function for Checkers

    - by Kamikaze
    Hi all! I'm trying to write an evaluation function for a game of checkers that I'm developing but I can't find the right documentation. I've read several documents on the web witch describe different techniques for either writing one or letting the computer find it(using genetic algorithms or Bayesian learning) but they're too complicated for a novice like me. All documents pointed a reference to "Some studies in machine learning using the game of checkers" by A.L.Samuel but I couldn't get my hands on it yet :(. I've only read the follow up "Some studies in machine learning using the game of checkers -II" and found some good info there, but it doesn't explain what the eval parameters mean (I think I don't have the whole article). Thanks for your help!

    Read the article

  • Evaluation of jQuery function variable value during definition of that function

    - by thesnail
    I have a large number of rows in a table within which I wish to attach a unique colorpicker (jQuery plugin) to each cell in a particular column identified by unique ids. Given this, I want to automate the generation of instances of the colorpicker as follows: var myrows={"a","b","c",.....} var mycolours={"ffffff","fcdfcd","123123"...} for (var i=0;i<myrows.length;i++) { $("#"+myrows[i]+"colour").ColorPicker({flat: false, color: mycolours[i], onChange: function (hsb, hex, rgb) { $("#"+myrows[i]+"currentcolour").css('backgroundColor', '#' + hex); } }); Now this doesn't work because the evaluation of the $("#"+myrows[i]+"currentcolour") component occurs at the time the function is called, not when it is defined (which is want I need). Given that this plugin javascript appends its code to the level and not to the underlying DOM component that I am accessing above so can't derive what id this pertains to, how can I evaluate the variable during function declaration/definition? Thanks for any help/insight anyone can give. Brian.

    Read the article

  • evaluation strategy examples

    - by Boontz
    Assuming the language supports these evaluation strategies, what would be the result for call by reference, call by name, and call by value? void swap(int a; int b) { int temp; temp = a; a = b; b = temp; } int i = 3; int A[5]; A[3] = 4; swap (i, A[3]);

    Read the article

  • Postfix evaluation in C

    - by Andrewziac
    I’m taking a course in C and we have to make a program for the classic Postfix evaluation problem. Now, I’ve already completed this problem in java, so I know that we have to use a stack to push the numbers into, then pop them when we get an operator, I think I’m fine with all of that stuff. The problem I have been having is scanning the postfix expression in C. In java it was easier because you could use charAt and you could use the parseInt command. However, I’m not aware of any similar commands in C. So could anyone explain a method to read each value from a string in the form: 4 9 * 0 - = Where the equals is the signal of the end of the input. Any help would be greatly appreciated and thank you in advance :)

    Read the article

  • What is "Call By Name"?

    - by forellana
    Hi to everyone! I'm working in a homework, and the professor asked me to implement the evaluation strategy called "call by name" in scheme in a certain language that we developed and he gave us an example at http://www.scala-lang.org/node/138 in the scala language, but i don't understand in what consists the call by name evaluation strategy? what differences it has with call by need? thanks, greetings

    Read the article

  • What's the (hidden) cost of lazy val? (Scala)

    - by Jesper
    One handy feature of Scala is lazy val, where the evaluation of a val is delayed until it's necessary (at first access). Ofcourse a lazy val must have some overhead - somewhere Scala must keep track of whether the value has already been evaluated and the evaluation must be synchronized, because multiple threads might try to access the value for the first time at the same time. What exactly is the cost of a lazy val - is there a hidden boolean flag associated with a lazy val to keep track if it has been evaluated or not, what exactly is synchronized and are there any more costs? And a follow-up question: Suppose I do this: class Something { lazy val (x, y) = { ... } } Is this the same as having two separate lazy vals x and y or do I get the overhead only once, for the pair (x, y)?

    Read the article

  • Is this code well-defined?

    - by Nawaz
    This code is taken from a discussion going on here. someInstance.Fun(++k).Gun(10).Sun(k).Tun(); Is this code well-defined? Is ++k Fun() evaluated before k in Sun()? What if k is user-defined type, not built-in type? And in what ways the above function calls order is different from this: eat(++k);drink(10);sleep(k); As far as I can say, in both situations, there exists a sequence point after each function call. If so, then why can't the first case is also well-defined like the second one? Section 1.9.17 of the C++ ISO standard says this about sequence points and function evaluation: When calling a function (whether or not the function is inline), there is a sequence point after the evaluation of all function arguments (if any) which takes place before execution of any expressions or statements in the function body. There is also a sequence point after the copying of a returned value and before the execution of any expressions outside the function.

    Read the article

  • Have You Downloaded SQL Server 2012 Evaluation Edition? Why Not?!

    - by andyleonard
    I am installing SQL Server 2012 Evaluation Edition on a virtual machine as I type. You can do this. Here’s one way: Grab some virtual machine software. I like Oracle VirtualBox . It’s cool. It’s free. Install VirtualBox. Download the 180-day free trial of Windows Server 2008 R2 . Also cool. Also free. Once Windows Server 2008 R2 is downloaded, build a VirtualBox VM. Download and install SQL Server 2012 Evaluation Edition ! That’s all there is to it. You can get started today, no need to wait until...(read more)

    Read the article

  • codility challenge, test case OK , Evaluation report Wrong Answer

    - by Hussein Fawzy
    the aluminium 2014 gives me wrong answer [3 , 9 , -6 , 7 ,-3 , 9 , -6 , -10] got 25 expected 28 but when i repeated the challenge with the same code and make case test it gives me the correct answer Your test case [3, 9, -6, 7, -3, 9, -6, -10] : NO RUNTIME ERRORS (returned value: 28) what is the wrong with it ??? the challenge :- A non-empty zero-indexed array A consisting of N integers is given. A pair of integers (P, Q), such that 0 = P = Q < N, is called a slice of array A. The sum of a slice (P, Q) is the total of A[P] + A[P+1] + ... + A[Q]. The maximum sum is the maximum sum of any slice of A. For example, consider array A such that: A[0] = 3 A[1] = 2 A[2] = -6 A[3] = 3 A[4] = 1 For example (0, 1) is a slice of A that has sum A[0] + A[1] = 5. This is the maximum sum of A. You can perform a single swap operation in array A. This operation takes two indices I and J, such that 0 = I = J < N, and exchanges the values of A[I] and A[J]. To goal is to find the maximum sum you can achieve after performing a single swap. For example, after swapping elements 2 and 4, you will get the following array A: A[0] = 3 A[1] = 2 A[2] = 1 A[3] = 3 A[4] = -6 After that, (0, 3) is a slice of A that has the sum A[0] + A[1] + A[2] + A[3] = 9. This is the maximum sum of A after a single swap. Write a function: class Solution { public int solution(int[] A); } that, given a non-empty zero-indexed array A of N integers, returns the maximum sum of any slice of A after a single swap operation. For example, given: A[0] = 3 A[1] = 2 A[2] = -6 A[3] = 3 A[4] = 1 the function should return 9, as explained above. and my code is :- import java.math.*; class Solution { public int solution(int[] A) { if(A.length == 1) return A[0]; else if (A.length==2) return A[0]+A[1]; else{ int finalMaxSum = A[0]; for (int l=0 ; l<A.length ; l++){ for (int k = l+1 ; k<A.length ; k++ ){ int [] newA = A; int temp = newA[l]; newA [l] = newA[k]; newA[k]=temp; int maxSum = newA[0]; int current_max = newA[0]; for(int i = 1; i < newA.length; i++) { current_max = Math.max(A[i], current_max + newA[i]); maxSum = Math.max(maxSum, current_max); } finalMaxSum = Math.max(finalMaxSum , maxSum); } } return finalMaxSum; } } } i don't know what's the wrong with it ??

    Read the article

  • JSP Custom Taglib: Nested Evaluation

    - by Tiago Fernandez
    Say I have my custom taglib: <%@ taglib uri="http://foo.bar/mytaglib" prefix="mytaglib"%> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%> <mytaglib:doSomething> Test </mytaglib:doSomething> Inside the taglib class I need to process a template and tell the JSP to re-evaluate its output, so for example if I have this: public class MyTaglib extends SimpleTagSupport { @Override public void doTag() throws JspException, IOException { getJspContext().getOut().println("<c:out value=\"My enclosed tag\"/>"); getJspBody().invoke(null); } } The output I have is: <c:out value="My enclosed tag"/> Test When I actually need to output this: My enclosed tag Test Is this feasible? How? Thanks.

    Read the article

  • Mouse movement / mouseover and JavaScript evaluation in watir

    - by Bilal Aslam
    I have a JavaScript-heavy Rails app which I am testing in watir. I have two specific testing requirements: I need to be able to simulate moving the mouse to a specific area of the screen (or at least triggering the onmouseover event for a div) Evaluating a snippet of JavaScript once the above has happened to see if a flag is set correctly I haven't been able to figure out how to do this in watir. Any ideas on how to do this?

    Read the article

  • Boolean Expression Evaluation in Java

    - by Trilok
    Hey everyone, Is there a relatively simpler (when compared with writing a parser) way to evaluate boolean expressions in Java? I do not want to use the JEP library. I have a String expression something like: (x 4 || x < 8 && p 6) [ I will replace the variables with values. Is there a way by which I can evaluate this expression? The problem is, this can be any level deep. So, writing a parser would be really complex. Thanks

    Read the article

  • Dynamic if statement evaluation problem with string comparison

    - by Mani
    I tried the example given in this thread to create if statement dynamically using BeanShell. But it is not working fine. Instead of using "age" variable as integer, i have used string in the below example. I am getting "fail" as answer instead of "success". Can anyone help me? /* To change this template, choose Tools | Templates and open the template in the editor. */ import java.lang.reflect.*; import bsh.Interpreter; public class Main { public static String d; public static void main(String args[]) { try { String age = "30"; String cond = "age==30"; Interpreter i = new Interpreter(); i.set("age", age); System.out.println(" sss" + i.get("age")); if((Boolean)i.eval(cond)) { System.out.println("success"); } else { System.out.println("fail"); } } catch (Throwable e) { System.err.println(e); } } } Thanks, Mani

    Read the article

  • Evaluation of environment variables in command run by Java's Runtime.exec()

    - by Tom Duckering
    Hi, I have a scenarios where I have a Java "agent" that runs on a couple of platforms (specifically Windows, Solaris & AIX). I'd like to factor out the differences in filesystem structure by using environment variables in the command line I execute. As far as I can tell there is no way to get the Runtime.exec() method to resolve/evaluate any environment variables referenced in the command String (or array of Strings). I know that if push comes to shove I can write some code to pre-process the command String(s) and resolve enviroment variables by hand (using getEnv() etc). However I'm wondering if there is a smarter way to do this since I'm sure I'm not the only person wanting to do this and I'm sure there are pitfalls in "knocking up" my own implementation. Your guidance and suggestions are most welcome. edit: I would like to refer to environment variables in the command string using some consistent notation such as $VAR and/or %VAR%. Not fussed which. edit: To be clear I'd like to be able to execute a command such as: perl $SCRIPT_ROOT/somePerlScript.pl args on Windows and Unix hosts using Runtime.exec(). I specify the command in config file that describes a list of jobs to run and it has to be able to work cross platform, hence my thought that an environment variable would be useful to factor out the filesystem differences (/home/username/scripts vs C:\foo\scripts). Hope that helps clarify it. Thanks. Tom

    Read the article

  • evaluation of a java thread dump

    - by raticulin
    I got a thread dump of one of my processes. It has a bunch of these threads. I guess they are keeping a bunch of memory so I am getting OOM. "Thread-8264" prio=6 tid=0x4c94ac00 nid=0xf3c runnable [0x4fe7f000] java.lang.Thread.State: RUNNABLE at java.util.zip.Inflater.inflateBytes(Native Method) at java.util.zip.Inflater.inflate(Inflater.java:223) - locked <0x0c9bc640 (a java.util.zip.Inflater) at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:235) at com.my.ZipExtractorCommonsCompress.extract(ZipExtractorCommonsCompress.java:48) at com.my.CustomThreadedExtractorWrapper$ExtractionThread.run(CustomThreadedExtractorWrapper.java:151) Locked ownable synchronizers: - None "Thread-8241" prio=6 tid=0x4c94a400 nid=0xb8c runnable [0x4faef000] java.lang.Thread.State: RUNNABLE at java.util.zip.Inflater.inflateBytes(Native Method) at java.util.zip.Inflater.inflate(Inflater.java:223) - locked <0x0c36b808 (a java.util.zip.Inflater) at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.read(ZipArchiveInputStream.java:235) at com.my.ZipExtractorCommonsCompress.extract(ZipExtractorCommonsCompress.java:48) at com.my.CustomThreadedExtractorWrapper$ExtractionThread.run(CustomThreadedExtractorWrapper.java:151) Locked ownable synchronizers: - None I am trying to find out how it arrived to this situation. CustomThreadedExtractorWrapper is a wrapper class that fires a thread to do some work (ExtractionThread, which uses ZipExtractorCommonsCompress to extract zip contents from a compressed stream). If the task is taking too long, ExtractionThread.interrupt(); is called to cancel the operation. I can see in my logs that the cancellation happened 25 times. And I see 21 of these threads in my dump. My questions: What is the status of these threads? Alive and running? Blocked somehow? They did not die with .interrupt() apparently? Is there a sure way to really kill a thread? What does really mean 'locked ' in the stack trace? Line 223 in Inflater.java is: public synchronized int inflate(byte[] b, int off, int len) { ... //return is line 223 return inflateBytes(b, off, len); }

    Read the article

  • Formula parsing / evaluation routine or library with generic DLookup functionality

    - by tbone
    I am writing a .Net application where I must support user-defined formulas that can perform basic mathematics, as well as accessing data from any arbitrary table in the database. I have the math part working, using JScript Eval(). What I haven't decided on is what a nice way is to do the generic table lookups. For example, I may have a formula something like: Column: BonusAmount Formula: {CurrentSalary} * 1.5 * {[SystemSettings][Value][SettingName=CorpBonus AND Year={Year}]} So, in this example I would replace {xxx} and {Year} with the value of Column xxx from the current table, and I would replace the second part with the value of (select Value from SystemSettings WHERE SettingName='CorpBonus' AND Year=2008) So, basically, I am looking for something very much like the MS Access DLookup function: DLookup ( expression, domain, [criteria] ) DLookup("[UnitPrice]", "Order Details", "OrderID = 10248") But, I also need to overall parsing routine that can tell whether to just look up in the current row, or to look into another table. Would also be nice to support aggregate functions (ie: DAvg, DMax, etc), as well as all the weird edge cases handled. So I wonder if anyone knows of any sort of an existing library, or has a nice routine that can handle this formula parsing and database lookup / aggregate function resolution requirements.

    Read the article

  • Evaluation of CTEs in SQL Server 2005

    - by Jammer
    I have a question about how MS SQL evaluates functions inside CTEs. A couple of searches didn't turn up any results related to this issue, but I apologize if this is common knowledge and I'm just behind the curve. It wouldn't be the first time :-) This query is a simplified (and obviously less dynamic) version of what I'm actually doing, but it does exhibit the problem I'm experiencing. It looks like this: CREATE TABLE #EmployeePool(EmployeeID int, EmployeeRank int); INSERT INTO #EmployeePool(EmployeeID, EmployeeRank) SELECT 42, 1 UNION ALL SELECT 43, 2; DECLARE @NumEmployees int; SELECT @NumEmployees = COUNT(*) FROM #EmployeePool; WITH RandomizedCustomers AS ( SELECT CAST(c.Criteria AS int) AS CustomerID, dbo.fnUtil_Random(@NumEmployees) AS RandomRank FROM dbo.fnUtil_ParseCriteria(@CustomerIDs, 'int') c) SELECT rc.CustomerID, ep.EmployeeID FROM RandomizedCustomers rc JOIN #EmployeePool ep ON ep.EmployeeRank = rc.RandomRank; DROP TABLE #EmployeePool; The following can be assumed about all executions of the above: The result of dbo.fnUtil_Random() is always an int value greater than zero and less than or equal to the argument passed in. Since it's being called above with @NumEmployees which has the value 2, this function always evaluates to 1 or 2. The result of dbo.fnUtil_ParseCriteria(@CustomerIDs, 'int') produces a one-column, one-row table that contains a sql_variant with a base type of 'int' that has the value 219935. Given the above assumptions, it makes sense (to me, anyway) that the result of the expression above should always produce a two-column table containing one record - CustomerID and an EmployeeID. The CustomerID should always be the int value 219935, and the EmployeeID should be either 42 or 43. However, this is not always the case. Sometimes I get the expected single record. Other times I get two records (one for each EmployeeID), and still others I get no records. However, if I replace the RandomizedCustomers CTE with a true temp table, the problem vanishes completely. Every time I think I have an explanation for this behavior, it turns out to not make sense or be impossible, so I literally cannot explain why this would happen. Since the problem does not happen when I replace the CTE with a temp table, I can only assume it has something to do with the functions inside CTEs are evaluated during joins to that CTE. Do any of you have any theories?

    Read the article

  • Design suggestion for expression tree evaluation with time-series data

    - by Lirik
    I have a (C#) genetic program that uses financial time-series data and it's currently working but I want to re-design the architecture to be more robust. My main goals are: sequentially present the time-series data to the expression trees. allow expression trees to access previous data rows when needed. to optimize performance of the data access while evaluating the expression trees. keep a common interface so various types of data can be used. Here are the possible approaches I've thought about: I can evaluate the expression tree by passing in a data row into the root node and let each child node use the same data row. I can evaluate the expression tree by passing in the data row index and letting each node get the data row from a shared DataSet (currently I'm passing the row index and going to multiple synchronized arrays to get the data). Hybrid: an immutable data set is accessible by all of the expression trees and each expression tree is evaluated by passing in a data row. The benefit of the first approach is that the data row is being passed into the expression tree and there is no further query done on the data set (which should increase performance in a multithreaded environment). The drawback is that the expression tree does not have access to the rest of the data (in case some of the functions need to do calculations using previous data rows). The benefit of the second approach is that the expression trees can access any data up to the latest data row, but unless I specify what that row is, I'll have to iterate through the rows and figure out which one is the last one. The benefit of the hybrid is that it should generally perform better and still provide access to the earlier data. It supports two basic "views" of data: the latest row and the previous rows. Do you guys know of any design patterns or do you have any tips that can help me build this type of system? Should I use a DataSet to hold and present the data, or are there more efficient ways to present rows of data while maintaining a simple interface? FYI: All of my code is written in C#.

    Read the article

  • Django - Better evaluation of relationship at the model level

    - by Brant
    Here's a simple relational pair of models. class Shelf(models.Model): name = models.CharField(max_length=100) def has_books(self): if Book.objects.filter(shelf=self): return True else: return False class Book(models.Model): shelf = models.ForeignKey(Shelf) name = models.CharField(max_length=100) Is there a better (or alternative) way to write the "has_book" method? I'm not a fan of the double database hit but I want to do this at the model level.

    Read the article

  • Dymanic if statement evaluation problem with string comparison

    - by Mani
    I tried the example given in http://forums.sun.com/thread.jspa?threadID=780576&tstart=67605 to create if statement dynamically. But it is not working fine. Instead of using "age" variable as integer, i have used string in the below example. I am getting "fail" as answer instead of "success". Can anyone help me? / To change this template, choose Tools | Templates and open the template in the editor. / import java.lang.reflect.*; import bsh.Interpreter; public class Main { public static String d; public static void main(String args[]) { try { String age = "30"; String cond = "age==30"; Interpreter i = new Interpreter(); i.set("age", age); System.out.println(" sss" + i.get("age")); if((Boolean)i.eval(cond)) { System.out.println("success"); } else { System.out.println("fail"); } } catch (Throwable e) { System.err.println(e); } } } Thanks, Mani

    Read the article

  • javascript variable evaluation in function

    - by lamerzpua
    I trying to use simile widget for own need but I'm stuck on such problem. I have loop for (i=0;i<15;i++){ Timeline.loadXML(function_that_return_url(), function(xml, url) { eventSource[i].loadXML(xml, url); }); } This code is for Timeline.loadXML: Timeline.loadXML = function(url, f) { var fError = function(statusText, status, xmlhttp) { alert("Failed to load data xml from " + url + "\n" + statusText); }; var fDone = function(xmlhttp) { var xml = xmlhttp.responseXML; if (!xml.documentElement && xmlhttp.responseStream) { xml.load(xmlhttp.responseStream); } f(xml, url); }; SimileAjax.XmlHttp.get(url, fError, fDone);}; When I open the page - my function function(xml, url) { eventSource[i].loadXML(xml, url); }); is passed to loadXML method which use it inside as f(xml, url); Problem is that i variable is not parsed as number and I receive message that eventSource[...] is not declared. How I can evaluate i values before it will be posted as argument for the method LoadXML ?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >