Search Results

Search found 828 results on 34 pages for 'recursion'.

Page 16/34 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • Compilation Error on Recursive Variadic Template Function

    - by Maxpm
    I've prepared a simple variadic template test in Code::Blocks, but I'm getting an error: No matching function for call to 'OutputSizes()' Here's my source code: #include <iostream> #include <typeinfo> using namespace std; template <typename FirstDatatype, typename... DatatypeList> void OutputSizes() { std::cout << typeid(FirstDatatype).name() << ": " << sizeof(FirstDatatype) << std::endl; OutputSizes<DatatypeList...>(); } int main() { OutputSizes<char, int, long int>(); return 0; } I'm using GNU GCC with -std=C++0x. Using std=gnu++0x makes no difference.

    Read the article

  • If a jQuery function calls itself in its completion callback, is that a recursive danger to the stac

    - by NXT
    Hi, I'm writing a little jQuery component that animates in response to button presses and also should go automatically as well. I was just wondering if this function recursive or not, I can't quite work it out. function animate_next_internal() { $('#sc_thumbnails').animate( { top: '-=106' }, 500, function() { animate_next_internal(); } ); } My actual function is more complicated to allow for stops and starts, this is just a simplified example.

    Read the article

  • Using Mergesort to calculate number of inversions in C++

    - by Brown
    void MergeSort(int A[], int n, int B[], int C[]) { if(n > 1) { Copy(A,0,floor(n/2),B,0,floor(n/2)); Copy(A,floor(n/2),n-1,C,0,floor(n/2)-1); MergeSort(B,floor(n/2),B,C); MergeSort(C,floor(n/2),B,C); Merge(A,B,0,floor(n/2),C,0,floor(n/2)-1); } }; void Copy(int A[], int startIndexA, int endIndexA, int B[], int startIndexB, int endIndexB) { while(startIndexA < endIndexA && startIndexB < endIndexB) { B[startIndexB]=A[startIndexA]; startIndexA++; startIndexB++; } }; void Merge(int A[], int B[],int leftp, int rightp, int C[], int leftq, int rightq) //Here each sub array (B and C) have both left and right indices variables (B is an array with p elements and C is an element with q elements) { int i=0; int j=0; int k=0; while(i < rightp && j < rightq) { if(B[i] <=C[j]) { A[k]=B[i]; i++; } else { A[k]=C[j]; j++; inversions+=(rightp-leftp); //when placing an element from the right array, the number of inversions is the number of elements still in the left sub array. } k++; } if(i=rightp) Copy(A,k,rightp+rightq,C,j,rightq); else Copy(A,k,rightp+rightq,B,i,rightp); } I am specifically confused on the effect of the second 'B' and 'C' arguments in the MergeSort calls. I need them in there so I have access to them for Copy and and Merge, but

    Read the article

  • What is the easiest way to get the property value from a passed lambda expression in an extension me

    - by Andrew Siemer
    I am writing a dirty little extension method for HtmlHelper so that I can say something like HtmlHelper.WysiwygFor(lambda) and display the CKEditor. I have this working currently but it seems a bit more cumbersome than I would prefer. I am hoping that there is a more straight forward way of doing this. Here is what I have so far. public static MvcHtmlString WysiwygFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) { return MvcHtmlString.Create(string.Concat("<textarea class=\"ckeditor\" cols=\"80\" id=\"", expression.MemberName(), "\" name=\"editor1\" rows=\"10\">", GetValue(helper, expression), "</textarea>")); } private static string GetValue<TModel, TProperty>(HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) { MemberExpression body = (MemberExpression)expression.Body; string propertyName = body.Member.Name; TModel model = helper.ViewData.Model; string value = typeof(TModel).GetProperty(propertyName).GetValue(model, null).ToString(); return value; } private static string MemberName<T, V>(this Expression<Func<T, V>> expression) { var memberExpression = expression.Body as MemberExpression; if (memberExpression == null) throw new InvalidOperationException("Expression must be a member expression"); return memberExpression.Member.Name; } Thanks!

    Read the article

  • how do I call a javacript function every 60 seconds?

    - by William
    So I'm trying to work on a Canvas demo, and I want this square to move from one side to the other, but I can't figure out how to call javascript in a way that repeats every 60 seconds. Here's what I got so far: <!DOCTYPE html> <html lang="en"> <head> <title>Canvas test</title> <meta charset="utf-8" /> <link href="/bms/style.css" rel="stylesheet" /> <style> body { text-align: center; background-color: #000000;} canvas{ background-color: #ffffff;} </style> <script type="text/javascript"> var x = 50; var y = 250; function update(){ draw(); x = x + 5; } function draw(){ var canvas = document.getElementById('screen1'); if (canvas.getContext){ var ctx = canvas.getContext('2d'); ctx.fillStyle = 'rgb(236,138,68)'; ctx.fillRect(x,y,24,24); } } </script> </head> <body onLoad="setTimeout(update(), 0);"> <canvas id="screen1" width="500" height="500"></canvas> </body> </html>

    Read the article

  • Recursive QuickSort suffering a StackOverflowException -- Need fresh eyes

    - by jon
    I am working on a Recursive QuickSort method implementation in a GenericList Class. I will have a second method that accepts a compareDelegate to compare different types, but for development purposes I'm sorting a GenericList<int I am recieving stackoverflow areas in different places depending on the list size. I've been staring at and tracing through this code for hours and probably just need a fresh pair of (more experienced)eyes. Definitely wanting to learn why it is broken, not just how to fix it. public void QuickSort() { int i, j, lowPos, highPos, pivot; GenericList<T> leftList = new GenericList<T>(); GenericList<T> rightList = new GenericList<T>(); GenericList<T> tempList = new GenericList<T>(); lowPos = 1; highPos = this.Count; if (lowPos < highPos) { pivot = (lowPos + highPos) / 2; for (i = 1; i <= highPos; i++) { if (this[i].CompareTo(this[pivot]) <= 0) leftList.Add(this[i]); else rightList.Add(this[i]); } leftList.QuickSort(); rightList.QuickSort(); for(i=1;i<=leftList.Count;i++) tempList.Add(leftList[i]); for(i=1;i<=rightList.Count;i++) tempList.Add(rightList[i]); this.items = tempList.items; this.count = tempList.count; } }

    Read the article

  • passing self data into a recursive function

    - by user272689
    I'm trying to set a function to do something like this def __binaryTreeInsert(self, toInsert, currentNode=getRoot(), parentNode=None): where current node starts as root, and then we change it to a different node in the method and recursivly call it again. However, i cannot get the 'currentNode=getRoot()' to work. If i try calling the funcion getRoot() (as above) it says im not giving it all the required variables, but if i try to call self.getRoot() it complains that self is an undefined variable. Is there a way i can do this without having to specify the root while calling this method?

    Read the article

  • Check if there are any repeated elements in an array recursively

    - by devoured elysium
    I have to find recursively if there is any repeated element in an integer array v. The method must have the following signature: boolean hasRepeatedElements(int[] v) I can't see any way of doing that recursively without having to define another method or at least another overload to this method (one that takes for example the element to go after or something). At first I thought about checking for the current v if there is some element equal to the first element, then creating a new array with L-1 elements etc but that seems rather inefficient. Is it the only way? Am I missing here something?

    Read the article

  • Will this ever result in a stack overflow error?

    - by David
    Will incrementing the instance variables of an object ever lead to a stack overflow error? For example: This method (java) will cause a stack overflow error: class StackOverflow { public static void StackOverflow (int x) { System.out.println (x) ; StackOverflow(x+1) ; } public static void main (String[]arg) { StackOverflow (0) ; } but will this?: (..... is a gap that i've put in to shorten the code. its long enough as it is.) import java.util.*; class Dice { String name ; int x ; int[] sum ; .... public Dice (String name) { this.name = name ; this.x = 0 ; this.sum = new int[7] ; } .... public static void main (String[] arg) { Dice a1 = new Dice ("a1") ; for (int i = 0; i<6000000; i++) { a1.roll () ; printDice(a1) ; } } .... public void roll () { this.x = randNum(1, this.sum.length) ; this.sum[x] ++ ; } public static int randNum (int a, int b) { Random random = new Random() ; int c = (b-a) ; int randomNumber = ((random.nextInt(c)) + a) ; return randomNumber ; } public static void printDice (Dice Dice) { System.out.println (Dice.name) ; System.out.println ("value: "+Dice.x) ; printValues (Dice) ; } public static void printValues (Dice Dice) { for (int i = 0; i<Dice.sum.length; i++) System.out.println ("#of "+i+"'s: "+Dice.sum[i]) ; } } The above doesn't currently cause a stack overflow error but could i get it too if i changed this line in main: for (int i = 0; i<6000000; i++) so that instead of 6 million something sufficiently high were there?

    Read the article

  • Can you make a PHP function recursive without repeating it's name?

    - by alex
    It's always bugged me a recursive function needs to name itself, when a instantiated class can use $this and a static method can use self etc. Is there a similar way to do this in a recursive function without naming it again (just to cut down on maintenance)? Obviously I could use call_user_func or the __FUNCTION__ constant but I would prefer something less ugly. Update Thanks for your answers. I might stick to including the function name for simple functions, and make take the other approaches for anything more complicated.

    Read the article

  • Segmentation fault in C recursive Combination (nCr)

    - by AruniRC
    PLease help me out here. The program is supposed to recursively find out the combination of two numbers. nCr = n!/ (r!(n-r)! ). I'm getting this error message when i compile it on GCC. Here's what the terminal shows: Enter two numbers: 8 4 Segmentation fault (Program exited with code:139) The code is given here: #include<stdio.h> float nCr(float, float, float); int main() { float a, b, c; printf("Enter two numbers: \n"); scanf("%f%f", &a, &b); c = nCr(a, b, a-b); printf("\n%.3f", c); return 0; } float nCr(float n, float r, float p) { if(n<1) return (1/(p*r))*(nCr(1, r-1, p-1)); if(r<1) return (n/(p*1))*(nCr(n-1, 1, p-1)); if(p<1) return (n/r)*(nCr(n-1, r-1, 1)); return ( n/(p*r) )*nCr(n-1, r-1, p-1); }

    Read the article

  • What exactly is a reentrant function?

    - by eSKay
    Most of the times, the definition of reentrance is quoted from Wikipedia: A computer program or routine is described as reentrant if it can be safely called again before its previous invocation has been completed (i.e it can be safely executed concurrently). To be reentrant, a computer program or routine: Must hold no static (or global) non-constant data. Must not return the address to static (or global) non-constant data. Must work only on the data provided to it by the caller. Must not rely on locks to singleton resources. Must not modify its own code (unless executing in its own unique thread storage) Must not call non-reentrant computer programs or routines. How is safely defined? If a program can be safely executed concurrently, does it always mean that it is reentrant? What exactly is the common thread between the six points mentioned that I should keep in mind while checking my code for reentrant capabilities? Also, Are all recursive functions reentrant? Are all thread-safe functions reentrant? Are all recursive and thread-safe functions reentrant? While writing this question, one thing comes to mind: Are the terms like reentrance and thread safety absolute at all i.e. do they have fixed concrete definations? For, if they are not, this question is not very meaningful. Thanks!

    Read the article

  • Where should I initialize variables for an OO Recursive Descent Parse Tree?

    - by Vasto
    I'd like to preface this by stating that this is for a class, so please don't solve this for me. One of my labs for my cse class is creating an interpreter for a BNF that was provided. I understand most of the concepts, but I'm trying to build up my tree and I'm unsure where to initialize values. I've tried in both the constructor, and in the methods but Eclipse's debugger still only shows the left branch, even though it runs through completely. Here is my main procedure so you can get an idea of how I'm calling the methods. public class Parser { public static void main(String[] args) throws IOException { FileTokenizer instance = FileTokenizer.Instance(); FileTokenizer.main(args); Prog prog = new Prog(); prog.ParseProg(); prog.PrintProg(); prog.ExecProg(); } Now here is My Prog class: public class Prog { private DeclSeq ds; private StmtSeq ss; Prog() { ds = new DeclSeq(); ss = new StmtSeq(); } public void ParseProg() { FileTokenizer instance = FileTokenizer.Instance(); instance.skipToken(); //Skips program (1) // ds = new DeclSeq(); ds.ParseDS(); instance.skipToken(); //Skips begin (2) // ss = new StmtSeq(); ss.ParseSS(); instance.skipToken(); } I've tried having Prog() { ds = null; ss = null; } public void ParseProg() { FileTokenizer instance = FileTokenizer.Instance(); instance.skipToken(); //Skips program (1) ds = new DeclSeq(); ds.ParseDS(); ... But it gave me the same error. I need the parse tree built up so I can do a pretty print and an execute command, but like I said, I only get the left branch. Any help would be appreciated. Explanations why are even more so appreciated. Thank you, Vasto

    Read the article

  • (Ordered) Set Partitions in fixed-size Blocks

    - by Eugen
    Here is a function I would like to write but am unable to do so. Even if you don't / can't give a solution I would be grateful for tips. For example, I know that there is a correlation between the ordered represantions of the sum of an integer and ordered set partitions but that alone does not help me in finding the solution. So here is the description of the function I need: The Task Create an efficient* function List<int[]> createOrderedPartitions(int n_1, int n_2,..., int n_k) that returns a list of arrays of all set partions of the set {0,...,n_1+n_2+...+n_k-1} in number of arguments blocks of size (in this order) n_1,n_2,...,n_k (e.g. n_1=2, n_2=1, n_3=1 -> ({0,1},{3},{2}),...). Here is a usage example: int[] partition = createOrderedPartitions(2,1,1).get(0); partition[0]; // -> 0 partition[1]; // -> 1 partition[2]; // -> 3 partition[3]; // -> 2 Note that the number of elements in the list is (n_1+n_2+...+n_n choose n_1) * (n_2+n_3+...+n_n choose n_2) * ... * (n_k choose n_k). Also, createOrderedPartitions(1,1,1) would create the permutations of {0,1,2} and thus there would be 3! = 6 elements in the list. * by efficient I mean that you should not initially create a bigger list like all partitions and then filter out results. You should do it directly. Extra Requirements If an argument is 0 treat it as if it was not there, e.g. createOrderedPartitions(2,0,1,1) should yield the same result as createOrderedPartitions(2,1,1). But at least one argument must not be 0. Of course all arguments must be = 0. Remarks The provided pseudo code is quasi Java but the language of the solution doesn't matter. In fact, as long as the solution is fairly general and can be reproduced in other languages it is ideal. Actually, even better would be a return type of List<Tuple<Set>> (e.g. when creating such a function in Python). However, then the arguments wich have a value of 0 must not be ignored. createOrderedPartitions(2,0,2) would then create [({0,1},{},{2,3}),({0,2},{},{1,3}),({0,3},{},{1,2}),({1,2},{},{0,3}),...] Background I need this function to make my mastermind-variation bot more efficient and most of all the code more "beautiful". Take a look at the filterCandidates function in my source code. There are unnecessary / duplicate queries because I'm simply using permutations instead of specifically ordered partitions. Also, I'm just interested in how to write this function. My ideas for (ugly) "solutions" Create the powerset of {0,...,n_1+...+n_k}, filter out the subsets of size n_1, n_2 etc. and create the cartesian product of the n subsets. However this won't actually work because there would be duplicates, e.g. ({1,2},{1})... First choose n_1 of x = {0,...,n_1+n_2+...+n_n-1} and put them in the first set. Then choose n_2 of x without the n_1 chosen elements beforehand and so on. You then get for example ({0,2},{},{1,3},{4}). Of course, every possible combination must be created so ({0,4},{},{1,3},{2}), too, and so on. Seems rather hard to implement but might be possible. Research I guess this goes in the direction I want however I don't see how I can utilize it for my specific scenario. http://rosettacode.org/wiki/Combinations

    Read the article

  • Recursive COUNT Query (SQL Server)

    - by Cosmo
    Hello Guys! I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories. Category Id : bigint (PK) Name : nvarchar(255) AcceptQuestions : bit IdParent : bigint (FK) Question Id : bigint (PK) Title : nvarchar(255) ... IdCategory : bigint (FK) How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(

    Read the article

  • Recursive COUNT Query (MS SQL)

    - by Cosmo
    Hello Guys! I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories. Category Id : bigint (PK) Name : nvarchar(255) AcceptQuestions : bit IdParent : bigint (FK) Question Id : bigint (PK) Title : nvarchar(255) ... IdCategory : bigint (FK) How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(

    Read the article

  • arbitrary vire connection / search and replace

    - by fatai
    input :["vire_connection",[1, 2, [ 3, [ 4, "connect"]]], ["connect", [3 , 5] ] ] output:["vire_connection",[ 1, 2, [ 3, [ 4, [ 3, 5 ] ] ] ] ], [ [ 3 , 5] ] ] after connection ( simply copying [3,5] to other wanted position ) , remove connect word input :["vire_connection", [ [ [ ["connect", [ 3, 4 ] ] ] ] ], [ 2, "connect"]] output :["vire_connection",[[[[[3,4]]]]], [ 2, [ 3 , 4 ]]] after connection ( simply copying [3,4] to other wanted position ) , remove connect word how can I do ?

    Read the article

  • How do I output the preorder traversal of a tree given the inorder and postorder tranversal?

    - by user342580
    Given the code for outputing the postorder traversal of a tree when I have the preorder and the inorder traversal in an interger array. How do I similarily get the preorder with the inorder and postorder array given? void postorder( int preorder[], int prestart, int inorder[], int inostart, int length) { if(length==0) return; //terminating condition int i; for(i=inostart; i<inostart+length; i++) if(preorder[prestart]==inorder[i])//break when found root in inorder array break; postorder(preorder, prestart+1, inorder, inostart, i-inostart); postorder(preorder, prestart+i-inostart+1, inorder, i+1, length-i+inostart-1); cout<<preorder[prestart]<<" "; } Here is the prototype for preorder() void preorder( int inorderorder[], int inostart, int postorder[], int poststart, int length)

    Read the article

  • How do I remove the leaves of a binary tree?

    - by flopex
    I'm trying to remove all of the leaves. I know that leaves have no children, this is what I have so far. public void removeLeaves(BinaryTree n){ if (n.left == null && n.right == null){ n = null; } if (n.left != null) removeLeaves(n.left); if (n.right != null) removeLeaves(n.right); }

    Read the article

  • Using recustion an append in prolog

    - by Adrian
    Lets say that I would like to construct a list (L2) by appending elements of another list (L) one by one. The result should be exactly the same as the input. This task is silly, but it'll help me understand how to recurse through a list and remove certain elements. I have put together the following code: create(L, L2) :- (\+ (L == []) -> L=[H|T], append([H], create(T, L2), L2);[]). calling it by create([1,2,3,4], L2) returns L2 = [1|create([2,3,4], **)\. which is not a desired result.

    Read the article

  • Make function non-recursive

    - by user69514
    I'm not sure how to make this function non-recursive. Any ideas?: void foo(int a, int b){ while( a < len && arr[a][b] != -1){ if(++a == len){ a = 0; b++; } } if( a == len){ size++; return; } if( a < (len-1)){ arr[a][b] = 1; arr[a][(b+1)] = 1; foo(a, b); arr[a][b] = -1; arr[a][(b+1)] = -1; } if( a < (len-1) && arr[(a+1)][b] == -1){ arr[a][b] = 0; arr[(a+1)][b] = 0; foo(a,b); arr[a][b] = -1; arr[(a+1)][b] = -1; } }

    Read the article

  • Scala: Recursively building all pathes in a graph?

    - by DarqMoth
    Trying to build all existing paths for an udirected graph defined as a map of edges using the following algorithm: Start: with a given vertice A Find an edge (X.A, X.B) or (X.B, X.A), add this edge to path Find all edges Ys fpr which either (Y.C, Y.B) or (Y.B, Y.C) is true For each Ys: A=B, goto Start Providing edges are defined as the following map, where keys are tuples consisting of two vertices: val edges = Map( ("n1", "n2") -> "n1n2", ("n1", "n3") -> "n1n3", ("n3", "n4") -> "n3n4", ("n5", "n1") -> "n5n1", ("n5", "n4") -> "n5n4") As an output I need to get a list of ALL pathes where each path is a list of adjecent edges like this: val allPaths = List( List(("n1", "n2") -> "n1n2"), List(("n1", "n3") -> "n1n3", ("n3", "n4") -> "n3n4"), List(("n5", "n1") -> "n5n1"), List(("n5", "n4") -> "n5n4"), List(("n2", "n1") -> "n1n2", ("n1", "n3") -> "n1n3", ("n3", "n4") -> "n3n4", ("n5", "n4") -> "n5n4")) //... //... more pathes to go } Note: Edge XY = (x,y) - "xy" and YX = (y,x) - "yx" exist as one instance only, either as XY or YX So far I have managed to implement code that duplicates edges in the path, which is wrong and I can not find the error: object Graph2 { type Vertice = String type Edge = ((String, String), String) type Path = List[((String, String), String)] val edges = Map( //(("v1", "v2") , "v1v2"), (("v1", "v3") , "v1v3"), (("v3", "v4") , "v3v4") //(("v5", "v1") , "v5v1"), //(("v5", "v4") , "v5v4") ) def main(args: Array[String]): Unit = { val processedVerticies: Map[Vertice, Vertice] = Map() val processedEdges: Map[(Vertice, Vertice), (Vertice, Vertice)] = Map() val path: Path = List() println(buildPath(path, "v1", processedVerticies, processedEdges)) } /** * Builds path from connected by edges vertices starting from given vertice * Input: map of edges * Output: list of connected edges like: List(("n1", "n2") -> "n1n2"), List(("n1", "n3") -> "n1n3", ("n3", "n4") -> "n3n4"), List(("n5", "n1") -> "n5n1"), List(("n5", "n4") -> "n5n4"), List(("n2", "n1") -> "n1n2", ("n1", "n3") -> "n1n3", ("n3", "n4") -> "n3n4", ("n5", "n4") -> "n5n4")) */ def buildPath(path: Path, vertice: Vertice, processedVerticies: Map[Vertice, Vertice], processedEdges: Map[(Vertice, Vertice), (Vertice, Vertice)]): List[Path] = { println("V: " + vertice + " VM: " + processedVerticies + " EM: " + processedEdges) if (!processedVerticies.contains(vertice)) { val edges = children(vertice) println("Edges: " + edges) val x = edges.map(edge => { if (!processedEdges.contains(edge._1)) { addToPath(vertice, processedVerticies.++(Map(vertice -> vertice)), processedEdges, path, edge) } else { println("ALready have edge: "+edge+" Return path:"+path) path } }) val y = x.toList y } else { List(path) } } def addToPath( vertice: Vertice, processedVerticies: Map[Vertice, Vertice], processedEdges: Map[(Vertice, Vertice), (Vertice, Vertice)], path: Path, edge: Edge): Path = { val newPath: Path = path ::: List(edge) val key = edge._1 val nextVertice = neighbor(vertice, key) val x = buildPath (newPath, nextVertice, processedVerticies, processedEdges ++ (Map((vertice, nextVertice) -> (vertice, nextVertice))) ).flatten // need define buidPath type x } def children(vertice: Vertice) = { edges.filter(p => (p._1)._1 == vertice || (p._1)._2 == vertice) } def containsPair(x: (Vertice, Vertice), m: Map[(Vertice, Vertice), (Vertice, Vertice)]): Boolean = { m.contains((x._1, x._2)) || m.contains((x._2, x._1)) } def neighbor(vertice: String, key: (String, String)): String = key match { case (`vertice`, x) => x case (x, `vertice`) => x } } Running this results in: List(List(((v1,v3),v1v3), ((v1,v3),v1v3), ((v3,v4),v3v4))) Why is that?

    Read the article

  • Best Functional Approach

    - by dbyrne
    I have some mutable scala code that I am trying to rewrite in a more functional style. It is a fairly intricate piece of code, so I am trying to refactor it in pieces. My first thought was this: def iterate(count:Int,d:MyComplexType) = { //Generate next value n //Process n causing some side effects return iterate(count - 1, n) } This didn't seem functional at all to me, since I still have side effects mixed throughout my code. My second thought was this: def generateStream(d:MyComplexType):Stream[MyComplexType] = { //Generate next value n return Stream.cons(n, generateStream(n)) } for (n <- generateStream(initialValue).take(2000000)) { //process n causing some side effects } This seemed like a better solution to me, because at least I've isolated my functional value-generation code from the mutable value-processing code. However, this is much less memory efficient because I am generating a large list that I don't really need to store. This leaves me with 3 choices: Write a tail-recursive function, bite the bullet and refactor the value-processing code Use a lazy list. This is not a memory sensitive app (although it is performance sensitive) Come up with a new approach. I guess what I really want is a lazily evaluated sequence where I can discard the values after I've processed them. Any suggestions?

    Read the article

  • Adding some delay in an recursive loop and breaking out of it on mouseover

    - by Moak
    I have created a loop function loopThem(){ $$('#main-nav a').each(function(i, n) { i.up("#main-nav").down("li.active").removeClassName("active"); i.up("li").addClassName("active"); var target = i.readAttribute("href"); i.up(".home-top").down("li.visible").removeClassName("visible"); i.up(".home-top").down(target).addClassName("visible"); }); loopThem(); } This function is called when the dom is loaded document.observe("dom:loaded", function() { loopThem(); }); It does what I want as far as rotating through a set of banners, however it does so at light speed How Can I A add a delay between the changing? B stop the loop from continuing once I mouse over?

    Read the article

  • How can I recursively read out directories in Perl?

    - by Przemek
    Hi, I want to read out a directory recursively to print the data-structure in an HTML-Page with Template::Toolkit. But I'm hanging in how to save the Paths and Files in a form that can be read our easy. My idea started like this sub list_dirs{ my ($rootPath) = @_; my (@paths); $rootPath .= '/' if($rootPath !~ /\/$/); for my $eachFile (glob($path.'*')) { if(-d $eachFile) { push (@paths, $eachFile); $paths[$i] = &list_dirs($eachFile); } else { push (@files, $eachFile); } } return @paths; } How could I solve this problem?

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >