Chip's Tips for Developers

Contains coding, but not narcotic.

Properties: just like public member variables, except when they aren’t

June 29th, 2009 1:34:43 pm pst by Sterling Camden

Many object-oriented languages provide an abstraction called properties:  data members that belong to a class instance, but whose public interface controls how those members can be manipulated via accessor methods.  In languages like C#, VB.NET, and Synergy/DE, the syntax for accessing properties is identical to accessing public member variables.  That’s convenient and intuitive – but misleading, because properties are methods, not data.

Usually that distinction has no practical consequences.  But just try passing a property as an “out” parameter.  Even if the property defines a setter method, the compiler complains “A property or indexer may not be passed as an out or ref parameter”.  That means that you can’t even pass an element of an ArrayList to an “out” parameter.  You can say:

myarray[0] = some_object;

but you can’t say

FillInTheObject(out myarray[0]);

My first reaction to this restriction was the same as that of BCS: Why doesn’t the compiler just generate a call to the setter method when the function returns?

A couple of potential reasons:

  1. Unless somehow the setter method could get passed into the exact statement(s) that modifies the parameter, you could introduce timing issues.  Another thread (or even a routine in the same thread) that has a reference to the property or the member data behind it could modify that data after the logical modification within the function, but before the function returns.
  2. Too much syntactic sugar leads to code diabetes.  When the compiler does too much for you, you get more overhead than you bargained for.

I’m not sure that either of these objections outweighs Caveat emptor.  After all, you currently can’t do this at all, so changing the behavior wouldn’t break any existing code.  Unless you’re in the camp that believes that the compiler should slap your hand whenever you do something it thinks you didn’t mean to do.  I’m not in that camp.

Why doesn’t Ruby have this problem?  After all, it has accessor methods for attributes (the equivalent of properties).  The answer is simple:  Ruby doesn’t support “out” parameters.  Like a good functional language, you must return values as the result of a function, not as an argument.  That constrains assignment to a distinct moment in the execution of the function (after it returns), and thereby eliminates the concurrency issue while simultaneously making the assignment apparent to the most casual perusal of the code.

So the real issue here is not that properties look like data while behaving like functions.  The real problem is that you shouldn’t use “out” parameters.

Posted in .NET, C#, Ruby, SynergyDE, Visual Basic | No Comments » RSS 2.0 | Sphere it!

Progn for Synergy/DE

June 28th, 2009 4:09:45 pm pst by Sterling Camden

As we have seen, it’s often useful in Synergy/DE to do more than one thing in a single statement – especially when defining macros.  One way you can join multiple operations is with a Boolean operator:

status = (operation1() && operation2())

But this approach has some limitations:

  1. If the first operation returns false, the second operation is not performed.  Of course, you can use that to your advantage as shorthand for an ‘if’.  And if you know that the first operation returns false, you could use || (or) instead of && (and) as shorthand for ‘if not’.  But what if you want to always execute both operations, regardless of their return value?  There isn’t an “I don’t care” operator.
  2. The only return value that you can get out of the expression is a Boolean value.  What if you wanted the actual result of the second operation, for instance?

Common Lisp solves this problem with PROGN:

(progn (operation1 …)
       (operation2 …))

which can take any number of operations (technically “forms”, not necessarily operations), and returns the result of the last one.

The downloadable code below provides a Progn class for Synergy/DE.  Using this class, you can say:

Progn.Do(operation1()).Returning(operation2())

which returns the result of operation2().  You can insert more operations in the middle using the Then() method:

Progn.Do(operation1())
    &.Then(operation2())
    &.Then(operation3())
    &.Returning(operation4())

The static Do() method returns a Progn object, ignoring its parameter.  The Then() method also ignores its parameter, and returns the same object.  The Returning() method merely returns its parameter.  Each of the steps is executed before the method to which it is passed.  In order to minimize casting, Progn defines versions of Do, Then, and Returning that take arguments of type int, decimal, alpha, Var, and object – with each version of Returning returning the same type as its argument.  So the only time you should need to cast the result is when returning an object of a class other than Var or string (which is alpha-compatible).

Of course, the operations above can be any expression that evaluates to a value – they don’t have to be function or method calls.

Combining Progn with Let, you can now construct inline functions with local scope that can also access their defining scope.  Unfortunately, you cannot evaluate these functions lazily.  In other words, you can’t create a closure to be called later on.  So we’re still not as functional as we’d like to be, but we’re taking one more small step in that direction.

Posted in SynergyDE | No Comments » RSS 2.0 | Sphere it!

JavaScript Sudoku enhanced and linted

June 22nd, 2009 2:32:53 pm pst by Sterling Camden

image I’ve added a few more enhancements to my online Sudoku game, which you can play here.

  • The game now displays the number of givens below the puzzle, which updates as you request hints.
  • You can enter the number of givens to use on the next puzzle, which defaults to the number used to construct the current puzzle.
  • For those users whose hands are glued to their mice, I’ve added a vertical column of buttons numbered 1-9.  Pressing one of these will set the value of the most recently focused cell to its value.
  • I fully JSLinted the code (sans options).  Many thanks to Douglas Crockford for creating this indispensable tool.

DT suggested the third item.  The second item partially answers DT’s other suggestion:  the ability to choose the difficulty level.  Of course, the real difficulty of a Sudoku relies on a lot more than the number of givens.  Which values are revealed or hidden and where they are located go much further towards determining how easily you can solve the puzzle – but I have yet to create an algorithm for evaluating those factors, much less for constructing a puzzle that produces the requisite range of frustration.  Anyone have any ideas?

Posted in Javascript, Web | No Comments » RSS 2.0 | Sphere it!

Point of style in C coding conventions

June 12th, 2009 9:52:55 am pst by Sterling Camden

An interesting question came up on the Code Project’s Lounge:

I’m trying to work out where to place the asterisk when declaring a pointer variable.
Do you think the asterisk belongs next to the type name or the variable name?

CType* Pointer = NULL;

vs.

CType *Pointer = NULL;

At first I was inclined to favor the first form, because I think of “pointer to” as part of the variable’s type information, rather than part of its name.  In fact, the Windows API is full of typedefs for pointers that allow you to declare them using a single token, like so:

LPSECURITY_ATTRIBUTES lpsa = NULL;    // Pointer to a SECURITY_ATTRIBUTES structure

Unfortunately, this practice hides the fact that C/C++ requires you to apply the * to every pointer variable in a multi-variable declaration.  Thus:

CType* Pointer1, Pointer2;

Doesn’t give you what you might expect, as Pointer2 is now an instance of CType, not a pointer to one.  That’s even less obvious when using one of Microsoft’s pointer typedefs:

LPDWORD pWord1, pWord2;

where pWord2 is actually a DWORD.

The C language treats type and level of indirection as separate concepts.  Thus, it makes sense to separate them syntactically.  But rather than attaching the * sigil to the variable name, perhaps it acts as a better signal that indirection is an independent characteristic of the variable to separate it from both its type and its name:

CType * Pointer = NULL;

Or perhaps the best solution is not to use pointers.

What do you think?

Posted in C and C++ | 1 Comment » RSS 2.0 | Sphere it!

JavaScript Sudoku, now with even more JavaScript

June 4th, 2009 8:13:49 am pst by Sterling Camden

I’ve made a few revisions to my JavaScript version of Sudoku (which you can play here).  Changes include:

  • As soon as you press a number key, it is checked (instead of waiting for you to leave the cell).
  • You can use h, j, k, and l to move around the puzzle (a la vim), in addition to the arrow and tab keys.
  • If you press the letter q, the current cell is toggled “questionable”.  The provided stylesheet colors questionable cells with a yellow background.  This can help you backtrack on your guesses.
  • When a new game is presented, the first empty cell is now focused (previously, nothing was focused).
  • I added a “Help” button that pops up a floating help window.  You can click and drag this window anywhere, and you can close it by pressing ESC or by clicking on the “x” button in the title bar.  Three new style classes were added for this window (see readme.txt and sudoku.css).
  • When you successfully solve a puzzle, an alert pops up that says “Solved!”  Waiting for that to happen will prevent you from thinking that you’re done when there are still some empty cells left.
  • I separated the styling for cells that are corrected by a Solve (class sudokuCorrected) and those that were still empty when Solve was pressed (sudokuSolvedEmpty).  The provided stylesheet colors the text for these red and blue, respectively.  This helps you better determine where you went wrong.

Posted in CSS, Javascript, Web | 8 Comments » RSS 2.0 | Sphere it!

Debugging the Brainbugger

May 25th, 2009 2:32:24 pm pst by Sterling Camden

I just couldn’t leave it alone.  The charm of learning two languages at once by writing an interpreter for one using the other consumed my attention.  Furthermore, I had left the door open for adding debugging facilities, and then I found myself needing them.

Daniel Cristonfani’s Fibonacci generator had me hooked.  It’s so small, yet it produces a seemingly endless series of Fibonacci numbers in ASCII representation.  These soon exceed the storage capacity for 64-bit, yet his program just keeps on spitting them out.  I let it run until each one was nearly 1000 digits long.

You may call me a weak geek, but I wasn’t able to decipher what the code was doing in my head, nor with the aid of pencil and paper.  So I decided to create a debugger for Brainfuck, so I could step through the code and watch its progress.

You can download the updated Brainfuck interpreter in Lisp with the debugger (ibf.lisp) below.   Run that, and you get an “ibf>” prompt.  There, you may enter the following commands:

add <code>          - Add BF code to the end of the code stream
back                - Back up one instruction (does not alter data)
clear               - Clear all data cells
code                - Display the code, with () around the current instruction
data                - Display the data cells, with () around the current cell
del                 - Delete the current instruction
exit                - Exit (same as quit)
go                  - Execute to the end
help                - Display this helpful information
ins <code>          - Insert code before the current instruction
load <file>*        - Load instructions from file(s)
new                 - Start over with no instructions or data
quit                - Quit (same as exit)
repeat <count> <cmd>- Repeat debugger command the specified number of times
reset               - Clear all data cells and rewind to first instruction
rew                 - Move back to the first instruction (does not alter data)
s                   - Combination of step;code;data
save <file>         - Save instructions to a file
skip                - Skip the next instruction (does not alter data)
step                - Execute the next instruction 

Commands are case-insensitive, and may be combined on the same line separated by semi-colons (;).  Thus, to step through Daniel’s Fibonacci generator, the session looks like this:

ibf> load fib.b

ibf> s

>(+)+++++++++>+>+[[+++++[>++++++++<-]>.<++++++[>--------<-]+<<<]>.>>[[-]<[>+<-]>

>[<<+>+>-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>+>+<<<-[>+<-]]]]]]

]]]]]+>>>]<<<]…

0 (0)

ibf> s

>+(+)++++++++>+>+[[+++++[>++++++++<-]>.<++++++[>--------<-]+<<<]>.>>[[-]<[>+<-]>

>[<<+>+>-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>+>+<<<-[>+<-]]]]]]

]]]]]+>>>]<<<]…

0 (1)

ibf> s

>++(+)+++++++>+>+[[+++++[>++++++++<-]>.<++++++[>--------<-]+<<<]>.>>[[-]<[>+<-]>

>[<<+>+>-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>+>+<<<-[>+<-]]]]]]

]]]]]+>>>]<<<]…

0 (2)

ibf>

You can see the current instruction and the current data cell in context but highlighted by parentheses.  Using this tool, I found that Daniel keeps the numbers in decimal (one digit per cell) and simply adds 48 to output each one as ASCII.  Thus, he’s only limited by the number of cells that a specific Brainfuck engine supports.  Typically, that’s 3000 – but my version is only limited by available memory.  We could keep on fibbing all day.

Since the debugger supports inserting and deleting code as well as loading from and saving to a file, you could use it as a limited IDE for Brainfuck.  The reset command will clear the data and rewind the program counter, so you can rerun your modified program until it works.

Posted in Brainfuck, Lisp | 1 Comment » RSS 2.0 | Sphere it!

Penetrating my cerebrum with Lisp

May 21st, 2009 1:40:20 pm pst by Sterling Camden

I’ve been casually studying Lisp for years now, and gathering a much better understanding of programming languages in the process.  I finished reading Paul Graham’s On Lisp earlier this year.  But the only way to truly grok a language is to use it to write something fairly complex.  Lisp is often stereotyped as being designed for highly abstract academic problems – and what could be more abstract and academic than writing an interpreter for Brainfuck?

While it may sound über-geekish to be able to say that my first real program in Lisp was an interpreter, I cheat a little bit here because Brainfuck is such a simple language to interpret (for a computer, anyway).  I also didn’t build in Brainfuck as an extension of Lisp the way most DSLs are written in Lisp – primarily because the comma and period characters are reserved for the Lisp compiler, and overloading the functions + and – wouldn’t be such a good idea, either.

So, you can feed my interpreter its code as a series of strings or as a list of symbols.  The string form is probably preferable, because the symbols have to be prefixed with ‘bf’ to avoid the collisions I mentioned above.

In the downloadable code below, brainfuck.lisp contains all of the functions for the Brainfuck interpreter, and bf.lisp is a command-line interface for it.  I developed it using CLISP, but it should be compatible with most Common Lisp implementations.  Usage:

clisp bf.lisp <bf-file>*

where <bf-file> is a file containing Brainfuck code.  If you supply more than one file, they are executed within the same machine as if they were one continuous file.

This brought me face-to-face with the problem of retrieving command-line arguments in Common Lisp, which isn’t standard across implementations.  I found a work-around for that in the Common Lisp Cookbook, but it didn’t handle CLISP.  After a little research, I was able to modify it to include support for CLISP:

(defun get-command-args ()
  (or
   #+SBCL *posix-argv*
   #+LISPWORKS system:*line-arguments-list*
   #+CMU extensions:*command-line-words*
   #+clisp EXT:*ARGS*
   nil))

If you want to call the Brainfuck machine from within Lisp, here are a few important functions:

(make-bf-machine) => bf-machine

(bf-add-string bf-machine code) => code-stream

(bf-add-list bf-machine code) => code-stream

(bf-step bf-machine) => current-cell-value

(bf-run bf-machine) => final-cell-value

(bf-current-instruction bf-machine) => current-instruction

The last one is important if you intend to step through a program, because it yields nil when there are no more instructions.

Since bf-add-list doesn’t validate the symbols it receives, it provides an opportunity for Lisp code injection.  You can pass it any symbol that represents a function that takes a bf-machine as its only argument.  For example, 'print might be handy for debugging.  The bf-add-string function doesn’t have the same facility/vulnerability, because it filters out non-Brainfuck characters.

Notes on the Brainfuck implementation

First, let me address each of the points in Daniel Cristofani’s Epistle to the Implementors:

  1. Greetings back atcha, Daniel.
  2. Duly perused.
  3. This implementation treats EOL as a 10.  That was a freebie from using CLISP.
  4. EOF on input leaves the current cell unchanged.
  5. Non-Brainfuck characters are dutifully ignored.
  6. I have not added any extensions to the language – nor have I implemented the “traditionally sanctioned” # and ! extensions.
  7. This implementation provides a logically infinite array of cells – in both directions.  Thus, if you shift left from cell 0, you will receive a new cell 0 containing a zero, and all other cells are shifted to the right.  The maximum value that can be stored in any cell is dependent on the capacity of numbers in the version of Common Lisp – which appears to be 64-bit floating point.
  8. It’s fascinating!

My implementation passes all of the tests that Daniel suggests, with the exception of being more lenient on:

  • The two bounds-checking tests, which run forever (or presumably until memory is exhausted, but I didn’t have the patience for that).
  • The two unmatched bracket tests.  When my implementation reaches the end of the code stream while hunting for a matching bracket, it just ends.

I also tested most of the programs that Daniel supplies.  I particularly like his Fibonacci generator, which is incredibly concise for a version that outputs successive values in ASCII.

Finally, since there’s no finer way to screw up your noggin than with alcohol, try the programs at 99 Bottles of Beer.

 

Posted in Brainfuck, Lisp, Wildly popular | 11 Comments » RSS 2.0 | Sphere it!

OPML Browser 2.0 for WordPress

May 11th, 2009 4:38:37 pm pst by Sterling Camden

Yes, this is such a major upgrade to my OPML Browser plugin for WordPress that it warrants bumping the initial digit in the version number.  Here’s what changed:

  1. The plugin now expects to be installed in its own folder: (siteurl)/wp-content/plugins/opml-browser
  2. JavaScript and CSS have been separated into their own files.
  3. JavaScript events are now hooked on window load instead of in the HTML.
  4. Added “alt” attribute to all “img” tags.
  5. Images are now looked for in (siteurl)/wp-content/plugins/opml-browser/images
  6. If an image cannot be found, it will be replaced by the supplied unknown.png (a question mark).
  7. Added “Sort items?” option.  This sorts within categories, unless the “flatten” option is enabled (see next item).
  8. Added the “Flatten hierarchy?” option.  This combines all items into one level.  If sorting, all items get sorted together.
  9. The OPML description attribute is now displayed as a tooltip (as in the OPML Blogroll widget, but it also works in IE and Opera now!).

As far as I know, the OPML Browser can now do everything that the OPML Blogroll widget could do (items 7 through 9 filled that out), so I am herewith declaring the OPML Blogroll widget retired from further upgrades.  Please use this plugin’s widget instead from now on.  Let me know if I’ve forgotten any functionality that you need.

A big “thank you” to all of my users who requested various features and reported bugs.  This plugin would not be what it is today without your input. 

Posted in AJAX, ATOM, CSS, Javascript, OPML, PHP, RSS, WordPress | 1 Comment » RSS 2.0 | Sphere it!

Sorting array keys in natural order in PHP

May 11th, 2009 12:21:29 pm pst by Sterling Camden

PHP, the language of myriad functions, devotes quite a few of those to the problem of sorting arrays.  One flavor of sort function useful in presenting data on web pages is natcasesort, which performs a case-insensitive, natural order sort.  However, even though natcasesort preserves key => value associations, you cannot use it to sort an array by its keys.  The sort order is determined by the value alone.

Consider the following:

   1: $array = array('wilma' => array('role' => 'wife', 'sex' => 'female', 'haircolor' => 'red'),

   2:                'fred' => array('role' => 'husband', 'sex' => 'male', 'haircolor' => 'black'),

   3:                'barney' => array('role' => 'neighbor', 'sex' => 'male', 'haircolor' => 'blond'),

   4:                'Betty' => array('role' => 'neighbor', 'sex' => 'female', 'haircolor' => 'black'),

   5:                'pebbles' => array('role' => 'child', 'sex' => 'female', 'haircolor' => 'red'),

   6:                'bam bam' => array('role' => 'neighbor\'s child', 'sex' => 'male', 'haircolor' => 'blond'));

   7: 

   8: natcasesort($array);

   9: 

  10: echo "<h3>using natcasesort</h3>";

  11: foreach($array as $name => $features) {

  12:   echo $name . "<br/>";

  13: }

Since natcasesort sorts on the value rather than the key, and the value in this case is another array, the sort order appears to be almost random:

pebbles

bam bam

Betty

barney

fred

wilma

To sort by the keys instead you can use ksort, but unfortunately it supports neither natural ordering nor case-insensitivity.  What you’d like here is a natcaseksort, but no such animal exists.

However, you can easily create one by combining two other functions:  uksort and strnatcasecmp.  The former performs a key sort using a supplied function taking two parameters (two key values) and returning <0, 0, or >0 to indicate their collational relationship.  The latter performs a case-insensitive, natural order string comparison, returning precisely those values.  Thus, the equivalent of the mythical natcaseksort is the following one-liner:

   1: uksort($array, 'strnatcasecmp');

which faithfully produces:

bam bam

barney

Betty

fred

pebbles

wilma

For once, the authors of PHP refrained from creating yet another sort function.  It just happened to be the one I needed.  But two functions that each Do One Thing Well fit together with surprisingly Unix-like elegance to do the job.

 

Posted in PHP | No Comments » RSS 2.0 | Sphere it!

CFile::GetStatus on root folder works sometimes

May 3rd, 2009 10:04:42 am pst by Sterling Camden

There’s nothing particularly magical about this tip, but its solution stumped me for a while so perhaps it will help out some other poor developer who is madly googling for an answer.

An MFC application needs to determine whether the path entered by a user is a valid folder.  The user already has to be an Administrator, so we don’t care about privileges.  All we want to know is, does this folder exist and is it indeed a folder and not a file or something else?

The MFC Way of doing this is to call CFile::GetStatus on the path, which fills in a CFileStatus structure and returns TRUE or FALSE.  The CFileStatus structure contains an m_attribute member that has bit values for whether its a folder, a file, etc.  This works fine most of the time.  But occasionally, calling it on the root folder of a device (e.g., “C:\”) will return FALSE.  The user reported that it failed only when the application was started from a command prompt instead of the Start menu.  That elicited from me a great big “Huh?”

Digging into it, I found that the problem reproduced when running from some command prompts, but not others.  From a command prompt where it normally failed, it wouldn’t fail if I started Visual Studio from that same prompt to debug it.  Thus, I resorted to the dreaded MessageBox debugging methodology.

I also googled this problem, found that others had run across it as well, but didn’t come up with any good solution.  One commenter suggested using SHGetFileInfo, which seemed to solve the problem until I realized that it also returned normally for folders that don’t exist.

I looked through the MFC sources and found that while the instance method for CFile::GetStatus simply uses GetFileAttributes, the static method that I was using does a FindFirstFile instead.  So I changed my application to call GetFileAttributes directly, and that works exactly as I would have expected.  It returns INVALID_FILE_ATTRIBUTES if the file or folder does not exist, and it returns a bit value that includes FILE_ATTRIBUTE_FOLDER if it is a folder of any kind (including a root folder).

GetFileAttributes provides a better solution anyway.  CFile::GetStatus just adds a bunch of extra code I didn’t need – even if I had used the instance version instead (which probably would also work).  The lesson here is that in an MFC application, it’s not always optimal to cling to MFC methods.  Take the blinders off and use the Win32 API when that provides precisely what you need.

Posted in C and C++, MFC, Windows | No Comments » RSS 2.0 | Sphere it!

Functional Let for Synergy/DE

April 23rd, 2009 9:41:15 am pst by Sterling Camden

Synergy/DE possesses a macro definition syntax that’s very similar to the #define syntax in C, but not quite as robust.  It doesn’t support macros that expand to multiple lines of code.  An individual parameter passed to a macro cannot be continued to the next line, either.  A macro cannot be used as a parameter to itself, nor within its expansion (as of 9.1.5).  But despite these limitations, I find macros to be a powerful tool for either simplifying my code or making it hopelessly obscure.  The basic Synergy/DE macro syntax is:

.define macroname(parameter, …) expansion

Wherever parameter is encountered within expansion it is replaced with whatever is passed to the macro in that argument position when it’s invoked.  In order to be recognized as the desired token within expansion, it must either be syntactically isolated as a token, or escaped with a back-quote (`).  Within strings, you use two back-quotes preceding and one following the identifier.  If you continue a macro to the next line, its expansion is also continued – which is why macros are limited to a single statement.  There is no syntax (yet) for saying, “this is a continuation of my macro, but I want it to be a new statement rather than a continuation of the same statement within the expansion.”

One problem that’s common to any parameterized macro system (be it Lisp’s, C’s, or Synergy/DE’s) is how many times an argument gets evaluated at runtime.  Macro invocation syntax looks like functional syntax, but how arguments get evaluated is quite a different ball game.  Consider the classic “max” macro:

.define max(val1, val2) fif(val1 > val2, val1, val2)

For a definition of the fif macro, see this post.  Now lets try using it:

account.fee = max(5.00, account.CloseQuarter() * 0.01)

Seems innocent enough, we’re going to close out the quarter, which returns the total, from which we’ll compute a fee of 1% of total activity, but not less than $5.00.  If max were a function, then each parameter would be evaluated once before invoking it.  But the max macro expands out into:

account.fee = fif(5.00 > account.CloseQuarter() * 0.01, 5.00, account.CloseQuarter() * 0.01)

which means that if 1% of activity is not less than 5.00, we’ll call account.CloseQuarter() twice.  Actually, because fif is implemented under the hood as a static method, we’ll always call account.CloseQuarter() twice.  Even if account.CloseQuarter() had no side-effects, it’s more than we intended to do.  I could also devise examples of macros in which an argument may not get evaluated at all.  This, too, can cause confusion when you’re looking at the code and thinking of the macro as if it were a function.

One way to solve this problem in Lisp is to use LET.  LET exists in many functional languages to allow you to define a scope for local assignments, but it can also be used to force single evaluation of macro parameters:

 

(defmacro mymacro (param1)  
  `(let ((,var1 ,param1))
      (maybe do things with ,var1)))

 

The macro generates a LET statement in the code, assigning the parameter param1 to a local variable var1, which only has the scope of the LET statement.  That assignment forces param1 to be evaluated once and only once within the generated code.  The LET then returns whatever the (maybe do things with var1) statement returns.  Even if there is a var1 declared in the surrounding code, the var1 referenced inside the LET will refer to the parameter’s value.  Other variables defined in the surrounding code may, however, be referenced and used within the macro (which isn’t hygenic, but is sometimes useful).

I have a dream

How could we do something similar in Synergy/DE?  We do have the ability to define a very local scope for variables in version 9, using the DATA statement — but there are at least two reasons why this won’t help us with macros:  (1) a DATA statement has to be on a line by itself, and we don’t have multi-line macro expansions (remember?), and (2) even if we did, we don’t have any way to return a value from a multi-statement block.   Probably the right way to solve this in the language would be to allow inline anonymous functions with access to the local scope (a la JavaScript and other languages with closures) and also provide a syntax for multiline macros.  We could dream, for instance, of something like this:

 

.define mymacro(param1) function, ^val
.&                          var1, i
.&                      proc
.&                          freturn maybe_do_things_with(var1) ;a macro that might use var1 or not
.&                      end(param1)  ;Invoke it, passing param1

 

By converting the macro into a function, you’d automatically evaluate arguments only once.  But that’s pie-in-the-sky – how about something I can use today?

Let my parameters go

The downloadable code below works with Synergy/DE version 9.1.5 and above, and provides a form of scoped LET.  The syntax is a bit more cluttered than I’d like, but it’s functional (pun intended).  For instance, you could define our mymacro example as:

.define mymacro(param1) let(assign(“var1”, param1), maybe_do_things_with(valueof(“var1”)))

and we can write a single-evaluation-safe version of the max macro as:

.define max(val1,val2) let(assign("val1",val1) && assign("val2",val2), fif((vv("val1") > vv("val2")), vv("val1"), vv("val2”)))

This version of max takes any two primitives (or Vars) and returns a Var containing the greater of the two values.  Both val1 and val2 will be evaluated once and only once, in their respective assigns.

The basic syntax for let is:

return_value = let(assignments, body)

where

return_value  is whatever body returns.  It will have the same type as what body returns, so you may need to cast it.

assignments are one or more “assign” macros, joined with the logical AND operator (&& or .and.)

body  is some expression whose result will be returned.

I lied just a bit when I said that the return value is the same as what body returns.  It will be one of the following, whichever is the best match for what body returns:

  • i (which covers boolean, int, and ^val functions)
  • decimal (which covers d and d.)
  • a (which also handles strings)
  • @Var (if it’s a Var)
  • @* (for all other object classes)

The syntax for the assign macro is:

assign(name, value)

where

name is the name of a let variable

value is the value to assign it

Under the hood

The assign macro expands into a static method named Lets.Set.  It returns a Lets object that is passed to let to maintain scope (let actually expands into a static method named Lets.Return).  The logical AND between two Lets objects causes the first one to maintain the scope of the second one.   Thus, we always use only one argument for all assignments, and the second argument is for the body.

The assignment of let variables is maintained in a static Hash of Stacks.  Each member of the hash is the stack of values for a given name.  An assign pushes a new value onto the stack for its name, and the let to which that assign belongs removes that value from the stack before it returns.  Within either a subsequent assign or within the body of the let, you can reference the topmost value on the stack for a given name via the valueof macro.

Since Stacks can only hold objects, if a primitive type is passed to assign, it is boxed in a Var.  The valueof macro (which expands into the static method Lets.Get) always returns an object, so I’ve provided a handy shortcut to cast it as a (Var): the vv macro.  vv(name) is equivalent to (Var)valueof(name).

What is It?

Another handy shortcut is the “it” macro.  “it” provides a reference to the most recently assigned value, without having to know its name.  “it” is also scoped to a let, so in the case of nested lets, it goes back to what it was in the outer let when the inner let returns.  To cast “it” as a Var, you can use the itv macro as a shortcut.

Why wouldn’t you know the name of the most recently assigned value?  Sometimes you don’t care, especially if you only need one temporary variable.  So, to generate a unique name, we have gensym, and as a shortcut for a let with only one assignment that uses gensym for its name, we have the genlet macro:

result = genlet(value, body)

Believe me, “it” will come in handy in that body.  In case you do want to inspect the name of whatever is assigned to “it”, there is the “itsname” macro to provide it to you.

I’ve provided quite a few tests in test_let.dbl.  These also serve as some good examples of usage.

Even though Synergy/DE doesn’t allow macros to be nested in their own parameters, I’ve worked around that for let and assign.  They aren’t actually parametric macros – they’re just text replacements for their static method names.  So you can have a let within an assign, and you can have a let within the body of a let.  The let variable scoping all works as you would expect.  You can also continue a statement to the next line in the middle of a let or an assign.

Back in the 1980s I stretched the DIBOL language (which at that time lacked integers, dynamic memory allocation, and recursion) to implement various DSL interpreters.  In the early 90s, I used the newly available xsubr routine to create a form of object-orientation by convention.  Ken Lidster and I subsequently designed a couple of prototypes for a true OOP implementation, which has finally come to fruition in Synergy/DE version 9.  Now once again, I’m pushing the limits of the language to enable the functional model.  Let us see where it goes from here.

 

Posted in SynergyDE | 1 Comment » RSS 2.0 | Sphere it!

Stack class for Synergy/DE

April 20th, 2009 2:22:31 pm pst by Sterling Camden

The concept of a stack has been useful to computing for more than fifty years.  It represents a LIFO (Last In First Out) series of data elements.  Of course you can use a simple array as if it were a stack — but one of the ways in which object orientation can actually simplify programming (rather than hopelessly obfuscating it as usual) is by clearly representing useful abstractions as classes and members.

The downloadable code below contains a Stack class that extends the Synergy/DE ArrayList class (which is patterned on the .NET version), adding methods for treating it as a stack:

  • Stack.Push(object) will insert object at index 0 of Stack.
  • Stack.Pop() returns the object at index 0 of Stack, removing it (or returning ^null if Stack is empty).
  • Stack.Remove(object) removes the first occurrence of object from Stack, returning true if found, otherwise false.

That last method doesn’t fit the pure model of a stack, but I needed it for my own evil purposes.

Stack pushes new objects onto the front of the base ArrayList for one simple reason:  the Synergy/DE foreach statement will therefore iterate over the items in LIFO order.  In fact, because Stack extends ArrayList rather than containing one, you can use any ArrayList method on a Stack.  Thus, Stack[0] always accesses the top stack item, without removing it.  Stack.Count gives you the number of items.  Etc.

Beware of overusing stacks – often where they seem to be necessary, recursion provides a better model.  Recursion is essentially a stack push, iterate through the code, and pop.  But it not only pushes the local data, it also pushes your current location in the algorithm.  However, some cases of nested operations (like the one I’m currently working on) can’t readily be solved through recursion.  That’s when you should use a stack instead.

Putting together a Queue class will be left as an exercise for the reader (until I need one).

Posted in SynergyDE | 1 Comment » RSS 2.0 | Sphere it!

Var class provides more flexible boxing of primitives in Synergy/DE

April 9th, 2009 12:35:09 pm pst by Sterling Camden

The object model in Synergy/DE version 9 treats primitive types as essentially different from classes — much like Java and C#.  Also imitating those two languages, Synergy/DE supports the practice of “boxing” primitives — wrapping a primitive type within an object.  That’s useful whenever you need to pass a primitive as a parameter where an object is required.  A common case is the ArrayList class, which stores a variable-length array of objects.  If you want a variable-length array of numbers or strings, then you need to box them:

myArrayList.Add((object)"hello world")

As you can see from the example, all you need to do to box a primitive is to cast it as an object.  To unbox, you cast the object as its primitive type:

writes(1, (a)MyArrayList[0])   ;Treating the first element of the ArrayList as alpha

If you use the wrong type on the unbox, you’ll get an “Invalid cast” error at runtime.  Unfortunately, there is no way to interrogate a boxed primitive for its primitive type, so you just have to know.  That even goes for decimal versus integer, so you’d better be aware that boxing the number 1 gives you a decimal object (which you must cast as (d), not (i)).  The only method for extracting the value that works for all primitive types is Object.ToString(), which gives you the string representation of the value.

I have my own reasons (which will be revealed in a later post) why I need more flexibility here, but I’ll bet some of you might find this useful as well.  The downloadable code below contains a set of classes in var.dbl to support a more type-agnostic boxing of primitives.  The only class you need to deal with is Var, which can be one of VarInt, VarDec, or VarAlpha.  When you cast a value as (Var) you’ll get an instance of one of those three classes — but you can treat it as an instance of Var for all practical purposes.  A Var can be cast as (i), (decimal), or (a) — no matter what its type.  Because of a compiler bug, I had to exclude (d) — op_Explicit thinks that d and decimal are the same type, but it won’t convert a d without precision into a decimal on the cast.  So if you need to use a d value, you’ll have to convert it to implied first.

Even though a Var remembers its type, it performs automatic conversions between types.  Casting a VarInt as (decimal) will give you a decimal equivalent of the integer value, for example.  Furthermore, Vars can be compared against one another — and also against primitives.  Thus:

(Var)1.0 == 1
(Var)1.0 == (Var)%integer(1)
(Var)"1" == 1

etc.  All of the comparison operators are supported, since Var includes the Comparable mixin.  For each comparison, if the primitive types do not match, then integer is promoted to decimal, and either integer or decimal is promoted to alphanumeric.

Vars also support the mathematical operators +, -, *, and /.  When operand types don’t match, integers are promoted to decimal.  Alphanumeric operations are a bit different, so they require some explanation.  Alphanumeric addition is string concatenation, and the other operand is promoted to alpha if needed.  Subtraction removes the first occurrence of the second operand from the first operand, and the other operand is promoted to alpha if needed.  Multiplication treats one of the operands as integer (converting the second one if both are alpha) and creates a new VarAlpha that contains a string of that number of replications of the alpha operand.  Alphanumeric division doesn’t make sense, so both operands get converted to decimal.

When converting alpha to decimal or integer, if an invalid digit is encountered then the result is zero (rather than throwing an exception).  Dividing by zero, however, still throws an exception (what would we return instead?).

Var also includes the Boolean mixin, so you can use any Var as a boolean expression.  Standard DIBOL rules apply:  integer and decimal are true if non-zero, alpha is true if non-blank.

Var supports unary negation, so -(Var)1.0 == -1.

You may wonder why I have a Var.Box method for an object parameter, which simply returns its parameter.  That’s so I can pass any type or object to Var.Box and get an object back.  Of course, in the case of an object parameter, that returned object will not support the same methods as a Var.  But the compiler will catch you if you try to use one on it, since it won’t be typed Var.  Duck typing of disparate classes is a problem for another day.

UPDATE 2009-04-22:  I updated the Functional If macro to implicitly handle Var without casting.

 

Posted in SynergyDE | 3 Comments » RSS 2.0 | Sphere it!

Boolean operations mixin for Synergy/DE

April 6th, 2009 11:48:39 am pst by Sterling Camden

The new class syntax in Synergy/DE version 9 allows you to define a whole host of operators for your own classes.  These include the boolean operations of testing for True, LogicalNot (! or .not.), LogicalAnd (&& or .and.), LogicalOr (|| or .or.), and ExclusiveOr (.xor.).  Once you’ve defined these in your class, you can write statements like:


if (myobject) ...
if (!myobject)...
if (myobject1 && myobject2) ...

etc.

Unfortunately, just defining op_True doesn’t automatically make the other operations default to anything.  Using the .not. operator (!) on an object that only defines op_True will give a compiler error, because op_LogicalNot is not defined.  Likewise for the others.  Furthermore, in the case of the binary operators LogicalAnd, LogicalOr, and ExclusiveOr, you not only need to define operations in which both operands are members of your class, but also any other combination with different types of operators.  Otherwise:


if (myobject && some_function_that_returns_an_integer())

will get a compilation error.  Likewise, you also need to define different orders of operands.  It turns out that to get full coverage for primitives, you need to define operands for your class and integer, decimal, and alphanumeric (integer also handles boolean, and alphanumeric also handles string), in both orders.  Including the case of two operands from your own class, that’s seven versions of each binary operator!  There are three such operators, plus op_True and op_LogicalNot, for a total of 23 methods just to implement a consistent test for truth.

The downloadable code below provides an include module that will define all those methods for you, using the mixin pattern that I provided earlier.  Within your class definition, you must define BOOLEAN_CLASS as the name of your class (since Synergy/DE does not, as of version 9.1.5, offer any compile-time symbol for the class under compilation), then include Boolean.dbl.  The generated methods will call a member method named “truth” to determine whether your object is true or not — so you need to supply just that one routine.  For example:

public class myclass
.define BOOLEAN_CLASS myclass
.include "Boolean"

method truth, boolean
proc
    mreturn whatever_makes_me_true
endmethod

endclass

Given the code above, you can use an instance of myclass in any boolean expression except one in which the other operand is a member of a different class.  In the latter case, you still have to anticipate the operand mix and either add your own operators or invoke a member of the other class that returns a primitive instead.

 

 

 

Posted in SynergyDE | 2 Comments » RSS 2.0 | Sphere it!

Functional “if” for Synergy/DE

March 2nd, 2009 12:00:18 pm pst by Sterling Camden

Programmers who have used languages derived from C will be familiar with C’s ternary conditional operator:

 
test ? iftrue : iffalse
 
which tests test for truth and returns iftrue if it is true, or iffalse if it isn’t.  No such operator exists in Synergy/DE, and many Synergy/DE programmers are just as glad that it doesn’t.  If you’re used to an imperative style of programming, it feels a bit obscure.  But there are a couple of good reasons why you’d want this sort of capability.  For one, it can save you a temporary variable declaration, as in the following:
 
if (x > y) then
  which = x
else
  which = y
mymethod(which)
 
Wouldn’t it be nice if you could just say:
 
mymethod((x > y) ? x : y)
 
But by far the biggest need for a functional-style if is in macro definitions.  Synergy/DE macros can be very powerful, but they have at least one glaring weakness:  they are limited to a single program statement (or part of a statement).  That’s only because (a) there’s no way to continue a macro definition to the next line without also continuing its expansion, and (b) the only statement terminator in Synergy/DE is end-of-line.  Besides, the imperative style of the DIBOL if-then-else (i.e., the fact that it doesn’t return anything) means that as soon as you add a condition into a macro you can no longer use your macro as an expression.  For instance, trying to write the C “max” function as a macro leads to frustration:
 
.define max(val1, val2) if (val1 > val2) then val1 else val2
 
This doesn’t work at all, because within the conditional, val1 and val2 must resolve to expressions, while in the “then” and “else” clauses they’re expected to be imperative statements.  And even where expressions can be used as statements (method invocations, for instance), you still can’t assign the result.
 
Until now.
 
The fif macro
 
The code below includes a “fif” macro (for Functional If), defined in fif.def, and code to support it in fif.dbl.  To use it, include fif.def at the top of your source file, and then you can use the syntax:
 
fif(test, iftrue, iffalse)
 
So you can write the “max” and “min” macros, for instance, as follows:
 
.define max(val1, val2) fif(val1 > val2, val1, val2)
.define min(val1, val2) fif(val1 < val2, val1, val2)
 
Caveats
  • Because this macro must call a method to do its work, all of the arguments will be evaluated once.  This is unlike the “if” statement, where only one of the “then” or “else” clauses gets evaluated.
  • This obviously involves more overhead than a simple if statement.  Use only where functional syntax is helpful — but remember that programmers are more expensive than CPU cycles, unless the code is executed very frequently.
  • The types for val1 and val2 must be compatible.  For those purposes, all object classes are compatible with one another — but there are rules for primitive types:  integer and decimal aren’t compatible (you need to convert one of them), but a decimal literal without precision will get converted to integer automatically if the other parameter is integer.  Alphanumeric and string are also compatible.
  • The return value will be one of the following, depending on the types of the values passed:  decimal, integer, alphanumeric, @Var, or object.  String arguments map to alphanumeric (unless the other argument is some other class of object).  All other classes map to object, so you’ll probably need to cast the result where non-primitive types are involved.

Implementation

In order to convert the multi-line, imperative DIBOL “if” statement into an expression, we have to use a function of one form or another.  Here’s where the static type system of Synergy/DE gets in our way — there is no way to designate a single function or method that can return any type.  Furthermore, bare functions cannot return objects (only primitive types), so we’re stuck using a static method.  But that actually works to our advantage, because we can use parametric polymorphism to define a separate version of our method for each argument/return type.

You’ll see in fif.dbl that I saved myself a bunch of typing (hah) by including the “Test” method’s code four times, defining the type for each inclusion.  I also used .ifndef to include the outer code on the first pass.  This is a trick I learned from Ken Lidster.  It’s not all that readable, but it’s certainly useful here.  Use cautiously, though, where noobies may tread.

You could add a .include for other types, if you have specific classes that you use frequently.  That would save you the trouble of casting the return value from the object (@*) version of the method in those cases.

The include file (fif.def) merely imports this code and defines a macro to call the Fif_.Test method.  The macro simply reduces syntactic weight — you could call the method directly, but I think “fif” is more readable than “Fif_.Test”.

Tests

The file test_fif.dbl provides some simple (but not comprehensive) tests for fif, using assertions.  It tries out the various types and automatic conversions.  See the comments in that file for details.

bld.bat contains the commands to build test_fif.dbr on Windows and Unix platforms.  ‘dbr test_fif’ to run it, and the tests succeed if you only get a STOP message.

comments.add(fif(you.liked(this), new Compliment(), new Flame()))

UPDATE 2009-04-22: Changed the macro definition to allow nesting of fifs.
UPDATE 2009-04-22: Added implicit support for Var
 
 
 

Posted in SynergyDE | 3 Comments » RSS 2.0 | Sphere it!

Sudoku in JavaScript

February 6th, 2009 12:09:27 pm pst by Sterling Camden

I’ve often found that one of the best ways to learn how to do things in a programming language is to attempt to write an interactive game.  My daughter got me hooked on Sudoku, and I thought to myself “this should be a pretty trivial algorithm to implement in JavaScript.”  I’ve been working on it a few minutes at a time in between other projects ever since.  This morning I finally put a lid on it.  You can download the code below, and you can see it in action and play it as often as you like.

The Game

This version of Sudoku presents the usual 9 x 9 grid which is divided into nine 3 x 3 regions.  The object of the game is to fill in the grid with numbers from 1 to 9, such that each row, column, and region contains one and only one instance of each number.  To get you started, each game provides a number of “givens” — cells that already have their value filled in, and which you cannot change (indicated by a gray background).  By default, this version randomly provides 36 givens — without any attempt to evenly distribute them across rows, columns, or regions.

When you enter a number in a cell, if the value conflicts with another cell in the same row, column, or region, then the background of both cells will be changed to red (unless the other cell is a given, in which case it remains gray).  If a cell has two or more conflicts, a darker shade of red is used, up to four conflicts — beyond which point the color remains the same.  If you try to enter a value in the cell other than the numbers 1 through 9, the cell is cleared.  You can also clear the cell by pressing “delete”.  When a cell is focused, the arrow keys can be used to navigate to the next cell in the specified direction, with wrap-around.  Tab and Shift-tab follow the browser’s defined behavior for navigating input controls — the cells are defined in column order within rows, followed by the buttons.

The “Hint” button provides another given, randomly choosing an empty cell to fill in.  If there are no empty cells remaining, an alert “Can’t fill in anything!” will be displayed.

The “Solve” button will reveal the entire puzzle.  Note that it may be possible to solve a Sudoku in more than one way for the given values, but this button reveals the solution that was generated when the puzzle was created.

The “New” button generates a new puzzle.

You can use your browser’s “Zoom” or “Text size” functions to resize the puzzle.

Browser-specific differences

This game was tested with the following browsers, and revealed a few minor issues where noted:

  • Google Chrome 1.0.154.46
  • Mozilla Firefox 3.0.6
  • Safari 3.2.1
  • Internet Explorer 7 & 8 – Sizing the browser small enough causes the cells to misalign.  Corners on the container aren’t rounded.
  • Opera 9.25 – border width differences used to delineate the regions are not honored, and neither are the rounded corners on the container.
  • Opera Mini Simulator- same issues as Opera.

I’ve attempted to make this game mobile-friendly, but of course it only works on platforms that support JavaScript and CSS.

Styling

All styling for this game has been separated out into the file sudoku.css.  You can modify this or provide your own stylesheet to change the effects for the following class names (note that more than one class name may be applied to an individual cell):

  • sudoku – the container for the game (defined in sudoku.htm)
  • sudokuButton – the control buttons
  • sudokuCell – every cell in the puzzle
  • sudokuGiven – a cell whose value is given
  • sudokuCorrected – a cell whose value has been corrected by pressing the “Solve” button
  • sudokuConflict0 – a cell whose value does not conflict with any other cells
  • sudokuConflict1 – a cell whose value conflicts with one other cell
  • sudokuConflict2 – a cell whose value conflicts with two other cells
  • sudokuConflict3 – a cell whose value conflicts with three other cells
  • sudokuConflict4 – a cell whose value conflicts with four or more cells
  • sudokuRegionTop – a cell that is along the top edge of a region
  • sudokuRegionBottom – a cell that is along the bottom edge of a region
  • sudokuRegionLeft – a cell that is along the left edge of a region
  • sudokuRegionRight – a cell that is along the right edge of a region
  • info – the section that contains the link to this page

Using the code

This code has been designed to play well with others.  It introduces only one global symbol, the name of the Sudoku function.  However, it does use the jQuery framework (included in the download).

You can instantiate a Sudoku puzzle within any HTML element using the following code:

new Sudoku(elem, ngivens)

where elem is the DOM Element that will contain the puzzle, and ngivens is the optional number of givens to display (default = 36).

Algorithm

For every new puzzle, the script generates a completed solution and then randomly chooses the location of the givens to reveal.  The algorithm for generating the puzzle can probably be made more elegant, but it works.  The generatePuzzle() function is called recursively, beginning with the first cell and progressing to the last one.  At each cell, the numbers 1 through 9 are attempted in a random order until no conflicts are found and we successfully recurse through the rest of the puzzle.  Thus, if no solution can be found for a given combination up to this point, we backtrack through the recursion and try something else.  This could certainly be optimized — for instance, we could keep track of unused values within the current row and only try those.  But I’m not certain that the benefit of that optimization wouldn’t be offset by the additional array manipulation required.  Ideally, this is a problem for graph theory — perhaps one day I’ll attack it from that angle.

For checking conflicts, the script maintains arrays of arrays:  an array of rows, an array of columns, and an array of regions.  Each element of these arrays is an array of DOM elements:  the “input” element for each cell.  Each of those elements also has back-linked properties for its row, column, and region.  Thus, when the “onchange” event occurs for a cell, we can easily check it against the other cells that might conflict.

For more details, see the comments in the code.

UPDATED 2009-02-17 to add styling for cells corrected by “Solve”.  Also added readme.txt and license.txt.

Posted in CSS, Javascript, Web, Wildly popular | 7 Comments » RSS 2.0 | Sphere it!

My apologies for your not being able to comment

January 8th, 2009 2:45:30 pm pst by Sterling Camden

I made the classic web developer mistake:   “It’s just a simple change, what could possibly go wrong?”  So I didn’t test it thoroughly before launching it on my unsuspecting readers.

For about a day, the “Add comment” button on posts here and at Chip’s Quips and Camden Software would only work if you were already subscribed to email notifications for the post in question.  My sin was particularly egregious, because you would only discover the impotence of that button after you’d already typed in your masterfully crafted response and were ready to submit it.  Shame on me.

Details:  I added a feature to allow you to subscribe to email notifications without leaving a comment, using a function that comes built into the Subscribe to Comments plugin for WordPress.  That function creates the necessary form for submitting those subscriptions, and I inadvertently placed it within the <form> tags for the comment form (thanks to the exceptionally cluttered version of comments.php that comes with the Brian’s Threaded Comments plugin).  When a form contains another form, the JavaScript method “submit” does not exist for that element, and that’s what the “Add comment” button calls when clicked.  I found my error using the very handy JavaScript debugger in Google Chrome.

But it’s all right now (in fact it’s a gas).  I also modified the comment form such that the email subscription checkbox is now in the tabbing order.  The Subscribe to Comments plugin adds this checkbox, but does not specify a “tabindex” attribute.  So I hacked my copy of the plugin and my copy of the comments.php that comes with Brian’s Threaded Comments to move this checkbox to before the “Add comment” button, both visually and in the tabbing order.  Thanks to apotheon for complaining about this, or I would never have noticed (being the author of each post, I never see the checkbox).  I left a comment on the Subscribe to Comments home page requesting the ability to specify a tabindex for the checkbox, but in the mean time I’m posting my modified version here, along with my modified comments.php.

 

Posted in Javascript, PHP, Web, WordPress | 5 Comments » RSS 2.0 | Sphere it!

Licensing now with even more license

December 9th, 2008 2:57:42 pm pst by Sterling Camden

I have changed the licensing on this site’s content from the CDD CopyWrite license to the newer, less restrictive Open Works License (OWL).  Essentially, this license allows you to do anything you want with the content — even include it within a product whose license is more restrictive.  It merely serves to protect my right (and yours) to reuse this code from any license claim made by anyone else who might use this content within their product.

I have included a copy of the license in text form within every download, except those that were provided by others or were already licensed under other terms.

Leave questions or comments below.

Tags: