DelayedLauncher 2.0

February 9, 2014: Delayed Launcher is now Open Source Software!

DelayedLauncher 2.0

And you thought I’d abandoned it. πŸ˜›

DelayedLauncher turned out to be more popular than I expected it to be.

Originally released as a solution to a problem in the 1.x series of Espionage, DelayedLauncher turned out to be useful for many people as a way of speeding up their system’s login time.

After receiving enough emails asking for the ability to specify delays for each of the items, it is finally here, DelayedLauncher 2.0, and yes, it’s still completely free. πŸ™‚


Requirements: Mac OS X 10.4+

P.S. If you’d like to contribute an icon for it, just contact us. I think a rocket with a wrist-watch strapped around it would suit it nicely.

Update: Version 2.2 fixes bugs and has a new icon!

Espionage 2.6 + New Video

Espionage 2.6 has arrived, and here’s the full list of changes:

  • NEW: Redesigned and improved password prompts
  • NEW: “Lock Folder” contextual item is back for 10.6 (*Only visible after restart!*)
  • NEW: Daylite application template
  • NEW: Added Rocketbox support to Mail application template
  • IMPROVED: Behavior when registering with improperly named license
  • IMPROVED: Relationship with the TEDiagnosticTool
  • IMPROVED: Added informative dialog for Dropbox
  • IMPROVED: Improved documentation on restoration from recovered disk images
  • IMPROVED: Clarity in how to restore from backups
  • IMPROVED: Reordered folder verification code to check for applications first
  • IMPROVED: The informative alert upon first encryption
  • IMPROVED: Added an additional check to prevent encryption of folders within folders
  • CHANGED: Default Minimum Image Capacity (MIC) to 10GB
  • FIXED: Incorrect backup interval for hourly backup times
  • FIXED: Hang that could occur during uninstallation if folders or disk images were missing
  • IMPROVED (2.6.1): Updated RBSplitView to 1.2
  • IMPROVED (2.6.1): Updated BWToolkit to 1.2.5
  • FIXED (2.6.1): Issue where LCC version could be incorrectly detected preventing Espionage from running

Overview of Significant Changes

Smarter Prompts

The new prompts are sleeker and have a timer on them to auto-deny the request after 60 seconds. Through the new action popup list it should now also be much clearer how an application can be added to the ignore list from the prompt itself.

Return of the Contextual Menu Item!

The “Lock” contextual menu is back in 10.6! It’s now called “Lock Folder” and rests directly in the root of the contextual menu:

After updating to Espionage 2.6, you must restart your computer before it appears on unlocked encrypted folders. Currently, this item will not appear on unlocked non-encrypted folders, though this may change in the future.

TrialPay – Get Espionage Free!

We’ve added TrialPay as a payment option to our new order page, which means you can get Espionage free by completing an affiliate offer.

New Screencast!

There’s a brand new awesome screencast on the homepage… check it out! πŸ™‚

Easy Cocoa Setup Assistants with TESetupAssistant

Setup assistants can be a great tool when you need to guide users through a series of steps.

TESetupAssistant was born during my work on the 2.0 update to Espionage, when I discovered that many of its UI elements could stand to benefit from a generic setup assistant class.

The gallery below shows some of the places in Espionage where we use TESetupAssisant, illustrating its versatility:

You can create these sorts of UIs very quickly and use them wherever the user needs to complete a series of steps, or even a single step (as shown in the first image above). Here’s a basic overview of it:

There are two main classes: TESetupAssistant and TEBaseAssistant. TESetupAssistant is associated with a nib file that determines the overall layout. It manages a one or more assistants, each of which inherit from TEBaseAssistant. Each TEBaseAssistant subclass has its own nib file, usually just containing a single NSView container object.

Example of a Modal Assistant

Here’s an example of a very simple assistant using the minified UI and running modally:

And here is all the code needed to create it:

#import <Cocoa/Cocoa.h>
#import "TESetupAssistant.h"

@interface MiniAssistant : TEBaseAssistant {
    IBOutlet NSTextField *textField;
}
@end

@implementation MiniAssistant
- (NSArray *)orderedSteps
{
    return [NSArray arrayWithObject:@"Mini Step"];
}
- (void)start
{
    [[controller nextButton] setTitle:@"Finish"];
    [textField setStringValue:NSSTR_FMT(
        "Hi there! I'm a mini-assistant %srunning modally!",
        [controller modal] ? "" : "not ")
    ];
}
@end

// To run it modally is just 4 lines of code (somewhere):

TESetupAssistant *sa = [[[TESetupAssistant alloc] initMini] autorelease];
[sa setModal:YES];
[sa addAssistant:[MiniAssistant assistant]];
[sa run];

Notice that we don’t even need to load the nib file. That’s because our nib file is named after our assitant (MiniAssistant.nib). You can of course override the -assistantNib method to specify a different one, but that illustrates one key aspect of TESetupAssistant, and that is that there are sensible defaults for almost everything, allowing you to quickly throw together these kinds of interfaces.

Get It On Github

I’m releasing TESetupAssistant as open source under a liberal license (just an attribution is asked for), and I’ve included a little demo app to help you hit the ground running. You can download it on github.

If you use it in your application I’d love to know! Shoot us an email or post a comment below and I’ll place a link here to your app.

Enjoy! πŸ™‚

You can follow me on twitter here.

How Secure Is Your iPad?

Apple’s iPad may turn out to be more of a security risk than a useful tool for some, especially for those who, prior to yesterday’s launch, speculated that the iPad would be a God-send to the health care system, and possibly other sectors like businesses.

According to Steve, however, the iPad is designed primarily for the following activities:

For some, even that may be something of a stretch.

As many have pointed out, the iPad is more of an oversized iPod Touch than an undersized MacBook Air, or as Daniel Tenner so aptly put it: “The uncomputer for the masses”.

When you send someone an email, you expect it to fall into the hands of its intended recipient, not someone who happened to get a hold of their device. I would never download all of my email onto an iPad because I can neither encrypt nor password protected it. Apple’s lockdown of the OS means third-party developers cannot intervene and remedy this situation because they’re not allowed to touch certain parts of the system.

Businesses and hospitals won’t be thrilled with employees and nurses running around with an easily swipeable device containing unprotected company secrets, client data, and patient information. Thanks to the “duplicating functionality” clause of the SDK TOS, developers can’t even write their own encrypted versions of Mail or the iWork suite.

If you want a secure iPad, you’ll either have to hope Apple implements it, or depend on each individual developer to properly secure their application’s data—a situation that nobody should be thrilled with.

How newLISP Took My Breath (And Syntax) Away

Translations: δΈ­ζ–‡

A few years ago, a little-known language called newLISP completely changed my understanding of what “good” programming languages look like.

Why newLISP?

Before saying another word, I’d like to address the question that some of my LISP-familiar readers may be asking right now: Why newLISP? Why not Clojure, Scheme, or Common LISP?

The answer is that after evaluating these dialects of LISP, I’ve come to the conclusion that newLISP has several important advantages over other LISPs.

Today, unfortunately, whenever someone mentions newLISP on an online forum frequented by adherents of another LISP, an almost clan-like flame war will erupt. An adherent of one particular dialect, usually someone who has never used newLISP, will shout obscenities such as, “newLISP goes back on just about every advancement made by LISPs”, or “dynamic scope is evil!”

The historical context out of which these sentiments are born is mostly unknown to those observing the debate. As signal gives way to noise, the discussion collapses, the melee disperses, and the bystanders go back to sipping their Java and eating their Pythons.

It is fortunate, I think, that my introduction to the language did not sprout out of one of these battles. It was, for the most part, largely unbiased.

Something called LISP

While attending the University of Florida, I had signed up for a course on artificial intelligence. Our professor predictably introduced the class to a programming language called LISP.

Up to that point in time my knowledge of LISP consisted of the usual hearsay and mantra of those unfamiliar with the language:

“People who like it are crazy zealots who think they’re superior to everyone!”
“It’s mainly used for artificial intelligence stuff.”
“No one uses it for practical purposes.”
“It’s mainly used as a research language.”
“It stands for ‘Lots-of-Irritating-Silly-Parenthesis’. Haha!”

You get the idea. I did not have a clue as to what it was, but I was excited to finally be forced into the position of having to find out. My grade depended on it, after all.

What I discovered was that LISP did in fact live up to its reputation of zealot-inducing awesomeness. Simply being exposed to some of the basic concepts and philosophies of LISP had an immediate and positive impact on my abilities as a programmer.

Syntax: Programmer Enemy #1

LISP’s relative lack of syntax was perhaps the greatest insight, for I immediately felt as though a great weight had disappeared. I realized that it was syntax that was at the root of most programming errors. It was syntax that created a subconscious burden that I had simply been unaware of; causing errors, bugs, and making it difficult to simply turn my thoughts into code. Despite having many years of experience with C-based languages, and being intimately familiar with their syntax, I realized that it was nevertheless a totally unnecessary burden that was slowing me, and everyone else, down.

This is one great advantage of Lisp-like languages: They have very few ways of forming compound expressions, and almost no syntactic structure. . . . After a short time we forget about syntactic details of the language (because there are none) and get on with the real issues.

—Abelson and Sussman

It’s not just the size of the syntax that matters, it’s what you can do with it. What requires layers of special syntax in languages like PHP, Python and Ruby, LISP can do with its basic concepts of lists, functions and symbols. It can do everything those languages can do, in a more elegant fashion, and still have enough tricks left up its sleeve to accomplish feats that are simply not possible in other languages.

Common LISP: A Series of Unfortunate Mistakes

Despite all of these exciting discoveries I still had an uneasy feeling.

Common LISP (CL) was a great departure from what I had known previously, but it reeked of antiquity, and worse, its syntax simply wasn’t very well thought out. The “Zen-like” perfection that it seemed to be yearning for was missing. It was a feeling that Mac users are all too familiar with: There were too many buttons, and most of them were unnecessary.

Common LISP Syntax in a Nutshell

Compared to C++, that’s fantastic. Then again, compared to C++, most languages appear favorable. Having had a taste of the liberty offered by the drop in syntax from C/C++/Java to CL, I did not see why all of this syntax was necessary, and indeed, most of it wasn’t.

Every little piece of syntax that’s introduced into a language adds to the programmer’s mental burden, be he conscious of it or not. I was not prepared to spend the effort learning Common LISP if a better alternative could be found.

What do you mean by “syntax”?

You may object at my inclusion of the functions defvar, =, eq, eql, etc. as they are functions. I include them because they constitute low-level functionality that cannot be expressed in the syntax of LISP itself. In other words, the functions = and eq are low-level primitives that must be defined in the language that LISP itself is implemented in, and their meaning and usage cannot be deduced from any other existing LISP syntax.

Consider PHP’s != and !==, they are both operators and are used in the same way, yet that doesn’t tell you anything about what the difference between them is. There’s no way to deduce their meaning from the existing semantics of the language and thus they each represent new syntax that must be learned.

How I Discovered newLISP

The professor revealed to us our “major class project”: we were to implement a text-based version of the game Chainshot:

Chainshot

An implementation of Chainshot

Chainshot starts with a grid completely filled with colored cells. Your goal is to clear the board and you do this by clicking on each cell. If the cell has any adjacent cells of the same color, they all disappear. The effect spreads to include all of the cells adjacent to those, and so on. Cells then drop down to fill in the gap left by the vanished group. If an entire column disappears then all cells to the right of it move left to fill it in. There’s a wonderful and free implementation of this for OS X called Otis.

For the midterm we were to make a version of this playable by a human, and for the final we had to write an AI to play the game.

“One more thing…” he said, “If you do it in LISP, you’ll get a 10% bonus.”

The problem though was most of the lectures focused on various algorithms and theory for doing AI. Those who wanted the 10% bonus would have to teach themselves the language.

Most students chose to forsake the bonus in favor of using a language that they were already familiar with, and like most students I had very little time, so I was partial to that sentiment. However, I decided to do a Google search to see if I could find a Common LISP alternative that was more appetizing.

To my delight I found a language that seemed to check all the right boxes, and surprisingly it wasn’t Scheme (although that is a wonderful language as well). Like Scheme, this language had greatly simplified Common LISP’s syntax, but at the same time it came with a standard library full of useful functions for performing modern scripting tasks, and all you needed to run it was a single tiny executable!

Discovering newLISP

newLISPHere is what ultimately turned me into such a fan of newLISP.

We had several months to complete the first part of the project, and the night before it was due, I did not have a single part of it complete. I had spent the night working on other things, and for perhaps an hour I spent some time looking over the newLISP website, reading about it.

The next day, approximately four hours before I was to hand in my finished, playable version of Chainshot, I sat down at a desk, put on my headphones, and proceeded to simultaneously learn newLISP while creating this game with it.

I finished in about 3 hours, of which only about ten minutes was spent debugging. I was dumbfounded. I had discovered something new, a language that allowed me to rapidly write what, after years of C-based languages, seemed like virtually “bug-free code” that just worked. It was a language that I had come close to mastering in a matter of minutes, having never used it before! In the time I had learned newLISP and written a text-based game in it I would probably only be finishing the tutorials for Ruby or Python.

newLISP’s Strengths

At the beginning of this post I made the claim that newLISP has several advantages over the other LISPs. They can all be summarized as follows: If you want a LISP-based scripting language, choose newLISP.

Before getting into the details let me warn:

newLISP is not a general-purpose programming language.

In the same sense that you wouldn’t use JavaScript to write an iPhone app (some beg to differ), you wouldn’t use use newLISP to write an operating system, a music player like iTunes, or a web browser like Firefox. For such endeavors I recommend without hesitation Clojure, Scheme, C, Objective-C, etc. In other words, languages geared for solving complex, low-level problems, as quickly as possible.

The very first sentence on newLISP’s website states (emphasis mine):

newLISP is a Lisp-like, general-purpose scripting language.

Long ago, when computers were slow, the LISP community was mercilessly mocked by their C and Assembly-wielding counterparts for the crime of being too slow. Ever since that time the subject of performance has been a sore spot for the LISP community from which, I dare say, it has yet to fully recover. Its focus turned towards compilation and proving to the world that it too, could be fast. As a result, few seem to have noticed the need for a general-purpose LISP focused instead on interpretation and scripting.

Luckily, newLISP seems to fit that role rather well. It is a general-purpose interpreted scripting language. It’s my understanding that because of how dynamic it is, it cannot even be compiled to bytecode (this does not mean it is not fast, though).

Without this understanding, some of its design decisions will not make sense. Why choose fexprs over macros? Why dynamic scope instead of lexical scope? Why One-Reference-Only memory management instead of garbage collection?

Design and Syntax

newLISP comes in a single, tiny 200+KB binary executable. Out of all the LISP derivatives I’ve tried, it is the easiest to setup, deploy, and develop for. Somehow that tiny package contains the entire language and includes functions for reading and writing files, parsing text, regular expressions, running code in parallel, over a network, and much more. For the final project I was the only person in the class to submit a fully parallelizable AI (scalable to any number of cores) to solve each grid. The only reason I did it was because I could do it without breaking a sweat. newLISP made it mind-numbingly easy, and this was before it had all the actor and Cilk stuff.

newLISP’s syntax is minimalist and well thought out. For the sake of comparison with the Common LISP syntax card, I’ve kept most of the attributes (such as font size) the same:

newLISP in a nutshell

Functions do not need any of the &rest, &optional flags. Simply pass in variables or don’t, the parameters that don’t get anything are set to nil, and extra stuff can be accessed through the function (args) or the symbol $args.

Functions, like most other things, evaluate to themselves. You don’t need a special #’ syntax to access them. Functions are also real lists. This means you can get their source after they’ve been defined, and even modify them while they are executing.

fexprs and eval

Instead of macros newLISP chose to use fexprs, or functions that simply don’t evaluate their arguments (although to the chagrin of some, newLISP calls them macros). This decision makes sense because in an interpreted LISP, almost everything happens at runtime and there are situations where fexprs can be much faster to execute than macros. It also means that newLISP’s “macros” don’t need the special backquote syntax, making them easier to write and read.

You may have heard the mantra against using eval in other languages. In newLISP, this just doesn’t apply. newLISP’s eval is faster than other LISPs.

This has many consequences, one of which is that sometimes newLISP’s fexprs can be faster than compiled macros in the other LISPs, but also it means that using eval is no longer frowned upon, which opens up all sorts of coding possibilities.

Equality and Memory Management

Notice that there’s a single equality operator, the equals sign. newLISP can get away with this luxury because of its memory-management model, called One-Reference-Only (ORO).

In short, most things are passed by-value and so you end up not needing all of those ridiculous comparison functions. If two things have the same value they are equal—end of story (except in the case of Objective newLISP).

This is not as crazy as it sounds. Internally, newLISP passes data by reference between built-in functions and does other optimizations. You can pass data by reference through the use of contexts and symbols, or by using Objective newLISP. newLISP’s ORO also means repeatable code execution times; you’ll never experience “GC Hell” because there is no garbage collector.

Dynamic Scope

Much fuss is often made over newLISP’s use of dynamic scope. It is true, dynamic scope can be dangerous!

In a similar way, pointers and alcohol can be dangerous too! That doesn’t mean you shouldn’t ever program in C or enjoy yourself at a party. Check for NULL, don’t drink and drive, and beware of “free variables.”

Remember, newLISP is an interpreted language. Lutz Mueller, the author of newLISP, made a simple cost/benefit analysis and chose dynamic scope because it’s faster than lexical scope, and because it’s very easy to avoid the potential pitfalls of dynamic scope. Instead of this:

(define (my-unsafe-func)
    (println my-var)
)

Do this:

(define (my-safe-func my-var)
    (println my-var)
)

It’s a small price to pay for the performance improvement, and oftentimes it’s actually quite handy to have dynamic scope (especially in combination with the no-longer taboo eval). If you need lexical scope though, newLISP has you covered.

Parallel Processing

newLISP takes an interesting approach for running code in parallel. Whereas Clojure uses advanced methods for multi-threading and ensuring safety, newLISP simply uses its small size and lets the Operating System do all the work!

There are no threads. Writing safe, parallel code is simple through actors and spawn/sync because newLISP simply forks itself. Its modest stature makes this a fairly cheap operation, allowing the OS to handle scheduling and memory-protection. Try forking a JVM… πŸ˜›

Excellent Documentation and Community

newLISP’s documentation is one of the best examples of excellent documentation that I’ve ever seen, simply surpassing the documentation for any other LISP that I’m aware of. You don’t need to shell out money for a book to learn it, and that’s because it doesn’t need a book! The short manual included with the reference documentation is all you’ll need to learn the language. Its documentation is one of the primary reasons that I was able to successfully procrastinate for my midterm.

If I had to pick a word to describe newLISP’s community it would probably be “cozy” (and for Common LISP it would probably be “abrasive”). Everyone’s question is heard and answered in a friendly and rapid manner, and there is no formality. Lutz Mueller will often answer your question or incorporate your suggestions directly into the language. It’s a small community, yes, but it’s also agile and capable of rapid change without politics.

Other Goodies

There are many other goodies that I won’t dwell on:

Conclusion + Related Links

newLISP is a true diamond in the rough, sorely under-hyped, but a thing of beauty nevertheless.

If you found this post interesting, you may find some of the links below worth visiting:

Using Espionage with Dropbox

We received an excellent tip from Ira Rainey of side lane digital development on a simple method of using Espionage with Dropbox.

espionage + dropbox

The method does not involve storing Espionage’d folders inside of Dropbox (which can lead to issues), but rather using Espionage to easily and conveniently encrypt all of the files from your Dropbox on your Mac.

Step 1 – Create a folder called ‘Vault’ in your Home folder

Create a folder called 'Vault'

Step 2 – Add ‘Vault’ to Espionage

Encrypt the Vault folder + Associate with Dropbox

Step 3 – Associate Dropbox & Check ‘Launch At Login’

Set Dropbox to launch at login

  1. Select ‘Vault’ in Espionage
  2. Click the ‘Edit Application Associations’ button
  3. Drop Dropbox onto the list, or select it after clicking the ‘+’ button
  4. Check the box to ‘Launch at Login’ (click ‘Yes’ if prompted to enable ‘Autounlock at login’)
  5. Click ‘Done’, then click ‘Save Changes’

Step 4 – Unlock the Vault folder

Unlock the Vault folder

Step 5 – Adjust Dropbox’s Preferences

Adjust Dropbox's Preferences

  1. Click the Move… button and select the unlocked Vault folder
  2. Uncheck the “Start Dropbox on System Startup” checkbox

That’s it!

Your Dropbox is now encrypted locally, you can now launch Dropbox (you’ll be prompted for the folder’s password). Dropbox will upload any changes to it securely over the internet, and the files are stored encrypted on their servers.

It’s important to note that if you sync your Dropbox with another Mac the files on that machine won’t be encrypted unless you repeat these steps there as well. We are still investigating whether it’s possible to get Dropbox to play nicely with a live Espionage’d folder that’s inside of it.

Many thanks to Ira Rainey for pointing this out! You can read more information about this tip on his blog.

We’re always interested in hearing about how our users use Espionage, so if you have any interesting tips you’d like to share with us don’t hesitate to let us know! πŸ™‚

Introducing Objective newLISP

newLISP is an awesome language that I use for all of my scripting needs, but one thing that is missing from it is a nice way of doing real object oriented programming.

By default it supports a pseudo-OOP paradigm called FOOP, but FOOP is simply inadequate for doing some of the most rudimentary of OOP tasks, such as allowing objects to hold references to each other.

That is why I’m announcing Objective newLISP: Real Object Oriented Programming for newLISP.

Let’s Dive In

Objective newLISP—ObjNL for short—is modeled after parts of Objective-C and Java. Let’s open up a REPL and begin:

$ newlisp ObjNL.lsp
newLISP v.10.1.6 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.

> 

Classes

Classes are simply contexts and are defined using the function new-class:

> (new-class 'Foo)
Foo

If we wanted to create a subclass of Foo called Bar we can easily do so:

> (new-class 'Bar Foo)
Bar

We can see that Foo is the superclass of Bar:

> Bar:@super
Foo

And that all classes inherit from ObjNL:

> Foo:@super
ObjNL

Objects

Objects are instantiated from classes using the function instantiate. They are contexts too:

> (setf obj (instantiate Foo))
Foo#1

As we’re subverting newLISP’s ORO memory management model to gain real OOP, we should deallocate it manually when we’re through using it. I will cover the topic of memory management last.

Constructors

Constructors are defined using the default function. Let’s define constructors for Foo and Bar (suppose we entered this into the REPL between a pair of [cmd][/cmd] tags):

(context Foo)
(define (Foo:Foo _bar)
    (setf bar _bar)
    true
)

(context Bar)
(define (Bar:Bar _foo)
    (setf foo _foo)
    true ; don't allow ourselves to be deallocated
)
(context MAIN)

Note the extra true at the end of each constructor. This is important because if the constructor returns nil that tells ObjNL that an error occurred and to therefore deallocate the object immediately. Thus if _bar were nil and we didn’t have that true the object would be deallocated, and we don’t want that.

When we call instantiate with extra arguments they are passed to the constructor:

> (setf obj (instantiate Foo (instantiate Bar)))
Foo#2

We can see that the instance variables were properly set:

> obj:bar
Bar#1
> obj:bar:foo

ERR: symbol expected : "obj:bar:foo"

Huh. We were able to check obj:bar but obj:bar:foo resulted in an error. It seems newLISP treats the entire thing as a symbol if there’s more than one colon, instead of assuming we’re doing multiple context lookups.

Thankfully Objective newLISP has you covered.

Deep Value and Symbol Access

> (. obj bar foo)
nil

The dot macro lets us look up the value of a symbol that we want through several object references. I’ll refer to this as “deep value access”. Sometime we want the symbol instead of the value, for example say for fun we want to create a circular reference between the objects obj and obj:bar. We can do this using the dot-reference macro:

> (.& obj bar foo)
Bar#1:foo
> (set (.& obj bar foo) obj)
Foo#2

The dot-reference macro allows for “deep symbol access”, it returns the context-qualified symbol for an object’s instance variable. Now we can show that our circular reference works:

> (. obj bar foo bar foo)
Foo#2
> (= obj (. obj bar foo bar foo))
true

Interfaces

Most object oriented systems have the concept of an interface, sometimes referred to as a protocol. Interfaces define a set of functions that a class can choose to implement or “conform” to. Objective newLISP has them too, and refers to them as interfaces even though they are technically mixins.

Let’s define a simple interface called protocol:

> (define (protocol:test) "hello!")
(lambda () "hello!")

There are two ways to implement an interface. You can specify a list of them when creating a new class:

> (new-class 'Foo ObjNL '(protocol))
Foo

Or you can add them to a class or object after its definition. We actually want to do this right now because we instantiated obj prior to adding protocol to Foo‘s list of interfaces. We can check to see this is true by asking if obj implements protocol:

> (implements? protocol obj)
nil

So the second way to add an interface to an object or class is to use the function add-interface:

> (add-interface protocol obj)
(protocol Foo ObjNL)

Now obj should implement it, so we can try it out:

> (if (implements? protocol obj) (obj:test))
"hello!"

The only real difference between an interface and a class is that a class has a constructor (default function) and ultimately inherits from ObjNL. You can use implements? to check inheritance as well:

> (implements? ObjNL obj)
true

Memory Management

The last, and perhaps most important topic, is what to do with all those objects you’ve got lying around, also referred to as “memory management.”

Objective newLISP supports two styles of memory management: manual and reference counting.

Manual memory management is simple: instantiate your object, and when you’re done with it, deallocate it!

> (setf b (instantiate Bar))
Bar#2
> (deallocate b)
true

Reference counting is done the same way it is done in Objective-C. Each object starts with a reference count of 1. When you want to hold onto that object you retain it, and when you’re through with it you release or autorelease it (which decrements the reference count). When the reference count hits zero the object is deallocated by deallocate:

> (setf b (instantiate Bar))
Bar#3
> (release b)
true

I will cover autorelease next, but I won’t go to great lengths to explain how all of this reference counting stuff works. If you’re unfamiliar with it, just know that it’s not complicated. If you want some practice make an iPhone app. πŸ˜›

To illustrate autorelease I will implement the method ObjNL:dealloc, which is called on an object just before it is deallocated.

> (define (Bar:dealloc) (println Bar:@self " has been deallocated!"))
(lambda () (println "Object " Bar:@self " has been deallocated!"))
> (push-autorelease-pool)
(())
> (dotimes (_ 5) (autorelease (instantiate Bar)))
Bar#8
> (pop-autorelease-pool)
Bar#8 has been deallocated!
Bar#7 has been deallocated!
Bar#6 has been deallocated!
Bar#5 has been deallocated!
Bar#4 has been deallocated!
true

One important point to mention is that deallocating objects in newLISP versions 10.1.8 or older is very slow. The details of why this is has to do with safety (which I discuss in the box below), but needless to say it was too slow to be acceptable. I contacted Lutz Mueller, the author of newLISP, and he agreed to introduce an “unsafe” optimization into the delete function. In versions 10.1.9 and later, deallocating Objective newLISP objects is approximately 480 times faster.

Because of this, it’s strongly recommended to use Objective newLISP with newLISP 10.1.9 or later. Currently the latest development release is 10.1.8, however Lutz graciously made this optimization available online in a development version of 10.1.9. Click here to grab the source for this version. This link will expire soon, when it does you can get the latest development release here.

Cautionary Note!

There are two situations to watch out for when using Objective newLISP:

#1: Unbound References in Functions

Instead of this:

(define (modify-obj)
    (setf obj:bar 5)
)
(setf obj (instantiate Foo))
(modify-obj)

Do this:

(define (modify-obj obj)
    (setf obj:bar 5)
)
(setf obj (instantiate Foo))
(modify-obj obj)

If you don’t do that, newLISP will read the obj:bar in the definition of modify-obj and instantly create and protect a context called obj, making it impossible to setf the obj later on.

#2: Dangling References

Use extreme caution when holding reference(s) to an object in a list or some other container! If that reference is later deallocated and you try to access it, bad things will happen:

> (setf b (instantiate Bar))
Bar#9
> (push b alist)
Bar#9
> (deallocate b)
Bar#9 has been deallocated!
true
> alist
Bus error

Normally this would not be a problem, the object in alist would simply be replaced with nil upon its deallocation. However, since we’re using the fast, unsafe version of delete to do our deallocation, newLISP will not do that. It is the same situation as when attempting to access free’d memory in C/C++/Objective-C.

Instead we should use retain/release:

> (setf b (instantiate Bar))
Bar#9
> (push (retain b) alist)
Bar#9
> (release b)
nil
> alist
(Bar#9)
> (release (pop alist))
Bar#9 has been deallocated!
true
> alist
()

When to use FOOP

Objective newLISP is not the answer to all OOP problems in newLISP. FOOP has its place too. If you’re dealing with a situation where you may end up needing lots of objects, FOOP is probably the better choice. Although you can’t do full-blown OOP with it, FOOP objects can use far less memory than ObjNL objects because in ObjNL, methods are stored in each object, not in the class. After trying out both you should have a good feeling for when to use one over the other (i.e., if the limitations of FOOP start to become obvious).

Download and API

You can grab Objective newLISP from Github.

Access the Objective newLISP API.

And for news, follow @taoeffect and @newlisp on twitter.

Thanks for checking out Objective newLISP!

Enjoy! πŸ˜€

Michael Moore’s “Capitalism: A Love Story”

Warning: This blog post is an opinion piece by Greg Slepak (while he searches for an appropriate medium), and has nothing to do with Tao Effect news.

This weekend I saw Michael Moore’s latest film Capitalism: A Love Story. Like most of his films, this one should come with a disclaimer: for the duration of the film you’ll be looking at the world through the eyes of Michael Moore and those who reflect his views. Don’t expect to see or hear any conflicting views or arguments.

For those that hate Moore’s films, there’s plenty in the film to nit-pick about. There’s a scene where he does his best to convince you that all Christian priests hate Capitalism and consider it an evil. Some have argued that he’s misusing the word “capitalism” altogether and should instead say “corporatism”. He also tends to group various corporate entities into a single-group. AIG, Citibank, Goldman Sachs, Bank of America, etc. All of these are placed in the group of “evil rich people bent on screwing over the lower-classes while having cocktail parties on corporate yachts.” In some cases, there is actual truth to that notion, but of course for those looking to put down Michael and nit-pick, he leaves plenty of room in his films to accommodate you.

However, despite the flaws, I enjoy watching Moore’s films precisely because of how rare their kind is.

It has been my general experience in life that many of the people that I encounter are perfectly satisfied to watch the latest action blockbuster out of hollywood, and when a movie like Capitalism rolls out they do two things: they pass up the ticket to see it for another action blockbuster, and then proceed to lambaste his films with a level of ignorance that far exceeds anything that I’ve heard Michael Moore say.

What further amazes me is how successful Moore has been at getting his films to play at major theaters. There are many many other films out there that do a much better job of espousing upon the insanities of our society and yet hardly ever make it into major theaters. Documentaries like Food Inc., Jesus Camp, The Century of Self (video link), Who Killed the Electric Car, and many others only find home to a handful of theaters across the country. These important films have been kicked out of mainstream society, to be replaced by the latest blow-em-up out of Hollywood that has sold out several times over.

That scenario never ceases to amaze me. How such a large amount of people, often the group that stands to benefit most from seeing movies like The Century of Self, who often live quite miserable lives because of their complete ignorance of their surroundings, can constantly, repeatedly purchase tickets to the same exact action script that Hollywood modifies slightly on a bi-monthly basis.

Ironically, it may in fact be because of the overly narrow viewpoint espoused in Capitalism, and its heavy use of emotional content, that he is able to get it distributed so widely. I say that’s better than nothing.

Further, while there are many imperfections in his films, they nevertheless tend to bring up worthy causes and viewpoints into the mainstream for discussion.

I also have to credit Capitalism for making me consider a thought that I hadn’t thought of before, namely,

Why do we allow corporate lobbyists and advisers at all?

It seems to me that just as we supposedly have the separation of church and state, we should institute the separation of the state from all other entities other than, of course, “the people.”

One thing that I’ve been astonished to learn from some of these films (Moore’s and others), is how incredibly entrenched major corporations are in the decision making of our government.

I considered the opposing viewpoint, that perhaps “because they represent the interests of a large amount of people and jobs” they should therefore have a strong say in policy making.

However, this is simply not true. Corporate interests do not include various idealized notions such as the right to a trial by jury, and even more idealized, yet worthy, concepts such as the rights to “life, liberty, and the pursuit of happiness.” Corporate interests are much simpler than that, they just want to “make a lot of money.”

Worse, they have demonstrated unequivocally that the way they’ll go about getting this money will often be by screwing over their workers, and quite often, their customers as well.

So, it seems to me that such entities should have no place whatsoever in any policy making that affects the lives of people outside of their corporation (and in some cases even inside of their corporation). Their advice is usually, simply put: bad. And in the rare instances where it’s not, we certainly did not need them for it. Instead of dictating policy to our representatives, they can call in like the rest of us. Respected scientists, nutritionists, farmers and various other in-field experts make good advisers to the FDA and USDA, not the board members of Kellogg’s and Monsanto.

Government, people often forget, should be owned by the people to serve the interests of the people. When corporations get in the picture, the people are no longer represented, instead the interests of a very small minority is represented, usually at the expense of all the others.

This is what has happened to our government. Although this situation is not anything new, it’s nevertheless messed up and it’s certainly worth changing.

A good way to upset the status quo is simply through the spread of information and the systematic removal of ignorance. Michael Moore’s Capitalism: A Love Story, though certainly flawed, helps to serve this purpose by bringing some of these issues to the forefront of America’s consciousness, and for that reason, I recommend you see it.