Sunday, November 12, 2006

Taming variables

I developed some new tools which perform static analysis of variable usage.

Factor's variables are dynamically scoped and very simple, there is a global namestack holding hashtables. Nesting a scope pushes a hashtable on the stack, variable lookups search up the namestack, and variable assignments store the new value in the topmost hashtable on the namestack.

The infer word has been replaced with an infer. word which gives variable usage information obtained by statically analyzing the code. Those in the know will recognize that this is a ripoff of InterLisp's MASTERSCOPE package. Here is an example:
  SYMBOL: x
[ 3 * x set ] infer.

* Stack effect:
( object -- )
* Writes free variables:
x

But if you wrap this in a with-scope, the assignment is lost as soon as the scope ends and there is no observable side effect:
  [ [ 3 * x set ] with-scope ] infer.
* Stack effect:
( object -- )

On the other hand, reading a variable from a nested scope might go up a scope if the variable is not defined, and so it can be observed from the outside:
  [ [ x get ] with-scope ] infer.
* Stack effect:
( -- object )
* Reads free variables:
x

But if you assign the variable in scope first, then we cannot observe the read:
  [ [ 5 x set [ x get ] with-scope ] with-scope ] infer.
* Stack effect:
( -- object )

Now, of course because this is built on stack effect inference, everything works if you have a word which indirectly calls get or set.

It even understands combinators, for example this one that applies 2 * to the value of x:
  [ x [ 2 * ] change ] infer.
* Stack effect:
( -- )
* Reads free variables:
x
* Writes free variables:
x

No special support for inferring change is defined, it just looks at the definition of change;
: change ( variable quot -- ) 
>r dup get r> rot slip set ; inline

Finally, it has special support for recording words which directly read and write globals:
  [ [ 5 x set-global ] with-scope ] infer.
* Stack effect:
( -- )
* Writes global variables:
x

Saturday, November 11, 2006

strongForth 1.1 released

strongForth is a statically-typed low-level Forth-like language. This release adds a floating point wordset. Right now it only runs under DOS (its actually a very old project), hopefully it will be ported to 32-bit Unix platforms at some point in the future.

Insane Cocoa bug

So it seems the frame method of NSWindow returns some client-side value, which is updated when the window receives events notifying it that it has been moved or resized. Which is all very well, but it seems that if you move the window around while it is not responding, then the frame method returns the old value! This is absurd.

It means that for example if you reload some files in the Factor UI listener, which then causes a 10-second recompile, during which you move the window, then mouse handling is completely screwed up after Factor starts responding again.

Does anybody know if there is a way to query the window system for the window's actual location?

Update: This only happens under certain circumstances. Very weird. I'll try to narrow it down.

Update 2: Actually it is pretty easy to reproduce. Start Factor and type 30000000 [ ] times (or anything else which takes several seconds to run). Then move the listener window around for a few seconds, then switch to another application. When Factor is done, switch back, and it will not respond to clicks because it will think the mouse location is different than what it actually is.

Friday, November 10, 2006

Factor 0.86 is ready

Factor 0.86 is now ready for release. As a few people on the mailing list have requested, I'm making this announcement before actually releasing Factor so that the code in darcs can get some extra testing. I'll be testing the X11 UI backend and AMD64 compiler backend tomorrow.

Thursday, November 09, 2006

You know you're too lazy to learn better tools when...

You try to justify the flaws in what you currently use on the basis that these flaws, while forcing you to do a lot more work than necessary and increasing turn-around time, encourage you to "design better".

Sad people

Some people are so blinded by Java zealotry that they choose to make a weblog dedicated to personal attacks on comp.lang.lisp posters.

Why Java zealotry you ask? I think a trait unique to Java programmers is to go antagonize other language communities, pretending to be interested in learning that language, when in fact they're just looking for excuses not to learn, and to criticize.

XML parser now supports namespaces

Daniel Ehrenberg has updated the contrib/xml module to support XML namespaces, with XML-RPC support coming up next. Dan used to be active in the Factor community six months or so ago, and now he's back, which is great. Unlike some open source projects, Factor contributors seem to stick around for a long time. When I was working on jEdit, a big problem was people throwing a few patches and plugins over the fence, then disappearing a week later...