Transitioning To Sequences
Posted: June 13, 2013 Filed under: Clojure | Tags: 4Clojure, Clojure 8 Comments »Problem #157 in 4Clojure.com is listed as a very simple problem. Despite having used Clojure’s map function a lot, I saw the solution to this problem recursively using loop and recur, by walking through each element of the function and determining its count. The following solution came from http://blog.qinjian.me/2012/12/21/4clojure_solutions/ . Look for #157 in the midst of quite a few solutions.
(fn __[coll]
(loop [x (- (count coll) 1)
l []]
(if (>= x 0)
(recur (- x 1)
(conj l (list (nth coll x) x)))
(reverse l))))
This solution makes more sense to me than this solution.
#(map list % (range))
It just doesn’t look as obvious. But the prevailing wisdom is to use Clojure’s sequence functions to handle problems like this.
Setting Up Windows PowerShell
Posted: June 13, 2013 Filed under: PowerShell | Tags: PowerShell, powershell scripts Leave a comment »I am forever hopeful about new environments and languages, and even after initializing my Windows workstation to run PowerShell scripts, I still remain hopeful.
The following is an excellent stackoverflow.com post covering an error you might get if you are running PowerShell for the first time on a Windows platform other than Windows server.
Basically, until I get the whole script signing thing down, and because I do not download just anything I’m sent and sit behind reasonable content and firewall protection, I removed script running restrictions after I got this error — PowerShell execution of scripts is disabled on this system — trying to run Windows PowerShell scripts.
Basically, both the 32 and 64-bit versions of PowerShell have to have this setting changed. The easiest way to do this is to go to the start menu and search for
both versions of Windows PowerShell ISE, that is PowerShell ISE x86 and PowerShell ISE.
Run each of these as administrator, and then issue this command for unrestricted script running
Set-ExecutionPolicy RemoteSigned
or
Set-ExecutionPolicy RemoteSigned
<code>Set-ExecutionPolicy unrestricted</code>
and answer Yes when prompted.
I was trying to experiment with GUIs using this information, so we will see how that all goes.
When Clojure Is Not Flashy
Posted: May 24, 2013 Filed under: Clojure | Tags: Clojure, Informix 4GL Leave a comment »Over the past two weeks as I have prepared for a nice long rest, I wound up mostly cleaning up BASH scripts and their Informix 4GL counterpart programs. The changes were made to simplify sending data to and receiving results back from our Registry of Motor Vehicles. While not as interesting or as flashy as working with Clojure, the changes were well needed, because they involved ease of use, reliability, and simplification. To me, it is just fine to have a good cleanup effort, even if it is for an over twenty-five year old application.
Finally, I was able to spend a little time finishing up enhancements to a Clojure program that splits up real-estate assessment data, and this got me thinking.
Working with Clojure is not a good thing just because it is a Lisp dialect and programming in Lisp has always been one of my goals.
Working with Clojure is not a good thing, because it is a functional programming language or even because it is a JVM language. As it turns out the only serious Java I encountered was a Visual Cafe application that was the Vinca/Legato/EMC Co-Standby For Windows configuration application.
Working with Clojure is not a good thing, because it is an up and coming language, though I admit that is part of what drew me to learn it.
And working with Clojure is not a good thing, because using the languages encourages writing small discernible functions, C and shell scripts on Unix encouraged writing small, well written C programs years ago.
Working with Clojure is a not good thing specifically for any of those reasons , but is a great thing, because it is possible to make a change in one area and not break something due to an accidental side-effect that could more easily occur in a language that supports mutable data structures.
This reason is not glamorous or flashy, but sometimes not having things blow up and go to pieces is better than temporary flash and glitz.
Instead Clojure can be a great tool for a one-person band, because it isn’t flashy and its constructs allow for reliability, when there is not a lot of time to ensure safety or reliability.
What’s With Python Decorators?
Posted: May 18, 2013 Filed under: Python | Tags: decorators, Mark Pilgrim, Puthon Leave a comment »Nearly four years ago, I started learning a new language, Python, because I felt that as a newer language it would make sense to use it as the implementation language for a water endpoint/meter configuration and reads store and forward system. That reason extended to someone needing to maintain the system after I was gone. Using Python alone did not make the application’s modules easier to maintain, but I give some credit to the language for it.
Of all things in Python that are visually difficult for me to comprehend are decorators. I have never used one or did not know I needed to. If I were using Python on a more regular basis, like when I was designing and implementing the system, I would just decide to conquer this subject once and for all. However, one thing I have learned over the years is to be suspicious of overly complicated things that perhaps should not be, and I leave decorators there. I could have missed it, but I was not able to find a description of decorators in Mark Pilgrim’s Dive Into Python.
Perhaps I will find that post out there that just puts it all together for me, but so far, I just see confusion where decorators are concerned.
Epilogue:
I try never to give up, so this tutorial is a good start.
The 2013 Clojure Cup
Posted: May 17, 2013 Filed under: Clojure | Tags: Clojure, Clojure Cup Leave a comment »Whether I can write software in 48 hours for the Clojure Cup is one thing — it’s a challenge some days to wake up — but at least I can promote it, so that I will do.
If some wonderful municipal idea comes to me, I’ll enter something. By September I will be converting a 25-year-old tax/utility collection system to calculate, adjust, and print quarterly water bills. This will be interesting.
How To Start Using NoSQL
Posted: May 15, 2013 Filed under: database | Tags: MongoDB, NoSQL Leave a comment »Every summer, I like to have a learning goal. I gain — hopefully — more knowledge, and, besides I can write one of those corny posts about what I did over the summer. Two years ago, that goal was learning Clojure, and I’m still learning it, but around that time, I also wanted to explore so-called NoSQL databases, MongoDB in particular.
Well, this summer, despite a large project looming, I would like to take up learning MongoDB. I learned Clojure on a more accelerated level by finding a project where Clojure could safely be introduced, and, if a bailout was needed, could be re-implemented in a language like Python or Perl. I have to find a way to introduce MongoDB the same way.
I have been using SQL databases for years, and believe my understanding is reasonable on how and where a SQL database would be introduced. When switching to a NoSQL database, where is the starting point? I have lots of data, but how would the data be introduced?
So, then, the journey begins with how. Only time will tell.
Of Python, Pythonic, and Many Paths To Accomplish Something
Posted: May 8, 2013 Filed under: Python | Tags: Python Leave a comment »I want to assure you, this is not a rant against Python. Three plus years ago, I would have been hard pressed to implement an entire store/forward system for our town’s water department using anything other than Python. I could have gotten away with not using Django, but it did not hurt to use Django for this project.
Today I asked a question in stackoverflow.com regarding how to take the following data:
{'cycle1': [1, 2407, 2393, 14],
'cycle2': [2, 1657, 1652, 5],
'cycle3': [3, 2698, 2673, 25],
'cycle4': [4, 2116, 2102, 14],
'cycle5': [5, 2065, 2048, 17],
'cycle6': [6, 1633, 1615, 18]}
<code>
and sum each of the last three columns per row, so all column 1s are summed, all column 2s are summed and so on.
One of the comments to one of the questions indicated an object, rather than a list should be used. Doing so would be more Pythonic.
At a time, where there appears to be great interest in functional programming in languages like Haskell, Scala, and Clojure, why does Python appear to be moving towards objects? That is the great mystery to me. I have nothing against objects, and worked a lot with the early Microsoft Visual Studio components as well as IBM’s OS/2 Presentation Manager toolkit. A lot of good object-oriented code has been written.
I am concerned about two things. Why do I hear there one way to do something in Python, and is there an apparent move toward objects? Is this just someone’s opinion or general to the Python community?
These are just my thoughts for the day, after migrating three-year old Python code to snap all our town’s reads, instead of just one section.