Search Results

Search found 761 results on 31 pages for 'tail'.

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

  • Is this implementation truely tail-recursive?

    - by CFP
    Hello everyone! I've come up with the following code to compute in a tail-recursive way the result of an expression such as 3 4 * 1 + cos 8 * (aka 8*cos(1+(3*4))) The code is in OCaml. I'm using a list refto emulate a stack. type token = Num of float | Fun of (float->float) | Op of (float->float->float);; let pop l = let top = (List.hd !l) in l := List.tl (!l); top;; let push x l = l := (x::!l);; let empty l = (l = []);; let pile = ref [];; let eval data = let stack = ref data in let rec _eval cont = match (pop stack) with | Num(n) -> cont n; | Fun(f) -> _eval (fun x -> cont (f x)); | Op(op) -> _eval (fun x -> cont (op x (_eval (fun y->y)))); in _eval (fun x->x) ;; eval [Fun(fun x -> x**2.); Op(fun x y -> x+.y); Num(1.); Num(3.)];; I've used continuations to ensure tail-recursion, but since my stack implements some sort of a tree, and therefore provides quite a bad interface to what should be handled as a disjoint union type, the call to my function to evaluate the left branch with an identity continuation somehow irks a little. Yet it's working perfectly, but I have the feeling than in calling the _eval (fun y->y) bit, there must be something wrong happening, since it doesn't seem that this call can replace the previous one in the stack structure... Am I misunderstanding something here? I mean, I understand that with only the first call to _eval there wouldn't be any problem optimizing the calls, but here it seems to me that evaluation the _eval (fun y->y) will require to be stacked up, and therefore will fill the stack, possibly leading to an overflow... Thanks!

    Read the article

  • How to implement tail calls in a custom VM

    - by DeadMG
    How can I implement tail calls in a custom virtual machine? I know that I need to pop off the original function's local stack, then it's arguments, then push on the new arguments. But, if I pop off the function's local stack, how am I supposed to push on the new arguments? They've just been popped off the stack.

    Read the article

  • Implement "tail -f" in C++

    - by Hamming
    Hi! I want to create a small code in C++ with the same functionality as "tail-f": watch for new lines in a text file and show them in the standard output. The idea is to have a thread that monitors the file Is there an easy way to do it without opening and closing the file each time?

    Read the article

  • Tail-recursive pow() algorithm with memoization?

    - by Dan
    I'm looking for an algorithm to compute pow() that's tail-recursive and uses memoization to speed up repeated calculations. Performance isn't an issue; this is mostly an intellectual exercise - I spent a train ride coming up with all the different pow() implementations I could, but was unable to come up with one that I was happy with that had these two properties. My best shot was the following: def calc_tailrec_mem(base, exp, cache_line={}, acc=1, ctr=0): if exp == 0: return 1 elif exp == 1: return acc * base elif exp in cache_line: val = acc * cache_line[exp] cache_line[exp + ctr] = val return val else: cache_line[ctr] = acc return calc_tailrec_mem(base, exp-1, cache_line, acc * base, ctr + 1) It works, but it doesn't memorize the results of all calculations - only those with exponents 1..exp/2 and exp.

    Read the article

  • What is a Long Tail Keyword?

    Did you know that a long tail keyword will out convert a root keyword 9 times out of 10. In this article, I will discuss the reasons why the long tail is a better keyword to chase than the more common methods of chasing the root.

    Read the article

  • The Long Tail Keyword Phrase Phenomenon

    There's been much conversation and debate over whether to use short tail or long tail keyword phrases when working optimizing your articles and websites. I think a bit of both may be in order. Well let's first distinguish the difference and then we can talk about how we can apply them to our articles and/or website meta tags.

    Read the article

  • Winning With Long Tail Keywords - Become an Authority in Your Niche

    Most accomplished webmasters and SEO experts will mirror my words here. Winning in the long tail is essential to becoming an authority in your niche. Too often do webmasters go for the "frontal assault" when trying to win a niche, which more often than not results in their competition finding out about them, then pushing them out of the game with their strong list of long tail rankings. So, what can you do in order to dominate your niche and become an authority?

    Read the article

  • SQL SERVER – Backing Up and Recovering the Tail End of a Transaction Log – Notes from the Field #042

    - by Pinal Dave
    [Notes from Pinal]: The biggest challenge which people face is not taking backup, but the biggest challenge is to restore a backup successfully. I have seen so many different examples where users have failed to restore their database because they made some mistake while they take backup and were not aware of the same. Tail Log backup was such an issue in earlier version of SQL Server but in the latest version of SQL Server, Microsoft team has fixed the confusion with additional information on the backup and restore screen itself. Now they have additional information, there are a few more people confused as they have no clue about this. Previously they did not find this as a issue and now they are finding tail log as a new learning. Linchpin People are database coaches and wellness experts for a data driven world. In this 42nd episode of the Notes from the Fields series database expert Tim Radney (partner at Linchpin People) explains in a very simple words, Backing Up and Recovering the Tail End of a Transaction Log. Many times when restoring a database over an existing database SQL Server will warn you about needing to make a tail end of the log backup. This might be your reminder that you have to choose to overwrite the database or could be your reminder that you are about to write over and lose any transactions since the last transaction log backup. You might be asking yourself “What is the tail end of the transaction log”. The tail end of the transaction log is simply any committed transactions that have occurred since the last transaction log backup. This is a very crucial part of a recovery strategy if you are lucky enough to be able to capture this part of the log. Most organizations have chosen to accept some amount of data loss. You might be shaking your head at this statement however if your organization is taking transaction logs backup every 15 minutes, then your potential risk of data loss is up to 15 minutes. Depending on the extent of the issue causing you to have to perform a restore, you may or may not have access to the transaction log (LDF) to be able to back up those vital transactions. For example, if the storage array or disk that holds your transaction log file becomes corrupt or damaged then you wouldn’t be able to recover the tail end of the log. If you do have access to the physical log file then you can still back up the tail end of the log. In 2013 I presented a session at the PASS Summit called “The Ultimate Tail Log Backup and Restore” and have been invited back this year to present it again. During this session I demonstrate how you can back up the tail end of the log even after the data file becomes corrupt. In my demonstration I set my database offline and then delete the data file (MDF). The database can’t become more corrupt than that. I attempt to bring the database back online to change the state to RECOVERY PENDING and then backup the tail end of the log. I can do this by specifying WITH NO_TRUNCATE. Using NO_TRUNCATE is equivalent to specifying both COPY_ONLY and CONTINUE_AFTER_ERROR. It as its name says, does not try to truncate the log. This is a great demo however how could I achieve backing up the tail end of the log if the failure destroys my entire instance of SQL and all I had was the LDF file? During my demonstration I also demonstrate that I can attach the log file to a database on another instance and then back up the tail end of the log. If I am performing proper backups then my most recent full, differential and log files should be on a server other than the one that crashed. I am able to achieve this task by creating new database with the same name as the failed database. I then set the database offline, delete my data file and overwrite the log with my good log file. I attempt to bring the database back online and then backup the log with NO_TRUNCATE just like in the first example. I encourage each of you to view my blog post and watch the video demonstration on how to perform these tasks. I really hope that none of you ever have to perform this in production, however it is a really good idea to know how to do this just in case. It really isn’t a matter of “IF” you will have to perform a restore of a production system but more of a “WHEN”. Being able to recover the tail end of the log in these sever cases could be the difference of having to notify all your business customers of data loss or not. If you want me to take a look at your server and its settings, or if your server is facing any issue we can Fix Your SQL Server. Note: Tim has also written an excellent book on SQL Backup and Recovery, a must have for everyone. Reference: Pinal Dave (http://blog.sqlauthority.com)Filed under: Notes from the Field, PostADay, SQL, SQL Authority, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, T SQL

    Read the article

  • Understanding Long Tail Keywords For SEO

    Long tail keywords are typically two or more words (a phrase) that you type into a search engine like Google when you are searching for a product, service, the answer to a question or any kind of research you might find necessary. And if you're not at the top of the search engines (preferably in one of the first 3 positions), your chances of making money online decrease substantially.

    Read the article

  • Understanding Long Tail Keywords For SEO

    Long tail keywords are typically two or more words (a phrase) that you type into a search engine like Google when you are searching for a product, service, the answer to a question or any kind of research you might find necessary. And if you're not at the top of the search engines (preferably in one of the first 3 positions), your chances of making money online decrease substantially.

    Read the article

  • Tail and wildcard characters

    - by Mitch
    I want to get the last 10 lines of multiple files. I know they all end with "-access_log". So I tried: tail -10 *-access_log But this gives me an error, where as: tail -10 file-* Gives me the output I'd expect. I would think this probably has more to do with BASH then tail. However commands like: cat *-access_log Work fine. Any suggestions?

    Read the article

  • tail-like view on HTML logfiles

    - by h0b0
    I'm working on an application that creates HTML log files. I'm tired of having to manually reload and scroll to the bottom in the browser to see the latest entries. A solution that does not really satisfy me is using the Firefox plugins ReloadEvery and ScrollyFox. In many situations reloading frequency and scrolling speed are just to slow. Of course I could actually use tail, but I would prefer a rendered HTML page. Do you have any suggestions? Firefox extensions are preferred, but any other tip is appreciated, too.

    Read the article

  • How can I implement a tail-recursive list append?

    - by martingw
    A simple append function like this (in F#): let rec app s t = match s with | [] -> t | (x::ss) -> x :: (app ss t) will crash when s becomes big, since the function is not tail recursive. I noticed that F#'s standard append function does not crash with big lists, so it must be implemented differently. So I wondered: How does a tail recursive definition of append look like? I came up with something like this: let rec comb s t = match s with | [] -> t | (x::ss) -> comb ss (x::t) let app2 s t = comb (List.rev s) t which works, but looks rather odd. Is there a more elegant definition?

    Read the article

  • Scheme. Tail recursive ?

    - by n00b
    Hi guys, any tail-recursive version for the below mentioned pseudocode ? Thanks ! (define (min list) (cond ((null? list '()) ((null? (cdr list)) (car list)) (#t (let ((a (car list)) (b (min (cdr list))) ) (if (< b a) b a) ) ) ) )

    Read the article

  • When there's no TCO, when to worry about blowing the stack?

    - by Cedric Martin
    Every single time there's a discussion about a new programming language targetting the JVM, there are inevitably people saying things like: "The JVM doesn't support tail-call optimization, so I predict lots of exploding stacks" There are thousands of variations on that theme. Now I know that some language, like Clojure for example, have a special recur construct that you can use. What I don't understand is: how serious is the lack of tail-call optimization? When should I worry about it? My main source of confusion probably comes from the fact that Java is one of the most succesful languages ever and quite a few of the JVM languages seems to be doing fairly well. How is that possible if the lack of TCO is really of any concern?

    Read the article

  • tail call generated by clang 1.1 and 1.0 (llvm 2.7 and 2.6)

    - by ony
    After compilation next snippet of code with clang -O2 (or with online demo): #include <stdio.h> #include <stdlib.h> int flop(int x); int flip(int x) { if (x == 0) return 1; return (x+1)*flop(x-1); } int flop(int x) { if (x == 0) return 1; return (x+0)*flip(x-1); } int main(int argc, char **argv) { printf("%d\n", flip(atoi(argv[1]))); } I'm getting next snippet of llvm assembly in flip: bb1.i: ; preds = %bb1 %4 = add nsw i32 %x, -2 ; <i32> [#uses=1] %5 = tail call i32 @flip(i32 %4) nounwind ; <i32> [#uses=1] %6 = mul nsw i32 %5, %2 ; <i32> [#uses=1] br label %flop.exit I thought that tail call means dropping current stack (i.e. return will be to the upper frame, so next instruction should be ret %5), but according to this code it will do mul for it. And in native assembly there is simple call without tail optimisation (even with appropriate flag for llc) Can sombody explain why clang generates such code? As well I can't understand why llvm have tail call if it can simply check that next ret will use result of prev call and later do appropriate optimisation or generate native equivalent of tail-call instruction?

    Read the article

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