Skip to content

Commit

Permalink
no more weblog.raganwald.com!
Browse files Browse the repository at this point in the history
  • Loading branch information
raganwald committed Feb 17, 2013
1 parent ebeda01 commit 9b1c9fe
Show file tree
Hide file tree
Showing 39 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion 2008-10-27/unfold.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unfold
---

Here's a little something from my old blog that I found myself using again. If you want the background, you might like my old posts [Really simple anamorphisms in Ruby](http://weblog.raganwald.com/2007/11/really-simple-anamorphisms-in-ruby.html) and [Really useful anamorphisms in Ruby](http://weblog.raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html).
Here's a little something from my old blog that I found myself using again. If you want the background, you might like my old posts [Really simple anamorphisms in Ruby](http://raganwald.com/2007/11/really-simple-anamorphisms-in-ruby.html) and [Really useful anamorphisms in Ruby](http://raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html).

This week-end, I found myself thinking about `#unfold` in a new way: it's a way of turning an iteration into a collection. So anywhere you might use `for` or `while` or `until`, you can use `#unfold` to create an ordered collection instead. This allows you to use all of your existing collection methods like `#select`, `#reject`, `#map`, and of course `#inject` instead of writing out literal code to accomplish the same thing.

Expand Down
4 changes: 2 additions & 2 deletions 2008-10-27/unfold.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# unfold.rb
#
# see Really simple anamorphisms in Ruby:
# http://weblog.raganwald.com/2007/11/really-simple-anamorphisms-in-ruby.html, and:
# http://raganwald.com/2007/11/really-simple-anamorphisms-in-ruby.html, and:
#
# Really useful anamorphisms in Ruby:
# http://weblog.raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html
# http://raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html
#
# The MIT License
#
Expand Down
4 changes: 2 additions & 2 deletions 2008-10-30/thrush.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The thrush is written `Txy = yx`. It _reverses_ evaluation. In Ruby terms,
thrush.call(a_value).call(a_proc)
=> a_proc.call(a_value)

In [No Detail Too Small](http://weblog.raganwald.com/2008/01/no-detail-too-small.html), I defined `Object#into`, an implementation of the thrush as a Ruby method:
In [No Detail Too Small](http://raganwald.com/2008/01/no-detail-too-small.html), I defined `Object#into`, an implementation of the thrush as a Ruby method:

class Object
def into expr = nil
Expand Down Expand Up @@ -75,7 +75,7 @@ Much better, Ruby 1.9 creates a new scope inside the block and `x` is local to t
# ...
end

`let` creates a new scope and defines your block local variable inside the block. This [signals](http://weblog.raganwald.com/2007/11/programming-conventions-as-signals.html "Programming conventions as signals") that the block local variable is not used elsewhere. Imperative methods can be easier to understand when they are composed of smaller blocks with well-defined dependencies between them. A variable local to the entire method creates a dependency across the entire method. A variable local to a block only creates dependencies within that block.
`let` creates a new scope and defines your block local variable inside the block. This [signals](http://raganwald.com/2007/11/programming-conventions-as-signals.html "Programming conventions as signals") that the block local variable is not used elsewhere. Imperative methods can be easier to understand when they are composed of smaller blocks with well-defined dependencies between them. A variable local to the entire method creates a dependency across the entire method. A variable local to a block only creates dependencies within that block.

Although Ruby 1.8 does not enforce this behaviour, it can be useful to write code in this style as a signal to make the code easier to read.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ What just happened is that `our_and` is defined as a lambda, with `called_by_nam

There are some important implications of this approach. First, with unhygienic, `our_and` disappears. There is no `our_and` function or method, invocations are replaced by whatever `to` expression you provide. Whereas, `called_by_name` actually defines a lambda for `our_and` and defines it in scope for our block of code.

> Note: Caleb asked about the fetish for lambdas. In Ruby 1.8 MRI, it makes no difference. In other implementations, these constructs will by hygienic. Yet, these implementations do not exist yet. So, either I don't understand YAGNI, or perhaps I have spent too much time with languages like JavaScript that [actually get this right](http://weblog.raganwald.com/2007/08/block-structured-javascript.html "Block-Structured JavaScript"), or I am from the future and I know that Ruby will get this right.
> Note: Caleb asked about the fetish for lambdas. In Ruby 1.8 MRI, it makes no difference. In other implementations, these constructs will by hygienic. Yet, these implementations do not exist yet. So, either I don't understand YAGNI, or perhaps I have spent too much time with languages like JavaScript that [actually get this right](http://raganwald.com/2007/08/block-structured-javascript.html "Block-Structured JavaScript"), or I am from the future and I know that Ruby will get this right.
Second, even though `temp` is still around and still could shadow some variable where it is defined, it doesn't shadow any definition inside your block. So you could define rewriters with `called_by_name` at the top level or inside of a method somewhere and be assured that you are making 100% hygienic code.

Expand Down
2 changes: 1 addition & 1 deletion 2008-11-04/unary_ampersand_in_ruby.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ So that's it: When you want to convert a block to a `Proc`, define an extra para

When you want to convert any object to a block, pass it to a method expecting a block and preface it with an ampersand. Ruby will call the `#to_proc` method if need be, then convert the `Proc` into a block.

p.s. *This post originally appeared on [weblog.raganwald.com](http://weblog.raganwald.com/2008/06/what-does-do-when-used-as-unary.html "The unary ampersand in Ruby")*
p.s. *This post originally appeared on [raganwald.com](http://raganwald.com/2008/06/what-does-do-when-used-as-unary.html "The unary ampersand in Ruby")*

---

Expand Down
2 changes: 1 addition & 1 deletion 2008-11-07/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Aspect-Oriented Programming in Ruby using Combinator Birds
---

In [Combinatory Logic](http://en.wikipedia.org/wiki/Combinatory_logic), the bluebird is one of the most important and fundamental combinators, because the bluebird *composes* two other combinators. Although this is usually discussed as part of [functional programming style](http://weblog.raganwald.com/2007/03/why-why-functional-programming-matters.html "Why Why Functional Programming Matters Matters"), it is just as valuable when writing object-oriented programs. In this post, we will develop an [aspect-oriented programming](http://en.wikipedia.org/wiki/Aspect-oriented_programming "") (or "AOP") module that adds before methods and after methods to Ruby programs, with the implementation inspired by the bluebird.
In [Combinatory Logic](http://en.wikipedia.org/wiki/Combinatory_logic), the bluebird is one of the most important and fundamental combinators, because the bluebird *composes* two other combinators. Although this is usually discussed as part of [functional programming style](http://raganwald.com/2007/03/why-why-functional-programming-matters.html "Why Why Functional Programming Matters Matters"), it is just as valuable when writing object-oriented programs. In this post, we will develop an [aspect-oriented programming](http://en.wikipedia.org/wiki/Aspect-oriented_programming "") (or "AOP") module that adds before methods and after methods to Ruby programs, with the implementation inspired by the bluebird.

> As explained in [Kestrels](http://github.com/raganwald/homoiconic/tree/master/2008-10-29/kestrel.markdown#readme), the practice of nicknaming combinators after birds was established in Raymond Smullyan's amazing book [To Mock a Mockingbird](http://www.amazon.com/gp/product/0192801422?ie=UTF8&tag=raganwald001-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0192801422). In this book, Smullyan explains combinatory logic and derives a number of important results by presenting the various combinators as songbirds in a forest. Since the publication of the book more than twenty years ago, the names he gave the birds have become standard nicknames for the various combinators.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Aspect-Oriented Programming in Ruby using Combinator Birds
---

In [Combinatory Logic](http://en.wikipedia.org/wiki/Combinatory_logic), the bluebird is one of the most important and fundamental combinators, because the bluebird *composes* two other combinators. Although this is usually discussed as part of [functional programming style](http://weblog.raganwald.com/2007/03/why-why-functional-programming-matters.html "Why Why Functional Programming Matters Matters"), it is just as valuable when writing object-oriented programs. In this post, we will develop an [aspect-oriented programming](http://en.wikipedia.org/wiki/Aspect-oriented_programming "") (or "AOP") module that adds before methods and after methods to Ruby programs, with the implementation inspired by the bluebird.
In [Combinatory Logic](http://en.wikipedia.org/wiki/Combinatory_logic), the bluebird is one of the most important and fundamental combinators, because the bluebird *composes* two other combinators. Although this is usually discussed as part of [functional programming style](http://raganwald.com/2007/03/why-why-functional-programming-matters.html "Why Why Functional Programming Matters Matters"), it is just as valuable when writing object-oriented programs. In this post, we will develop an [aspect-oriented programming](http://en.wikipedia.org/wiki/Aspect-oriented_programming "") (or "AOP") module that adds before methods and after methods to Ruby programs, with the implementation inspired by the bluebird.

> As explained in [Kestrels](http://github.com/raganwald/homoiconic/tree/master/2008-10-29/kestrel.markdown#readme), the practice of nicknaming combinators after birds was established in Raymond Smullyan's amazing book [To Mock a Mockingbird](http://www.amazon.com/gp/product/0192801422?ie=UTF8&tag=raganwald001-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0192801422). In this book, Smullyan explains combinatory logic and derives a number of important results by presenting the various combinators as songbirds in a forest. Since the publication of the book more than twenty years ago, the names he gave the birds have become standard nicknames for the various combinators.
Expand Down
2 changes: 1 addition & 1 deletion 2008-11-26/string_to_proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Portions Copyright (c) 2006 Oliver Steele
# <http://braythwayt.com> except as otherwise noted.
#
# See http://weblog.raganwald.com/2007/10/stringtoproc.html
# See http://raganwald.com/2007/10/stringtoproc.html
#
# Ported from the String Lambdas in Oliver Steele's Functional JavaScript
# http://osteele.com/sources/javascript/functional/
Expand Down
2 changes: 1 addition & 1 deletion 2008-11-28/string_to_proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Portions Copyright (c) 2006 Oliver Steele
# <http://braythwayt.com> except as otherwise noted.
#
# See http://weblog.raganwald.com/2007/10/stringtoproc.html
# See http://raganwald.com/2007/10/stringtoproc.html
#
# Ported from the String Lambdas in Oliver Steele's Functional JavaScript
# http://osteele.com/sources/javascript/functional/
Expand Down
2 changes: 1 addition & 1 deletion 2008-11-28/you_cant_be_serious.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The other way is to say that I want to compose `.inject` and `+` together. Witho

".inject(&'+')"

Meaning "*I want a new lambda that does an inject using plus*." Point-free style does require a new way of thinking about some things, but it is a clear win for simple cases. Proof positive of this is the fact that Ruby on Rails and Ruby 1.9 have both embraced point-free style with `Symbol#to_proc`. That's exactly how [`(1..100).inject(&:+)`](http://weblog.raganwald.com/2008/02/1100inject.html "(1..100).inject(&:+)") works!
Meaning "*I want a new lambda that does an inject using plus*." Point-free style does require a new way of thinking about some things, but it is a clear win for simple cases. Proof positive of this is the fact that Ruby on Rails and Ruby 1.9 have both embraced point-free style with `Symbol#to_proc`. That's exactly how [`(1..100).inject(&:+)`](http://raganwald.com/2008/02/1100inject.html "(1..100).inject(&:+)") works!

`String#to_proc` supports fairly simple cases where you are sending a message or using a binary operator. So if we wanted to go all out, we could write our example as:

Expand Down
2 changes: 1 addition & 1 deletion 2008-12-12/fibonacci.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
A program to compute the nth Fibonacci number
===

Since [I'm looking for a job](http://braythwayt.com/reginald/RegBraithwaite20120423.pdf "Reginald Braithwaite's Resume") and people often like to ask for a [fizzbuzz](http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html "Don't Overthink FizzBuzz") program to weed out the folks who can't string together a few lines of code, I thought I'd write up a program to compute the nth Fibonacci number. There's an intriguing bit of matrix math involved, so I learned something while implementing it.
Since [I'm looking for a job](http://braythwayt.com/reginald/RegBraithwaite20120423.pdf "Reginald Braithwaite's Resume") and people often like to ask for a [fizzbuzz](http://raganwald.com/2007/01/dont-overthink-fizzbuzz.html "Don't Overthink FizzBuzz") program to weed out the folks who can't string together a few lines of code, I thought I'd write up a program to compute the nth Fibonacci number. There's an intriguing bit of matrix math involved, so I learned something while implementing it.

*Reminder: This was written in 2008, it does not necessarily reflect my employment situation today.*

Expand Down
2 changes: 1 addition & 1 deletion 2008-12-17/another_fibonacci.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In this version, `Fibonacci` is an entity in Kernel namespace. You do not call `

Also, the class `Fibonacci::Matrix` explicitly defines `*` and `^` so that we can write arithmetic operations on matrices the way we write them on integers. This is one of the prime motivations for languages like Ruby to permit operator overloading. A comparison of this point to the first version is inconclusive to my eyes. `*` and `^` are terser than `times` and `power`.

However, defining them as operators means making them methods in Ruby. This is a little suspect because our code isn't truly polymorphic. It's not like we write `x = y * z` and are oblivious to the implementation of `*` that `y` provides at run time. This is a failing of many OO programs: They look like OO, but they are really written procedurally or functionally, however the OO mechanisms hamper rather than support the program. [Not all functions should be object methods](http://weblog.raganwald.com/2007/10/too-much-of-good-thing-not-all.html "Too much of a good thing: not all functions should be object methods"). The original version was blatant about its behaviour: `times` and `power` were written as lambdas, and it was very obvious that they did one thing only without presenting the facade of polymorphism.
However, defining them as operators means making them methods in Ruby. This is a little suspect because our code isn't truly polymorphic. It's not like we write `x = y * z` and are oblivious to the implementation of `*` that `y` provides at run time. This is a failing of many OO programs: They look like OO, but they are really written procedurally or functionally, however the OO mechanisms hamper rather than support the program. [Not all functions should be object methods](http://raganwald.com/2007/10/too-much-of-good-thing-not-all.html "Too much of a good thing: not all functions should be object methods"). The original version was blatant about its behaviour: `times` and `power` were written as lambdas, and it was very obvious that they did one thing only without presenting the facade of polymorphism.

`Fibonacci::Matrix` also takes advantage of `Struct`. You can read [all about Struct](http://blog.grayproductions.net/articles/all_about_struct) if you are not familiar with this handy tool. Note that `Struct.new` returns a class, not an instance of a Struct. This is a very handy paradigm for Ruby programs.

Expand Down
2 changes: 1 addition & 1 deletion 2008-12-18/called_by_name.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Now, `called_by_name` is not a replacement for macros. There are lots of things

Of course, `called_by_name` does so with lots of anonymous functions, and that is a much more expensive implementation than using a hygienic macro to rewrite code inline. But it feels like a move in an interesting direction: if it is a win to sometimes meta-program Ruby's syntax with DSLs, it ought to also be a win to sometimes meta-program Ruby's semantics with call-by-name functions.

*(This material was originally published [June, 2008](http://weblog.raganwald.com/2008/06/macros-hygiene-and-call-by-name-in-ruby.html "Macros, Hygiene, and Call By Name in Ruby on raganwald.com"))*
*(This material was originally published [June, 2008](http://raganwald.com/2008/06/macros-hygiene-and-call-by-name-in-ruby.html "Macros, Hygiene, and Call By Name in Ruby on raganwald.com"))*

Update (December 18, 2008)
---
Expand Down
2 changes: 1 addition & 1 deletion 2009-01-02/flight_of_the_phoenix.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Whither Rewrite?

So, the Rewrite Gem broke when ParseTree and Ruby2Ruby changed some of their representations. I thought about either freezing the versions Rewrite needed or upgrading the gem, but then I had a remarkably stupid idea: Why not try to make it a little more useful than a proof-of-concept?

So, I started [RewriteRails](https://github.com/raganwald-deprecated/rewrite_rails/tree). The idea is remarkably simple: You are writing a Rails project. You want to use things like [`andand`](http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html "Object#andand & Object#me in Ruby") and [`String#to_proc`](http://weblog.raganwald.com/2007/10/stringtoproc.html "String#to_proc"). But you either have a fastidious disdain for opening core classes and slinging proxy objects around, a fanatical need for speed, or you want to be able to rip all that stuff out if you grow bored with it.
So, I started [RewriteRails](https://github.com/raganwald-deprecated/rewrite_rails/tree). The idea is remarkably simple: You are writing a Rails project. You want to use things like [`andand`](http://raganwald.com/2008/01/objectandand-objectme-in-ruby.html "Object#andand & Object#me in Ruby") and [`String#to_proc`](http://raganwald.com/2007/10/stringtoproc.html "String#to_proc"). But you either have a fastidious disdain for opening core classes and slinging proxy objects around, a fanatical need for speed, or you want to be able to rip all that stuff out if you grow bored with it.

RewriteRails solves all of these problems I invented that nobody is complaining about.

Expand Down
2 changes: 1 addition & 1 deletion 2009-01-13/maybe.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ One of the most provocative implementations suggested for handling `nil` objects

Now you can write things like `@person.name` and know that if `@person` is `nil`, you will always get `nil`. Always. Everywhere. Interesting! In fact, it's another implementation of the Maybe Monad, only in a very clever, OO way. That being said, here's why it doesn't work for me.

Right off the bat, [semantics like this really should not be implemented as methods](http://weblog.raganwald.com/2007/10/too-much-of-good-thing-not-all.html "Too much of a good thing: not all functions should be object methods"). Why does `nil + 1` produce `nil`, but `1 + nil` produce `TypeError: coerce must return [x, y]`? There's a real problem trying to make anything involving `nil` commutative.
Right off the bat, [semantics like this really should not be implemented as methods](http://raganwald.com/2007/10/too-much-of-good-thing-not-all.html "Too much of a good thing: not all functions should be object methods"). Why does `nil + 1` produce `nil`, but `1 + nil` produce `TypeError: coerce must return [x, y]`? There's a real problem trying to make anything involving `nil` commutative.

In fact, I would go so far as to say that `:foo == nil` should be `nil`, as should `:foo != nil`. That makes sense, because as given:

Expand Down
Loading

0 comments on commit 9b1c9fe

Please sign in to comment.