Thursday, May 27, 2010

My First Script-Fu Script

 
I'm exploring how to write a Script-Fu
script. Actually, I wrote one years ago.
However, it has been so long since then
that I've forgotten most of what I learned.

Time to update my skills.

Here's a Script-Fu tutorial that I like:

A Script-Fu Tutorial

The first thing the tutorial does is give
you a little knowledge of the Scheme programming
language. Script-Fu scripts are written in
Scheme.

I've been trying to review Scheme and have even
created a blog for doing so. My first Scheme blog
post is here:

Learn to Program in
Scheme 1, Getting Started


The overall Scheme blog that this post comes from
is here:

Learn to Program in Scheme

OK. Back to the tutorial. The tutorial makes
three simple points about Scheme:

  1. Statements are surrounded by parentheses
  2. The first item inside the parentheses is
    the operator
  3. Since functions are basically operations that
    you write yourself, functions also come first
    inside the parentheses

In some ways, it would seem that Scheme is a
simplified programming language. All you have
is operators and arguments to operators. The
operator and its arguments are surrounded by
parentheses. It's that simple.

OK. That's a too brief summary of Scheme on
my part. However, since I'm learning this stuff
myself as I write, I want to keep moving.

I'll try some of the console stuff first. To
get to the console, fire up Gimp and go through
the following menus:

Xtns > Script-Fu > Script-Fu Console

A cautionary note about the second menu.
It seems that on my version of Gimp, there
are 2 menus labeled Script-Fu. That
is to say, the Xtns menu has two items
with the same name. Why that is I'll probably
never know.

In any case, it is the first Script-Fu
menu that is of interest. This is the one that
has the Script-Fu Console menu underneath
it.

As the tutorial suggests, I enter the following
in the bottom of the console window:

(+ 3 5)

I get this back as output:

> (+ 3 5)
8

OK. This is kind of fun. I assume
that the number 8 comes back and
prints because Scheme operations
always return an argument of some
kind. That's my, as of now, vague
understanding of Scheme.

Wow! Just noticed the console has a
save button. Does this mean
you can save things that you try out?
Perhaps. I have not tried this feature
yet.

I'll leave off here. The next blog
post will cover the let operator.
Perhaps I should call it the let
statement. In any case, let will
be the subject of my next post as this
seems to be the next topic in the tutorial.

One lesson I've learned from this tutorial
is that you have to do the work. To get
results and to learn, you have to do what
the tutorial author suggests for homework.

My tendency is to want to read a tuturial
and absorb the whole thing in one single
reading. Sometimes that's not possible.
Sometimes it's important to do your homework.

Ed Abbott

No comments:

Post a Comment