Lots of Irritating Superfluous Parentheses
LISP: The Programming Language From Hell
The year is 1999. Current affair and news programs are running segments detailing a possible near-apocalypse, where there is no electricity or water, necessary services are down, and mobs are out looting. People are being advised to stock up on necessities, just in case the worst happens. (As it turns out, nothing very much will happen, very much disappointing a bored eleven year old girl who was looking forward to an exciting period of her life that she could one day bore her children and grandchildren with.) (Although, Sydney tested a new management program designed to automatically add a certain amount of flouride to the city’s water, and the program promptly dumped an entire year’s supply into everyone’s water. People had to drink bottled water for weeks.)
In the IT world, everyone is frantically rewriting and editing computer code to bring it into the new millenium. Some segments of this code is 30 years old or so, and though basic, are absolutely huge. Unfortunately, all this code happens to be written in a much older programming language - one that most people no longer use and therefore, no longer learn. Bugger. We have a problem.
Cut to 2006. After the Y2K Bug problem, people are once again being taught, at least to some degree, one of three of the older languages: Fortran, COBOL, and Lisp. The IT industry wants to make sure that everyone has at least some idea of how the older languages work, just in case there’s ever a case where they’re so idiotically short-sighted once more. (I don’t blame the people who wrote the original code. After all, they had some 30 years to go. I blame the stupid idiots who kept using the code without updating it. Honestly.)
Unfortunately, this means that I am now bewilderedly doing my best to program in the scheme dialect of Lisp, which is totally alien to everything I’ve ever done before, not to mention linguistically challenged. It consists of a few words and a whole heap of brackets that unfortunately make absolutely no sense to the untrained observer. Of course Lisp is, in its way, a very useful language - it’s dynamic and easy to use once you grasp it, and is experiencing a resurgence of interest among open-source programmers - but utterly frustrating to those used to, say, languages like visual basic where everything is a lot more specific and detailed, and half-English. I’m getting tutored my my neighbour for the moment, but damn I hate this stuff.
Kieran said,
June 9, 2006 @ 7:03 am
Well, with the exam tommorow I suppose it’s a bit late to offer my help again.
The trick to remember with scheme is that the brackets surround an instruction, with each of the little bits inside the brackets being some ingredient.
(for anyone else reading, substitute ‘instruction’ for ‘procedure’ and you’ve got the real lingo)
When you’re talking about nesting brackets what you need to look at is that every ingredient to the first instruction is also an instruction surrounded by brackets, so just ignore the contents and just see (another instruction).
e.g.
(number? number)
is an instruction that tells you if ‘number’ is a number. The first word tells you what’s going on, and the second one tells you the ingredient.
(+ 3 4)
is an instruction that adds 3 and 4. Again the first bit tells you what’s going on and the other bits are ingredients into it.
(if (number? number)
(+ 3 number)
“Error”)
Getting a little more complicated now with nesting but it’s still the same stuff.
The ‘if’ instruction takes something to check, something to do if it’s true and something to check if it’s false.
(if (condition) (do-if-true) (do if false))
That’s what I see. I’ll put it back into the form it was…
(if (condition)
(do-if-true)
(do-if false))
In this case the condition is another instruction, so it needs to go in brackets. so is ‘do-if-true’. ‘Do-if-false’ however, is not an instuction, so no brackets are needed.
You can quite easily put that ‘if’ structure into another instruction if you want.
Whenever you run an instruction, there is a result. This is called the ‘return value’. For example, (+ 3 4) returns ‘7′. An ‘if’ instruction returns the value of ‘do-if-true’ if the condition is true but returns the value of ‘do-if-false’ if the condition is false.
‘Define’ is the same. (Define (number 3)) simply makes ‘number’ have the value ‘3′. So if you use ‘number’ in that program, it will be the same as writing ‘3′.
‘Define only looks complicated when it’s used to define another procedure. Take this for example…
(define (is-big? number)
(if (> number 10)
“yes, the number is big”
“no, the number is small”))
All you’re really doing there is making it so that you can write (is-big? some-number) instead of having to write all that ‘if’ stuff underneath it. ‘is-big?’ is the name of the new instruction and ‘number’ is the ingredient you need to give that instruction for it to work.
Recursion is a bit harder to get your head around, so go and read the definition at http://olapps.qut.edu.au/glossary/admin/glossary.asp?GlossaryID=401#R and then take a look at this example…
(define (is-big? number)
(if (> number 10)
“yes, the number is big”
(is-big? (+ 1 number))))
Back to our ‘is-big?’ example, this time what it does is if the number isn’t big, it tries again but this time it adds 1 to the number to see if -that- is big. So now ask yourself, what will it do if number + 1 isn’t big enough…? You guessed right, it’ll try again and again until number IS big enough (that is, it’s greater than 10).
Iteration is a little different. It still calls itself again but instead of doing it because it calls itself as an ingredient of itself, it keeps doing the same thing over and over again a certain number of times. That number of times is called a ‘counter’.
Kieran said,
June 9, 2006 @ 7:04 am
Sorry that none of the indenting worked, this is why I wrote my own website instead of being at the mercy of someone else’s laziness :). That being said, you did choose what is IMHO the best blogging CMS around.
http://gamsklik.com said,
November 6, 2007 @ 7:21 pm
/ tramadol medicine