Getting Squeak to write Squeak (a feeble effort at LISPY stuff)

John Maloney JohnMaloney at earthlink.net
Mon Nov 17 16:09:57 UTC 2003


Mike,

As Ned pointed out, and as you suspected yourself, the problem you're having
is one of context. You were trying to evaluate an expression with an assignment
to a variable such as "c" in a context where that varible did not exist as either
a local variable, an instance variable, or a workspace binding.

One simple thing you could do is to use a capital letter variable to indicate that
it should be a global variable. You need to first create that variable by assigning
to it in a workspace. For example, you could do:

   A _ nil.

to create the global variable "A", then

  Compiler evaluate:: 'A _ 17'

An alternative is to declare you variables as locals in the expression
to be evaluated like this:

  Compiler evaluate: '| a b | a _ 6. b _ 7. a * b'

It's true that when you evaluate expressions in a Workspace, it maintains
a set of variable bindings local to that workspace. I looked at trying to
hand the compiler my own instance of a Workspace but it got messy.

It sounds as though you'll need to create new variables dynamically,
and you're not sure how many you might need. In that case, you
might be better off putting all your bindings into a big array and
referring to variables by index. Or use a dictionary and refer to
variables values with expressions like "dict at: 'a'". But most likely
there's a simpler way to implement your decision tree in Smalltalk
that wasn't an option in LISP because it lacks objects.

	-- John





More information about the Squeak-dev mailing list