Post := IoRecord {Actually, this looks almost readable, right? It's all valid Io code. The question is, how do we get it to do what we want? Without further ado, here's an implementation that gives us enough:
has many authors
belongs to blog
belongs to isp
}
Author := IoRecord {
has many blogs
has many posts
has one name
}
IoRecord := Object clone do(Since I'm a bad person and really enjoys metaprogramming, I had to get rid of most of the duplication the first implementation contained. Let's say it like this: the first version didn't have the collector and appender methods. And boy do they make a difference. This is real metaprogramming. Actually, these two methods are actually macros, almost as powerful as Common Lisps. Notice that the words we send in to collector doesn't actually get evaluated. This is one of the reasons we don't need to use symbols - we can just take the unevaluated messages and take their name. In the appender macro we're doing something really funky where we use setNext.
init := method(
self belongings := list
self hasOnes := list
self hasManies := list
self hasFews := list
)
appender := method(msg,
blk := block(
call sender doMessage(msg) append(call message next name)
call message setNext(call message next next)
)
blk setIsActivatable(true)
)
collector := method(
meths := call argCount / 2
waiter := Object clone
for(index, 0, meths-1,
waiter setSlot(call argAt(index*2) name,
appender(call argAt(index*2+1)))
)
waiter
)
belongs := collector(
to, belongings
)
has := collector(
many, hasManies,
one, hasOnes
)
curlyBrackets := method(
current := self clone
call message setName("do")
current doMessage(call message)
)
)
No comments yet.
You must be logged in to add your own comment.