Tagged: programming

funcjure

funcjureI’ll soon be starting a new permanent job, and in preparation I’m making it clear what is my prior intellectual property. In this case, it’s not so I can make “oodles of money” in the future, but it’s actually so I can release it as Open Source.

So what I’ll be explaining here is not something I’ve finished, but an idea which I’ve actually been playing around with for a year or so, but never gotten around to fully implementing. This will also help bring together my thinking on this and hopefully inspire me to really get going on this project :-)

 

What is funcjure?

funcjure is a “functional syntax wrapper” around Clojure. What do I mean by that? Well, Clojure is a great language, especially if you’re either used to or prepared to adapt to prefix notation. ie instead of typing 1+1, you type (+ 1 1) which although relatively easy to understand, can get a bit harder as things get more complex, like 9+5*7/4+62/6 which would translate as (+ 9 (*5 7) (/ 62 6) etc…

The logical question is Why? (do I have to type prefix notation) The Clojure and Lisp people will say “well, that’s the way it is, so just get used to it”, which I’m fine with as I wrote my first Lisp program over 3 decades go. Even still, I would prefer to use infix notation (which is what we’re taught for maths) and see no reason why we shouldn’t as computers are great at doing the sort of rote translation required to convert infix to prefix notations.

Clojure is a great language, which also has a fantastic ecosystem and community, and is written in Java which has a HUGE ecosystem. Furthermore, Clojure can call Java code, which has helped tremendously by giving Clojure “out of the box” access to so many libraries and products. Finally, because Clojure is a Lisp, its strong point is Symbolic Manipulation which is exactly what is required for translating infix to prefix structures in order to implement funcjure!

What would this look like? Let’s take some typical Clojure and then show what it would look like in funcjure:

"Hello World!"            ; Minimal "Hello World!"
; "Hello World!"

(println "Hello World!" ) ; Standard "Hello World!"
; println("Hello World!)
; Clojure((println "Hello World")) ; Execute some Clojure code
(def a "test")            ; Define a variable
; a="test"

(def mylist '(1 2 4 5 6)) ; Define a variable list
; mylist='(1 2 3 4 5 6)

(println a mylist)        ; Print our variables
; println(a mylist)

(first (rest '(1 2 3 )))  ; Get the 2nd element of the list
; first(rest('(1 2 3)))

(.println System/out "Hello World from Java!")
; System.out.println("Hello World from Java!")
; or Java(System.out.println("Hello World from Java!"))

(defn factorial           ; Now let's do the classic Factorial function
  ([n]                    ; when only one argument is passed in
    (factorial n 1))
  ([n acc]                ; when two arguments are passed in, with recursion
    (if  (= n 0)  acc
    (recur (dec n) (* acc n)))))
(factorial 6)             ; And test it
; factorial(n) = factorial(n 1)
; factorial(n, acc) = if((n==0), acc, recur(dec(n), n*acc))
; factorial(6)

The overall purpose is to make code much more accessible and ‘natural’ to write as we’re essentially taught infix notation as our “second language” when we study even the most basic mathematics. None of this is really new – in the beginning, things look like our old friend BASIC, with direct assignment and loose typing, which easily map to Clojure. You’ll also notice that access to Clojure and Java is provided by the respective functions. Speaking of functions, these are written similar to Prolog and other languages (eg Erlang) which allow for “pattern matching” in function definitions. In the beginning, the capabilities would be mapped directly to Clojure (as shown above), but eventually it would be nice to go to a full Prolog style, so the factorial function could be written like

factorial(0) = 1                ; The base termination case
factorial(n) = n*factorial(n-1) ; Iteration by recursion

which I think is way more elegant.

That’s about it for this post, as this really contains the base concepts for what I’d like to do. There’s obviously a lot more scope and subtlety to this, some of which I’m aware of and probably a lot more which I’m not, but I personally would much prefer to use a language like this and have access to Clojure and Java when needed for efficiency or easy code porting.

What do you think? All comments / suggestions / critiques would be gratefully accepted as I haven’t really done much more work than this, other than having a 1/2 working translator for this syntax which I’m going to (hopefully) get to work on in the next few weeks before I start my job.

Advertisements

Free “Mathematica”* in the Wolfram Cloud

Wolfram CloudMy history with Mathematica goes back about 20 years, when I was doing Masters research and using Mathematica for both programming and visualisation.

One problem was that it was expensive unless you could justify it. Also, there were no free or “community” editions available…

Well, THAT’S ALL CHANGED NOW!

Almost a week ago, Stephen Wolfram announced the Wolfram Programming Cloud, which as you can see from the image below is extremely powerful – try doing that in a programming language…

MySurface3DMy SurfaceYep, Mathematica just integrated for two variables and then just assigned that to MySurface which represents that expression and plotted it in 3D

“Ah…”, I hear you say, “that’s just some fancy trickery with a good library, but it’s not real programming”. Well, that’s kind of right, except for the fact that Mathematica has a huge range of such libraries, spanning across most disciplines: Applied Mathematics, Arts and Humanities, Business and Economics, Education, Engineering, Information Science and Technology, Mathematica Technology, Mathematics, Science and Social Science.

Also, those two lines above are written in the language for Mathematica which is now called Wolfram that is a “symbolic, functional, and rule-based multi-paradigm programming language“. Pure language wise, it’s pretty hard to match.

It’s fully functional, being able to pass around functions to functions in whatever way you want, like above. But it doesn’t stop there as you can do conventional procedural programming:

For[i=0,i<4,i++,Print[i]]
0
1
2
3

or, rule and pattern- based programming:

rule = {a_, b_} :> {b, a}
{1, 3} /. rule
{3, 1}

and purely functional programming like this classic fibbonaci example:

f[1]=1;  f[2]=1;
f[n_] := f[n-1]+f[n-2] // Define Fibbonaci Function
f /@ Range[10]       // Now get the first 10
{1,1,2,3,5,8,13,21,34,55}

So that’s pretty much all of the major programming paradigms covered! Also, with all the talk about REPL’s these days, Mathematica has had one since it’s inception, except it’s not the REPL you’re used to. Apart from the normal ASCII behaviour, it can typeset and edit equations along with displaying graphics and widgets making it more of a SupeREPL.

Mathematica REPLI’ve not even scratched the surface here in order to keep the examples short and understandable, but you can easily find more by searching for “Mathematica programming example” or “Wolfram programming example“. Or, if you just want to see what it’s capable of doing or just get some inspiration, check out the Wolfram Language Code Gallery.

Interested? Then just head on over to the Wolfram Programming Cloud https://programming.wolframcloud.com/app/ and get started with the free version which is more than adequate to work out if you should upgrade to add extra options like an offline desktop version or even the mighty Mathematica itself.

Oh, and one last thing…

The Wolfram Cloud works on an iPad!

Yes, our (some very geeky people & me :) dream of being able to do complex computation and programming on the iPad is here – as long as you’re connected… Hopefully it won’t be that long before an offline “iPad Desktop” version comes out :-)


* Technically, the whole of Mathematica is not all in this product yet, but it seems quite a bit is and hopefully it will only be a matter of time before the whole thing is

100th Post!

100th Blog PostI’m not the most prolific of bloggers, but after that first post on the 30th June 2012 “Hello world! Of Architecture and Change” this is now the 100th post – WOOHOO! As you can see above, I had a fairly modest celebration with a few Grenadier mates  – thanks guys ;-)

As with any Base-10 based moment, I think it’s time for a bit of reflection and cogitation… What better place to start than the “mission statement” from that first post:

If you’re interested in IT, Privacy, Science, Maths, Process, Systems
(of people and technical), Programming, Organisations and any other
topics that grab my attention, then you may want to follow this.

So how did I score?

The inevitable question is where now? Firstly, I think it’s time for a renewed mission statement:

To boldly go, where I've not gone before
To seek out new ways of being, living, thinking and working
To explore seemingly strange new worlds and ideas of other people
These are the voyages of me...
In physical, virtual, emotional & mental space: The final frontiers

Enterprise - NCC1701But a bit more specifically, what are my thoughts and plans for the future?

  • I like blogging about “anything”. I know this may be frustrating for some who very much stay on a particular “message topic”, as one day I’m talking about a product, another some programming, people or an organisation type. Well, that’s just me so I won’t change that…
  • I do want to increase the “technical content”, by which I mean around Architecture, Design and Programming. I got drawn down a people and process rabbit hole, which in some ways culminated with previous post on Toxic Waterfall. I’ll still blog in this area, but have a lot of technical ideas I want to explore and talk about along the way
  • I think topics like Maths, Science, Privacy and the like are probably better covered on Twitter, which I’ll be getting back on to next year after I’ve returned from a well earned break in Australia

Sam-TaegeukOr put more simply, I’ll probably stick with The Classics of Transformation:

  • People (& Organisations)
  • Process (with People and Organisations)
  • Technology (to implement Processes for People in Organisations)

but most importantly in a humane context

The RiczWest Weekly Magazine

FlipboardIconI’m always playing around with various curation mechanisms – there was (and kind of still is) the DailyRiczWest, but I still haven’t got that fully automated and as I’m not using Twitter at the moment it’s fallen by the wayside a bit. I am still browsing though, using Flipboard and wanted an alternative for curating content that I found. I’d had a look at Flipboard magazines when they came out but dropped them as soon as I figured out there was no way to share them with other people who don’t have it.

The GOOD NEWS? You can now share your Flipboard Magazines with people that don’t have it!!!

The process is so easy – when you’ve created a magazine, just go to it and tap “Share” then “Copy Link”, which you can then use in emails, web pages etc… I just created a static page, My Flipboard Magazines, which just contains static links to the 6 different magazines I have on the subjects of:

  • Hardware: Gizmos & Geekery
  • Programming: Interesting articles, mostly on Clojure
  • News: Interesting news mostly in the areas of IT, Technology & Science
  • Miscellanea: Various things that can’t be categorised :-)
  • Reference: Articles and Reverences
  • Favourites: Things that are interesting to me, but I don’t tweet

which I’ll then just tweet a link to every week using If This Then That. Not ideal, but another mechanism for curation.

It would certainly be better in the long term to also collate those ‘Flips’ (in to the magazines) in to a text file like I do with the DailyRiczWest, which is something I’m looking at currently and will blog about if I figure it out. If anyone knows how to do this already (using IFTTT or another mechanism) then please let me know or add a comment.

Is Java the new C?

JavaLogoI started programming in Java a few years after it was released. I had been doing C++ for a number of years and just come off a C++ project which failed because they (who were a pretty good team of programmers) couldn’t scale it because of the two common killers: Threads and Memory Management. Near the end I was reading James Gosling’s original paper on Java which addresses the major problems of C++ and explaining how Java addressed them. I was obviously quickly sold! As a result I spent over a decade programming in Java and J(2)EE, in the beginning implementing (mostly web) projects way faster than the “C++ laggards” could.

Now, I’ve been doing Solution and SOA Architecture, occasionally whipping up a prototype in Java, or doing some Perl but quite often working with WSDL, XSD’s and just plain models. Recently though, I’ve been playing around with Clojure in my own time and am amazed at how much fun it is. It really reminds me about my early experiences with Java, but that would be the subject of another blog post…

Recently it has struck me just how many languages have versions or been constructed to run on the Java JVM. A list from Wikipedia shows:

Java LanguagesThat’s quite a few languages! What’s more, a number of them have plugins to an IDEs such as IntelliJ or more commonly eclipse. It struck me that these languages were effectively using Java and often IDE’s as a runtime / development platform, much like many high level languages used C.

Which begs the question – where is Java headed in the long-term? Yes, they’re adding Lamda’s in Java 8, but why would I want that when I can work with Clojure which has had this from the beginning and has a whole bunch of good extra stuff… Is it destined to become a “low level language and environment” upon which more sophisticated languages will be built?

The Future of Programming – hint: it’s not a new IDE!

So as I’ve been tweeting a bit, there was a #RasPiThon this weekend. For me, it was at first a bit of a curiosity as I’ve got one and wondered what it was all about. The bit that got me totally hooked though, was the interactivity of it all – both between the coders (of which there were about 4 – find out more about them at Raspithon – 48 hours of Python) and their “audience” (in the chat window). And the fact that it was “just” a bunch of kids between 12 and 16! When you here about something like this, you assume it’s at least a bunch of 20-somethings or maybe even some “old codgers” like me getting together… Then it hit me! In 5-10 years, these “kids” will be the programmers working on systems I’ll be architecting – how cool!

Raspberry Pi o ThonIt struck me as quite funny that so many in the “Agile community” and many other people are debating about pair programming… Strangely enough, these kids haven’t been listening to that or going to “the right conferences” and taken it to the next level of what @JenniferSertl calls “social coding”. How spot on!

Imagine this in a corporation, with a live stream of the developers, chatting by voice, then the “product owners” chatting in a window (you have to limit their bandwidth somehow ;) seeing the software develop in real time! Getting a bit boring? Go away and come back later…

Oh – and how do you get the code? That’s on GitHub: RasPiThon. OK, so in a corporate context, you’d have a corporate GitHub, but you get the picture – just “corporatise” the toolset they’re using, or maybe not…

Part way through the whole marathon, they were DOS’d – Raspithon continues: live feed undaunted by DDoS attacks – BTW Major -ve Karma to whoever did that. The interesting thing was how “the group” then re-oriented themselves to solve this (it was after all the key part of their “value chain” :), eventually finding another host and updating their DNS record – oh for this sort of swift response in a corporate context… No “website is down” form submissions or SLA’s – they just solved it! Back to the coding then, which did result in a complete game:

If you looked at this whole thing from a process point of view in the context of The Marshall Model, these guys were drifting between Synergistic and Chaordic! And yet again, I bet you they’ve never ready any of Bob’s work (although I suspect they will one day :) It was just natural for them.

So what are the lessons for us to learn? If you want to see the “future”, then just check out what the “kids” are doing… If it freaks you out, you’d better get used to it as they’re coming whether you like it or not :-) As @flowchainsensei and others have tweeted, the end of the “pure manager” is coming, so you’d better get engaged wherever you are and start doing something productive, wrap you’re head around the “social context” which is coming (although that’s probably redundant if you’re reading this) as what we are seeing in activities like this really is the “target process state” of things.

I’ll leave the last word however to lozlesndstuff (who you’ll probably work with one day), that I think indicates what this (and RaspberryPi) was really all about:

    lozlesndstuff: This is awesome, inspired me to learn more about coding