This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;; unify.clj | |
(ns building-problem-solvers) | |
(defn unify ... ) | |
;;;;;;; unify_test.clj | |
(load-file "unify.clj") | |
(ns building-problem-solvers | |
(:use clojure.test)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def initialize | |
@x = 3 | |
end | |
def fiddle &block | |
instance_eval &block | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance_eval { 3 } | |
x = lambda { 3 } | |
instance_eval &x # wrong number of arguments, 1 for 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fact("x"); query("x"); #=> ["x"] | |
fact("x"); query("y"); #=> [] | |
fact("is_cool(fred)"); query("is_cool(fred)"); #=> ["is_cool(fred)"] | |
fact("is_cool(parent_of(fred),on(saturdays))"); query("is_cool(parent_of(fred),on(saturdays))"); #=> ["is_cool(parent_of(fred),on(saturdays))"] | |
fact("x"); query(":y"); #=> [{":y"=>"x"}] | |
fact("is_cool(fred)"); query("is_cool(:y)"); #=> [{":y"=>"fred"}] | |
fact("is_cool(parent_of(fred),on(saturdays))"); query("is_cool(parent_of(fred),:time)"); #=> [{":time"=>"on(saturdays)"}] | |
fact("is_cool(fred,saturdays)"); query("is_cool(fred)"); #=> [] | |
fact("is_cool(fred,saturdays)"); query("is_cool(fred,:time)"); #=> [{":time"=>"saturdays"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application | |
def fact s | |
end | |
end | |
module RFact | |
def fact fact_as_string | |
Application.new.fact fact_as_string | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application | |
def fact s | |
end | |
end | |
module RFact | |
def fact fact_as_string | |
Application.new.fact fact_as_string | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def not | |
3 | |
end | |
end | |
Foo.new.instance_eval { not } #=> syntax error, unexpected '}' | |
Foo.new.instance_eval { not() } #=> true | |
Foo.new.send :not #=> 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I found http://groups.google.com/group/growing-object-oriented-software/browse_thread/thread/47695af2c6b5adda fascinating, so I decided to make it a little more concrete. It's also in ruby using rspec, sorry about that. Here's the code under test: | |
class EligibleForDiscountPolicy | |
def initialize transaction, user | |
@transaction = transaction | |
@user = user | |
end | |
def decide | |
return true if @user.is_gold_member? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProceduralFiveDigits | |
def initialize | |
@new_population = Array.new(100) { generate_individual } | |
reset | |
end | |
def evolve | |
1000.times do | |
100.times do | |
@parent_a, @parent_b = [pick_individual, pick_individual] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Users/andrewwagner> which ruby | |
ruby not found | |
/Users/andrewwagner> rvm list | |
rvm rubies | |
ruby-1.9.2-p290 [ i386 ] | |
/Users/andrewwagner> rvm use 1.9.2 | |
Using /Users/andrewwagner/.rvm/gems/ruby-1.9.2-p290 |