How to Kill Wisteria

12 02 2011

 

Our house came with wisteria plant preinstalled. Like all craplets it looked useful at first, climbing up the tressles, providing a touch of class and some handy shade. It looked good ant served a function. Little did I know…

The problem with wisteria is that it grows. As it grows, it loses the refined and cultured appearance, turning the previously elegant pergola into an overgrown mess. Trim it you say? The stuff grows faster than a crowd at a highschool fight. Trim it and it’s back the next day. It’s like the scene in X-men 3 when Wolverine is fighting that guy whose arms keep growing back.

Since the control of wisteria requires a dedication far greater than my laziness allows, this summer I decided to kill the monster. It was a difficult decision, but was the only way I could ensure escape from the beast that had tortured me for years. This was my chance for freedom.

I set to work with my trusty pruning shears and saw. I hacked, and chopped and sweated from sunrise to sunset for days on end. My muscles ached, back hurt, and I’d developed something they call “blisters”. But it was worth the effort. Eventually that wisteria plant was nothing but a stump. I WAS FREE! THE WISTERIA WAS GONE!

To ensure this freedom remained, I poisoned the stump with weed killer. Twice. And then I slept, sound in the knowledge that I would never be bothered by wisteria again.

A peaceful two weeks ensued. Everything was sunshine, lollipops and rainbows. Until this morning. I was in the garden, and what did I see? A stump covered in fresh leaves and sprouts. The devil plant still lives. The nightmare continues.

How do you kill a wisteria plant? I’ve come to the conclusion that you can’t. I think I’ll just move.





Proper Semicolon Usage

14 09 2010

There comes a point in every man’s life where he must ponder how to use a semi-colon properly. Some of you may think the answer is obvious: it’s to mark the end of a statement in the line of code. Wrong. The semicolon was around way before C, C++, Java, and the like. It was on the keyboard long before computers were invented – programmers just made use of it.

I remember being taught this many moons ago in high school. However, I wasn’t paying much attention, and have never used them in writing since. So the knowledge has faded and it’s time for a refresher.

In English semicolons are used:

  • To separate items in a list or series that has internal punctuation. For example: Wellington, New Zealand; Canberra, Australia; London, England; and Paris, Texas.
  • To connect two closely related independent clauses (sentences that can stand alone) without a conjunction. For example:

I like children; they taste great on toast.

Semicolons are old-hat; no one uses them anymore.

I don’t like the drugs; the drugs like me.

  • To join two independent clauses with the use of a transitional phrase or conjunctive adverb. For example:

He has large feet and hands; therefore, his other appendages must be large too.

I am in Auckland; hence, the weather is bad.

  • Apparently they can also be used before introductory statements; although, I can’t ever recall seeing this done before. For example:

Always look on the bright side of life; for example the sun is shining, birds are singing, and children are playing.

So what am I going to do with this new found knowledge? Most likely forget it; in most cases, the semicolon can be replaced with either a full stop or comma and a conjunction. That is why the semicolon’s usage is on the fall; they’re simply not needed.

I have a lot of writing to do for university in the next year, and I definitely need to brush up on my skills. However, I don’t see any real advantage in using semicolons; except to look smart.





Notes on LISP Part V: Recursion

10 09 2010

“To understand recursion, you must first understand recursion.”

Resursion is where a function calls itself as part of its definition. As such, a recursive function must consist of two parts:

  1. A termination condition.
  2. Rules that reduce other conditions towards that termination condition.

Consider this simple LISP function to find the last element in a list which works recursively by calling itself.

Code:
(defun my-last ( l1 )
   (if (null (cdr l1) )
      l1
      (my-last (cdr l1))
   )
)

(my-last ‘(a b c  d e f g))

 Result:
G

The termination condition is if (null cdrl1) returns T (or true) list input l1 must be the last item in the list as there are no more items and the current  l1 Is returned.

The reduction rules are that if (null cdrl1) returns nil (or false) this is not the end of the list so the next item in the list is checked by calling (my-last (cdr l1)). The new value for l1 is checked, and so on until (if (null (cdr l1)) returns T and the process is ended.

Recursive functions have their advantages and disadvantages over iterative functions. Some problems can be easier to solve using recursion, making for less complex and simpler code. However iteration can be faster, uses less memory, and is less abstract so makes for easier to understand code.





Notes on LISP Part IV: car and cdr

9 09 2010

Here’s where the LISt Processing fun begins!

Car returns the first item in a list.

Example:
(defvar A ‘(a b c d e))
(car A)

Result:
A

cdr returns the rest.

Example:
(defvar A ‘(a b c d e))
(cdr A)

Result:
B C D E

 

Combining

car and cdr can also be combined in the form cxr where x is a combination of up to four a or ds with a representing car and d representing cdr.

Example:
(defvar A ‘(a b c d e))
(caddr A)

Result:
C

This is equivalent to taking the car of the cdr of the cdr of A.

Equivalent code:
(defvar A ‘(a b c d e))
(car (cdr (cdr a)))

Result:
C

Using these two functions, ou can select any value in a list of sub-list.

 

What the lecturer didn’t tell us

An alternate way of selecting values in a list is to use the nth function which takes the form (nth position list). In Common LISP, lists are zero indexed meaning an positions starts at zero.

Example:
(defvar A ‘(a b c d e))
(nth 2 A)
Result:
C

There is also an nthcdr function which performs n number of cdr functions on a list.  
Example:
(defvar A ‘(a b c d e))
(nthcdr 2 A)
Result:
C D E

Common LISP also has functions first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, and tenth to select items from a list.

Example:
(defvar A ‘(a b c d e))
(third A)
Result:
C

Why did the lecturer not tell us this? My theory is that he likes saying car and cdr combined. Go on… say it car cdr car car car. It’s fun! Make any combination you want;)





Notes on LISP Part III: Why the quote(‘)?

7 09 2010

Simply put, so we can tell the difference between a value and a variable.

Code:
(list a b)

Result:
Error: Attempt to take the value of the unbound variable `B’.

With the quote:
Code:
(list ‘a ‘b)
Result:
(A B)





LISP Notes Part II: Division

7 09 2010

How does LISP do math? Let’s see by having a play with the division function.

Code: (/ 30 5 2)
Result: 3

That shows to me that calculations are done from left-to-right with the order of evaluation being 30 ÷ 5 = 6 then 6 ÷2 =3.

Code: (/ 30 (/ 5 2))
Result: 12

As expected, by altering the code (/ 5 2) changes the result. But what’s interesting about this is that it gives the correct result. That may not seem so interesting, but if you compare it with Java:

Code:

public class divide{
   public static void main(String[] args){
      System.out.println(30/(5/2));
   }
}

Output: 15

Why the difference? In Java integers round down to their nearest whole value, so 5 ÷ 2 = 2. Looks like LISP does not do this.

Code: (/ 5 2)
Result:
5/2

Hmmm interesting… in LISP it would seem that a value retains its value as a ratio until it can be converted into an integer.  That means mathematical equations give correct results. Awesome.





Notes on LISP Part I: Getting Started

6 09 2010

LISP is the programming language that was used to create The Terminator, Agent Smith, HAL, the Cylons from Battle Star Galactica, and the Decepticons. Ok,  those are all fictional characters. But, if you do want to create a psychopathic machine based entity, LISP the language of choice – the language of Artificial Intelligence (there’s also Prolog, but that ain’t what they’re teaching at Uni…).

LISP stands for LISt Processing and was developed in 1958 by some dudes at MIT (John McCarthy & Co). Yep, that’s right, 1958, which means it’s older than the sun. But hey, there ain’t nothing wrong with old technology. I still use a knife to cut my food, and that’s one of the oldest technologies there is. Heck, sometimes I even bash things with rocks. It’s all good, as long as it gets the job done.

Apparently LISP is a “functional programming language” which means that functions can be treated like variables, ie: functions can take functions as parameters and output functions. That means LISP can be used to write programs that write programs. That’s heavy.

Anyway, since LISP is so old there are quite a few different versions of it, and the one we’re learning at university is Common LISP.

First thing needed is a LISP interpreter. There are plenty of free LISP interpreters around and the one I’m using as recommended by my university lecturer is Allegro Common LISP,  downloaded  for free  from www.franz.com.

Next before we play, we need to know some function.

Here are some basic keywords/symbols I’ve learnt thus far:

Basic LISP Primitives     

Keyword/Symbol What it does/means
+ Adds two numbers. Takes the form (+5 4) = 9.
- Subtracts the second from the first.  (- 9 5) = 4
* Multiply
/ Divide
car Returns the first element from a list.
cdr Removes the first element from a list and returns the rest of the list.
‘(quote) Stops the evaluation of the expression that follows it.
cons Joins two objects.
append Joins two lists by adding the first to the beginning of the second.
list Creates a list.
length Returns the length of a list
Reverse Reverses a list
setf Used to set values.
defun Used to define a function.
defvar Defines a variable.
nil Has no value. Also used in conditional tests. If a test is false nil is returned, otherwise t is returned.
t A value of anything other than nil.
if If conditional test. Takes the form:(if(condition) (do-if-t)(do-if-nil)
when when conditional test. Takes the form:(when(test)( code))
unless Opposite of when. Completes the code it test returns nil.
cond Multiple condition test. Returns the last expression assessed, unless no tests are evaluated as true, in which case it returns nil.Takes the form:(cond((test1 expression)(test2 expression)(test3 expression)))
equal, = Boolean function that returns true if the given arguments are the same.
listp Boolean function that returns true if the given argument is a list.
numberp Boolean function that returns true if the given argument is a number.
atom Returns true if an object is an atom, nil if otherwise.
evenp Boolean function that returns true if the given argument is an even number.
oddp Boolean function that returns true if the given argument is an odd number.
null Boolean function. Returns True if a liest is empty.
and Logical and.
or Logical or.
not Logical not.
member Returns true if first argument is a member of the second argument.
let Creates a local variable.
do Loop. Takes the form (do ((variable initial update) (code)))







Follow

Get every new post delivered to your Inbox.