Default Programs Editor 2.7

The next version of Default Programs Editor has been posted, along with a total site redesign. All the important stuff is now on the root page, and I’ve severely dialed back on cruft to put most of your experience on a single page. And, one more note: this announcement is actually for the second release of version 2.7. There were a couple bugs I noticed in the crash report logs that really needed to be fixed before I announced the release, so, if you happened to grab DPE in between the redesign and this post, check and see if you’ve got the older version. They’re each got a proper version number, but “2.7” refers to the later release.

Download now at http://defaultprogramseditor.com
Have an idea or feature request? Put it on the feedback forum: http://defaultprogramseditor.uservoice.com

Want to support Default Programs Editor? Help spread the word! Suggest Default Programs Editor to be included in Ninite (link). Donations are accepted too, and thank you so much to the many people who’ve contributed.

There’s some cool new stuff in 2.7, most notably context menu icon editing‘Open With’ support, and built in registry backups. The latter two items were requested on the feedback forum and quite popular, so if you have a feature request, be sure go there and request it. There’s also a myriad of great little usability tweaks like better keyboard accessibility (also a requested feature on UserVoice).

Changelog:

Version 2.7.2675.2253 (October 29, 2010)
Bugs Fixed:
– Fixed a minor DPI related layout bug.

Crashes Fixed:
– Fixed a crash after clicking the DDE ‘Edit’ button when adding a new context menu item.
– Viewing ‘Open With’ programs caused a crash when the item listed in the registry didn’t exist on disk.
– Fixed a crash when starting the application for some users.

Version 2.7.2660.1843 (October 23, 2010)
New Features:
+ Added support for editing ‘Open With’ programs.
+ Added support for editing context menu item icons.
+ Added support for registry backups of file type information.
+ Added “%1” by default when browsing for an application, and added an option to toggle it.
+ “Show in folder” button added to success page when saving to a .reg file.
+ Increased performance when loading long lists.
+ Better support for deleting verb precedence trees.
+ Increased keyboard accessibility.

Bugs Fixed:
– Fixed miscellaneous layout bugs.
– Fixed being stuck on the the options page after an elevated restart.
– Fixed issue causing scope labels to be listed twice for context menu items.

Crashes Fixed:
– Setting certain applications as context menu default could cause a crash.
– Selecting multiple extensions caused a crash when switching to the context menu page in certain scenarios.

Project Euler in F#: Problem 2

Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
Find the sum of all the even-valued terms in the sequence which do not exceed four million.

The Thinking

The problem is similar to Problem 1, but this time instead of a natural number sequence, we’re to use a fibbonacci sequence, evens only, less than 4 million. Then, we’ll need to sum them up; that we did in Problem 1 with Seq.sum. How can we generate the sequence? I’ll be taking a simple two-step approach. First, figure out a function to generate a fibbonacci sequence (up through 4,000,000), then take all the evens. We can Seq.sum that resulting sequence to find our answer.

Generating a Fibonacci Sequence

Generating a fibbonacci sequence in F# is a textboook case, and so much so that it’s actually an example snippet for the built-in F# function we’re going to use to generate it: Seq.unfold. Seq.unfold is a  function that returns a sequence, based on a function we provide. It takes two parameters: a sequence element generator function, and the inital value to start with.
[sourcecode]Seq.unfold generator state[/sourcecode]
The generator function must be defined with a single input parameter (the “state value”), and returning an “option tuple of the next element in the sequence and the next state value” (from documentation).

A fibbonacci algorithm requires two inputs (the previous two digits), but we can only pass one parameter. Luckily in F# we have Tuples. A tuple lets us package up several values into a single group, and is written with as a comma separated list inside parenthesis:
[sourcecode]let sometuple = (“this”, “is”, “a”, “single”, “tuple”)[/sourcecode]
The return value is also something new, using the built-in Option module. We’ll be returning an Option, either Some or None. None is a signal to unfold that this is the end of sequence, and for all the rest of the return results, we need to return Some-thing (the next element of the sequence as well as the next state value in tuple form) as we learned above, from the documentation for unfold.

This might seem like a lot to process all at once, but it ends up looking pretty simple when it’s all put together. The generator function for fibbonacci numbers less than 4m looks like this:
[sourcecode]let fibgen (x,y) = //define a function ‘fibgen’ and pass in a single parameter, a tuple that represents the most recent two digits of the fibbonacci sequence so far
if(x < 4000000) then // define a cut-off threshold to keep the sequence from going on forever Some(x+y, (y, x+y)) // return an Option tuple; the next elemnet of the sequence: x+y (the two most recent elements added together), and the next state value- a single tuple that will be used next time the funciton is run else None // we're up to 4m, so tell unfold we're done with the sequence [/sourcecode]And now, we can plug that into Seq.unfold: [sourcecode]let fibseq = Seq.unfold fibgen (1,1) // (1,1) is a single tuple parameter with the initial values for the fibgen function[/sourcecode]If we run this in the Interactive F# window in Visual Studio, we can confirm this produces the full fibbonacci sequence: [sourcecode]val it : seq = seq [2; 3; 5; 8; ...][/sourcecode]

Getting Just The Evens

If you recall our solution to Problem 1, it should be easy to figure out how to make a new sequence with only the even values by using seq, modulo, and yield that we’ve already learned.
[sourcecode]let fibevens = seq{for i in fibseq do if i % 2 = 0 then yield i}[/sourcecode]

My Solution

Putting it all together, with Seq.sum to add up the sequence:
[sourcecode]let fibgen (x,y) = if(x < 4000000) then Some(x+y, (y, x+y)) else None let fibseq = Seq.unfold fibgen (1,1) let fibevens = seq{for i in fibseq do if i % 2 = 0 then yield i} let result = Seq.sum fibevens printfn "%A" result [/sourcecode]Project Euler Problem 2: Answered

Further Reading

A Post Script

Each part of the above solution is named for clarity. We could easily compose these functions for a more compact solution:
[sourcecode]printfn “%A” (Seq.sum(seq{for i in ((1,1) |> Seq.unfold(fun (x,y) -> if(x < 4000000) then Some(x+y, (y, x+y)) else None)) do if i % 2 = 0 then yield i}))[/sourcecode] The only thing that gets weird in this compact version is the anonymous replacement for fibgen, which uses lambda syntax fun & ->, and the pipeline operator, |> to pass in the intial state. There are some goofy rules for when you can and cannot use piplineing; check out the Pipeline section of Chapter 8 of The F# Survival Guide for a good primer.

Call for ideas for DPE 2.7

After taking a bit of a break from the project, I’m reopening development of Default Programs Editor, with a couple of great ideas in mind. The feedback since I launched 2.0 almost a year ago has been outstanding, and has guided six minor releases in the mean time. For version 2.7 development I’m openly soliciting ideas to make the next version even better.

How you can help

Download Default Programs Editor, and poke around. Mess with stuff. Make little tweaks to your system, then reverse them. What feels right? What gets annoying? What could be better? Let me know!