Friday, March 28, 2008
Book 9: The Devil in a Forest (Wolfe)
Medieval Wolfe. What is his obsession with boxes of sand? Short Sun books have it too! Seriously, good book. I wouldn't have gotten the twist had he not discussed it at the end. Keep track of everyone's weapons!
Book 8: Slave Nation (Blumrosen)
American revolutionaries endorse slavery to ensure success of their revolution.
Wednesday, March 19, 2008
Book 7: The Golden Ocean (O'Brian)
Nautical story in mid-18th century. All the great things from the Aubrey/Maturin series, condensed. Very very good.
Thursday, March 13, 2008
Thursday, January 31, 2008
Book 4: Blood Meridian (McCarthy)
Good. Relentlessly violent western. Unsuccessful stabs at philosophy. Imprisoned: leave your people and you may die.
Book 2: The Ladies of Grace Adiue (Clarke)
Very good. Fairy stories in the vein of Jonathan Strange and Mr. Norrell, with mostly happy endings. And a pig.
Monday, January 07, 2008
2008 Reading List
I plan to keep track of the books I read in 2008 (like I did in 2006). My goal is, again, to read fifty books this year.
Scheme: Through the List Once
The simplest way to compute the average of the numbers in a list is:
- compute the sum of the numbers in the list
- compute the length of the list
- divide the sum by the length, giving the average
sum and len defined as (define (sum l) (foldl 0 + l))
(define (len l) (foldl 0 (lambda (x y) (+ 1 y)) l))then we can compute the average as: (define (two-pass-average l)
(cond
((null? l) 0)
(else (/ (sum l) (len l)))
)
)This solution is correct, but it walks the list twice (once to compute the sum and once to compute the length). If we add a couple of accumulators and a facade function, we can compute the average with one list pass, like this:(define (one-pass-average len-acc sum-acc l)
(cond
((and (null? l) (= 0 len-acc)) 0)
((null? l) (/ sum-acc len-acc))
(else (one-pass-average (+ 1 len-acc) (+ (car l) sum-acc) (cdr l)))
)
)
(define (average l) (one-pass-average 0 0 l))The drawback to the one-pass method is that we've lost the nice definition of sum and len in terms of foldl. I wonder if we can restore it?
Thursday, August 30, 2007
Key Changes
The band with the offensive name goes through a lot of key changes. This is just an extreme version of what rock does already. Where does the E-flat in F7 come from when you're playing in C? It sounds to me like they're going into the dominant more (playing the flat-five to imply a major second).
Wednesday, February 21, 2007
Two SQLServer SQL Tips
1) My transaction log file was gigantic (38GB). I fixed it by doing this:
deleting my log file and then doing this:
2) When I'm writing a script that creates tables, I often want to drop the table if it already exists. Instead of writing out the
Now that I think about it, I wonder whether T-SQL has the equivalent of Oracle's 'CREATE OR REPLACE'. That's basically what I've re-implemented here.
sp_detach_db MyDB,deleting my log file and then doing this:
exec sp_attach_db 'MyDB', '[pathToMDF]\MyDB.mdf'2) When I'm writing a script that creates tables, I often want to drop the table if it already exists. Instead of writing out the
if exists (select ...) drop table over and over again, I created a little stored procedure to do it:
CREATE PROCEDURE drop_table @tableName varchar(255) AS
if exists (select name from sysobjects where name=@tableName and type='U')
EXEC('DROP TABLE '+@tableName)
GO
Now I can drop a table like this: exec drop_table 'MyOldTable'. I created a similar procedure for dropping stored procedures. Now that I think about it, I wonder whether T-SQL has the equivalent of Oracle's 'CREATE OR REPLACE'. That's basically what I've re-implemented here.
Friday, January 26, 2007
FizzBuzz Exposes a Scheme Design Pattern?
I wrote a simple FizzBuzz in Scheme:
Then, inspired by Reg's "overthought" Ruby version, I did a Scheme version of his implementation:
The design pattern I'm talking about concerns multi-arg Scheme functions like
I've had to do this a few times writing Scheme functions, so maybe it's a design pattern! Mark Dominus has pointed out that patterns are a sign of weaknesses in programming languages. So, is this a real weakness in Scheme? Is there another way to recurse with a multi-argument function?
(define (number-interval f t)
(if (<= f t) (cons f (number-interval (+ f 1) t)) '()))
(define (fb n)
(cond
((eq? (remainder n 15) 0) 'FizzBuzz)
((eq? (remainder n 5) 0) 'Buzz)
((eq? (remainder n 3) 0) 'Fizz)
(else n)
)
)
(define (FizzBuzz m n) (map fb (number-interval m n)))
Then, inspired by Reg's "overthought" Ruby version, I did a Scheme version of his implementation:
(define (carbonate n name)
(lambda (x)
(if (and (number? x) (eq? (remainder x n) 0))
name
x
)
)
)
(define (compose . fns)
(define (compose-list functions)
(if (null? functions)
(lambda (x) x) ; identity function
(lambda (x)
(define (g y) ((compose-list (cdr functions)) y))
(g ((car functions) x))
)
)
)
(compose-list fns)
)
(define (FizzBuzz2 m n)
(map (compose (carbonate 15 'FizzBuzz) (carbonate 5 'Buzz) (carbonate 3 'Fizz)) (number-interval m n))
)
The design pattern I'm talking about concerns multi-arg Scheme functions like
compose, above. The composition of a list of functions is the composition of the first with the composition of the rest. But I can't see how Scheme's multi-argument-function syntax is amenable to the natural recursion. So I have to write the compose-list helper function.I've had to do this a few times writing Scheme functions, so maybe it's a design pattern! Mark Dominus has pointed out that patterns are a sign of weaknesses in programming languages. So, is this a real weakness in Scheme? Is there another way to recurse with a multi-argument function?
Tuesday, November 28, 2006
Book 50: Tatja Grimm's World (Vinge)
Disappointing Vinge. But it was his first novel, so maybe that's why. Some exciting scenes, but none of the "wow" factor of "A Fire Upon the Deep" or "A Deepness in the Sky". And his attempts to avoid "as you know, Bob" setups are kind of clumsy (but I guess at least he tried). And neologistic abbreviations are so annoying ("art'ry" for "artillery" -- yeesh!). Stephenson does this too, with "phant'sy". Stop banging me on the head with etymology, you smug jerk!
So that's fifty books! And before December!
So that's fifty books! And before December!
Book 49: H.M.S. Surprise (O'Brian)
Another great Aubrey/Maturin. Very exciting battles and espionage. And Dil was an affecting character, despite her short stay in the story.
Book 48: Darwinia (Wilson)
Reasonably OK. Wilson's books seem to get better in the order he wrote them. Unfortunately, I'm reading them in reverse order! The one standout for me in this book was his establishing Lovecraftian monsters in a hard SF environment.
Tuesday, November 14, 2006
Book 47: Post Captain (O'Brian)
Second Aubrey/Maturin. Crammed with plot and excitement. Maturin's wool suit and bees were hilarious.
Book 46: Going Postal (Pratchett)
Very good. Usual Discworld wackiness, but with a motivating good-versus-evil plot and some character development more believable than Moist von Lipwick's name.
Monday, October 30, 2006
Book 45: Chronoliths (Wilson)
Very good. Similar to "Spin" in that it describes what happens to realistic characters after a science-fictiony incident in the near future. Not quite as good as Spin.
Subscribe to:
Posts (Atom)