The Green Hop

June 17th, 2009

New poem (from March): The Green Hop.

Smalltalk snippet of the day: Fizz Buzz

February 28th, 2007

The spec. is: print the numbers from 1 to 100, except where a number is divisible by 5, print “Fizz”, and where divisible by 7, print “Buzz”. Where divisible by both, print “Fizz Buzz”.

1 to: 100 do:
    [ :i | | fb |
    fb := (#((5 'Fizz') (7 'Buzz'))
        select: [ :each | i \\ each first = 0 ])
        collect: [ :each | each second ].
    Transcript
        << (fb isEmpty
            ifTrue: [ i ]
            ifFalse: [ fb fold: [ :a :b | a, ' ', b ] ]) ;
        nl. ].

Nested ifTrue:ifFalse:, or and: / or: might do the job in fewer lines, but would be more cryptic. Note that this version splits out the ’spec’ part into an array, so you could add (11 ‘Bazz’). Nevertheless, I feel that there could be a better version…

This came up in the context of an article which said that 199 out of 200 job applicants couldn’t code it correctly. Many people expressed disbelief, claiming that it is an easy problem. The thing is, it’s not that easy. Sure, you can write a version that works, but getting it exactly right first time is hard. I didn’t: I didn’t suppress the numbers when it was Fizz (or Buzz); I only printed one of Fizz / Buzz, when both matched, and so on.

I suppose my mistake was not to write tests in advance of coding (because it was a simple problem - duh). Next time, I will try that.

Smalltalk example of the day

February 23rd, 2007

I often find myself typing out code snippets to prove to myself that, yes, it really is easy in Smalltalk. Rather than keep them to myself, I think they may be useful as examples of Smalltalk code, so I’m going to try starting a series.

At The Daily WTF, they are removing spaces from a string. In Smalltalk, this is:

'The cat sat on the mat' copyWithout: Character space.

If you want to remove any whitespace, you can use:

'The cat sat on the mat' reject: [ :c | c isSeparator ].

Remove any non-alphanumeric:

'The cat sat on the mat' select: [ :c | c isAlphaNumeric ].

Mouse

November 25th, 2006

Thought I’d post this mouse. It’s the first SVG drawing I did.

mouse

As with all my images, this is available under a CC attribution / share-alike license.

A Pop Client

November 20th, 2006

This is ported from CL-POP, which is written by Brian Sorg and is gratifyingly easy to port. Not sure if that is because of Brian’s good code, because POP is a very simple protocol, or because of the cousinly similarity of Lisp and Smalltalk.

pop.tgz.

Also contained in the archive is an example script which deletes mail off of the server according to its headers.

NB. Only those methods of PopClient which are in the tests or used by the script have been tested, and that does not include retrieving whole messages.

My First Scheme Program!

November 12th, 2006

I was following a Photoshop tutorial for creating Lichenstein-style images when I realized that it was using a built-in filter, which GIMP lacks… so I wrote one.

Halftone dots version 1.

I haven’t wrapped it up with the script-fu stuff, so if you want to run this for yourself, you have to run the (define)s first, then the script at the end; it will create a new layer with a dot-rendition of the currently active layer.

I’ve been wanting to learn Lisp/Scheme for some time now, but needed a project. I must say, GIMP makes it quite hard - it often uses arrays instead of lists, for example, and the IDE - well, it’s charitable to call it even that. Still, it offers me a lot more possibilities than I had before. If only Inkscape were scriptable.

Correction - these are halftone dots; benday dots are of uniform size (much easier). Possibly the dots should be on a 45 degree grid as well.

New Smalltalk article series

October 6th, 2006

I didn’t find writing a tutorial very satisfactory, so I’m going to try another take on introducing Smalltalk, by talking about those features of the language that really amaze me.

Wow Smalltalk!

SVG Browser pt. 2

October 5th, 2006

The SVG browser has the problem that putting text at angles seems to make Firefox start working the processor hard, even after the image is rendered. Don’t know why.

Anyway, here’s a reworking of the Class diagram with the methods all horizontal. Maybe it’s more readable too…

Class diagram - horiz. text

Here’s a mockup of a class hierarchy diagram:

Obviously, I don’t expect to show the whole tree this way - only small portions of it.

SVG Browser

October 4th, 2006

Some screenshots of the SVG browser I was playing with a while back:

A class diagram (inspired by the ‘donut’ diagrams in “Smalltalk, Objects, and Design”):

Class diagram

A namespace tree - the maths needs a bit of work, and the tree is way too cramped:

Namespace diagram

Smalltalk logos

September 29th, 2006

Not so long ago, there was a thread on comp.lang.smalltalk proposing a new logo: [|]. Somebody mentioned Polly Morphic, the parrot mascot of the Smalltalk Chronicles (I think it was). Anyway, I like Polly Morphic much better than the brackets thing, so here’s my effort (ignore the writing for now):

Polly Morphic

This is the SVG original: Polly Morphic - SVG.

I’ve also found that jpeg artifacts can be quite pleasing sometimes:

Polly Morphic - with jpeg artifact feathers

By request, here’s a cropped version.

Polly Morphic - cropped

I’m going to try re-drawing her in a horizontal position.

The license for these images is CC attribution / share-alike, but I’m open to offers/requests.