Wednesday, May 26, 2010

Grails 1.3.1 dependency resolution

After upgrading Grails to 1.3.1 from 1.2.2, I repeatedly received "UNRESOLVED DEPENDENCIES" errors. After an inordinate amount of troubleshooting, I stumbled upon the sole archived message on the Internet that recommended deleting (or renaming) the %USER_HOME%\.ivy2 directory. Sure enough, this worked like a charm, so I post the resolution here for posterity. It seems there were some transitive dependencies that weren't getting sorted out. It's all good now.

Sunday, May 16, 2010

The Light Bulb Is Not Yet On

I have reset on going through Essentials of Programming Languages, and struggling my way through learning Scheme. I wrote a working answer (at least as tested) for a problem in the second chapter, but I feel like I happened upon it through test-driven development. I suppose in some ways that's a good thing, but I can say that it is not a terribly comfortable feeling to write some code but not really grok what it's doing. Anyway, here is the paraphrased problem, and my solution (test cases included):

Exercise 2.2.9, #3. (car&cdr2 s slst errvalue) generates a procedure composition that, when evaluated, produces the code for a procedure that takes a list with the same structure as slst and returns the value in the same position as the leftmost occurrence of s in slst. If s does not occur in slst, then errvalue is returned.

(define (contains? s los)
(if (null? los)
#f
(if (symbol? (car los))
(if (eq? s (car los))
#t
(contains? s (cdr los)))
(if (contains? s (car los))
#t
(contains? s (cdr los))))))

(define (car&cdr2 s slst errvalue)
(if (contains? s slst)
(car&cdr2-help s slst 'car)
errvalue))

(define (car&cdr2-help s slst lst)
(if (symbol? (car slst))
(if (eq? s (car slst))
lst
(list 'compose lst (car&cdr2-help s (cdr slst) 'cdr)))
(if (contains? s (car slst))
(list 'compose 'car (car&cdr2-help s (car slst) 'cdr))
(list 'compose lst (car&cdr2-help s (cdr slst) 'cdr)))))


Here are the tests (schemeunit):
(define-test-suite 2.2.9
(test-case "3."
(check equal?
(car&cdr2 'a '() 'fail)
'fail)
(check equal?
(car&cdr2 'a '(a) 'fail)
'car)
(check equal?
(car&cdr2 'a '(b) 'fail)
'fail)
(check equal?
(car&cdr2 'a '(a b) 'fail)
'car)
(check equal?
(car&cdr2 'b '(a b) 'fail)
'(compose car cdr))
(check equal?
(car&cdr2 'c '(a b c) 'fail)
'(compose car (compose cdr cdr)))
(check equal?
(car&cdr2 'd '(a (b c) d) 'fail)
'(compose car (compose cdr cdr)))
(check equal?
(car&cdr2 'dog '(cat lion (fish dog) pig) 'fail)
'(compose car (compose cdr (compose car (compose cdr cdr)))))
(check equal?
(car&cdr2 'c '((a b) c) 'fail)
'(compose car cdr))))

Any Schemers care to give me pointers? I sure could use the help.