Technical Difficulties from on Top of the Mountain
  Learning a new language
As part of expanding my horizons, I've been meaning to work on learning a new language. At first it was going to be Ruby, which is supposedly an object-oriented scripting language kind of like perl and python; but there was never any push for me get started and I kept running across weirdnesses like indent dependent syntax and notes about how they were going to tear everything apart and re-do it because they had learned better.

At the pilot for the Masters of Fine Arts in Software, I was once again motivated to get off my duff and get back into the trenches with a new language, and several others were very heavily into Ruby, so I thought I might go that way until Richard made a pitch for Lisp (which I wasn't that interested in) and CLOS. CLOS is Common Lisp Object System, and it sounded really powerful, so I went away thinking that maybe I should find out more about CLOS.

After searching far and wide, what I found was a bunch of different LISP dialects, and notes about each one like: "A really good implementation, but not very stable." or "looks promising, but couldn't get it to install." which led me to realize that there was almost no way I was going to be able to find a usable Lisp and get started with it without some help (which I didn't have). I also found a great series of articles by Paul Graham, describing what Lisp was and wasn't supposed to be, where its power was, and how the Lisp community had shot itself in the foot and destined itself for obscurity.

While Lisp has a number of great features (like memory management and runtime binding), what everyone was enthralled with was the fact that it has no syntax, and instead is written as expressions, which are parsed into lists, and then can be manipulated at runtime. Lisp's most powerful feature is its macro system (and the fact that the macros can act on themselves), so its really easy to create your own language--in fact the Lisp community is continually re-fracturing itself into thousands of splinter groups, so that its almost impossible to share any progress. This is a disease the smalltalk community seems to have as well, only they're not continually redefining the language, its just their environment that diverges and the fact that they don't have source files.

I've plowed into C++ templates enough to realize how having a separate limited language for macros is a shortcoming, but I was going to wait on the Lisp side of things to see if someone could cook up something resembling a syntax, and the ability to do useful things (like make system calls and communicate with other programs).

Then, Don Park dropped another one of this techno gadget bombs: Lua. Lua is a scripting language designed to be light, fast, and easily bound to great things like C & C++.

I did a quick background check on it and found this one article which described a set of speed tests between MzScheme (a lisp like thing), Ruby, Python on Lua. The author was hoping that MzScheme was the fastest, but it wasn't, though it made a respectable showing. The results were: Lua was always the fastest by quite a bit, MzScheme and Python switched for second and third, and Ruby was always last by a mile.

That pretty much sold it.

So I downloaded some Lua stuff and got started. So far I haven't scratched the surface very far. Tables are a builtin in Lua, though it does some weird stuff and lets you use them as lists too (basically using ints as keys from 1..n). One thing that is interesting, is that you can do multiple assignments, sort of like in perl:

a,b=1,2 ;
val1, val2 = val2, val1 ;  -- swap two vars without a temp
And also like perl, they tried to be clever with AND and OR. Now in perl you can do cool stuff like indx1= getindex() || 1 ; so that if getindex() came back with 0, you could assign it a different value. Unfortunately if 0 was a valid number you had to write out the test for undef the long way. Perl 6 adds indx1= getindex() |& 1 ; which will only return 1 if getindex() returns undef. Perl of course also lets you do things to existing variables, so in perl 6 you'll be able to say: indx1 |&= 1; which is amazing compact and somewhat oblique to novices. But trust me, its cool, and I'd have used it all over the place if it was in perl 5.

Unfortunately Lua does not have increment, or the common C shortcut: a += 1 ; which I am really scratching my head about, but it does have some pass through on OR and AND. OR is of course supposed to be like ||, but I had never seen anyone try and do a passthrough in perl with &&, so I was kind of scratching my head about what it was for till I got to the end of the section on expressions where they explained that they tried to implement the a= expr ? val1 : val2 syntax from C. Basically, its supposed to work like this:

finalval= expr AND val1 OR val2.
Unfortunately, if val1 is false or nil then it doesn't actually work, so you can say the ternary C operator is partially supported; which is to say if you use this in your code and you know what you're doing it might work.

So far my impression is that the syntax could use some cleanup, the tables are neat (though perl has tables too), and I'm still waiting to find the silver bullet. But I'll keep plugging away at it for now.

Comments: Post a Comment

<< Home
Life in the middle of nowhere, remote programming to try and support it, startups, children, and some tinkering when I get a chance.

January 2004 / February 2004 / March 2004 / April 2004 / May 2004 / June 2004 / July 2004 / August 2004 / September 2004 / October 2004 / November 2004 / December 2004 / January 2005 / February 2005 / March 2005 / April 2005 / May 2005 / June 2005 / July 2005 / August 2005 / September 2005 / October 2005 / November 2005 / December 2005 / January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / February 2007 / March 2007 / April 2007 / June 2007 / July 2007 / August 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / May 2008 / June 2008 / August 2008 / February 2009 / August 2009 / February 2010 / February 2011 / March 2011 / October 2011 / March 2012 / July 2013 / August 2013 / September 2013 / October 2013 / November 2013 / December 2013 / December 2014 / February 2015 / March 2015 / July 2016 / September 2016 / December 2016 / April 2017 / June 2017 / July 2018 /

Paul Graham's Essays
You may not want to write in Lisp, but his advise on software, life and business is always worth listening to.
How to save the world
Dave Pollard working on changing the world .. one partially baked idea at a time.
Eric Snowdeal IV - born 15 weeks too soon, now living a normal baby life.
Land and Hold Short
The life of a pilot.

The best of?
Jan '04
The second best villain of all times.

Feb '04
Oops I dropped by satellite.
New Jets create excitement in the air.
The audience is not listening.

Mar '04
Neat chemicals you don't want to mess with.
The Lack of Practise Effect

Apr '04
Scramjets take to the air
Doing dangerous things in the fire.
The Real Way to get a job

May '04
Checking out cool tools (with the kids)
A master geek (Ink Tank flashback)
How to play with your kids

Powered by Blogger