Skip to content
August 8, 2008 / Abe Pralle

On Safari with new Slag operators

Ever since we shipped MadStone off to Nintendo I’ve been taking a break from language and tool-coding and working on a spiritual successor to Puzzle Pits entitled Doc Fuzzle: On Safari.  It’s been really fun to work on and it’s coming along well – check it out:

I’ve been glad to be able to work on a modern tile-based game engine.  My tile algorithm lectures in my Virtual Worlds class have been a little shakey, but this is the first chance I’ve had to do something about it!  The excellent graphics are by Carl Eberhard, and it’ll be coming out on the iPhone in a few months or so.

Well anyways… I’ve always billed Slag as a practical language, and there’s been one thing that’s been bugging me as I’ve been coding On Safari: the inordinate number of times I find myself saying something like “if (ref isNot null)”.

I had a brief flirtation a few weeks ago with allowing the ‘?’ character to be part of identifiers, Ruby-style, but ultimately abandoned the idea – with Slag’s transparent access methods, you’d have to have some properties also end with “?” to be consistent with query methods and by that point it’s weird to say “next? = true” instead of “has_next = true” or some such.

Today I realized a better fit for the question mark in Slag: I turned it into a post-fix unary operator (the query valid operator, I call it) that returns a Boolean “true” if an expression is “true”, “yes”, non-null, or non-zero depending on the type of the expression.  So “if (ref isNot null)” becomes “if (ref?)”.  Likewise instead of saying “if (list.count > 0)” you can say “if (list.count?)”.  James Palmer mentioned this was how it works in Perl – or was it Lisp?  Anyways, I think it’ll be handy and it’ll give Ryan Raub the ability to have the question-mark query methods that he likes from Ruby!

While I was at it I implemented something that I’d been meaning to for a while: the auto-iterator for lists.  It’s real simple: if you were going to type “forEach (obj in list) obj.update”, you can say just “obj->update” instead.  Okay, this isn’t a massive time-saver, but I think it’ll be nice to have.

Those two features will be coming in Slag/Plasmacore v0.23!

Advertisements

2 Comments

Leave a Comment
  1. Jacob Stevens / Aug 9 2008 8:15 am

    Hey Abe!

    Two things:

    1. I think this is a great solution to the question mark issue! It seems to, in least some way, serve the purpose of the alternative you discussed awhile, without impacting the readability negatively in the fringe cases.

    2. Fuzzle on Safari is looking fantastic! I’m really impressed by the quality and detail of the graphics. Congratualtions! I can’t tell much about the gameplay yet, but I’m intrigued by the puzzle potential of the lion… 🙂

  2. James / Aug 19 2008 8:13 pm

    Actually it was predicates in Scheme that use ‘?’. For example, (odd? n) tests if n is odd. In Lisp it would be (oddp x). It’s a coding convention adopted by Schemers and Lispers and not a rule or feature of either language. So, in that way Slag is different. In the example you give you would probably write (null? list) in Scheme. But you could write a function simply called ‘?’ that implements a ‘?’ operation exactly as you describe. Though I am not sure about the readability of (? (length list)). It reads better as a suffix.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: