ASH redefinitions in nested scopes considered dangerous.

Veracity

Developer
Staff member
ASH symbol names are case-insensitive. I guess I knew this, but it still confuses me, on occasion. You can end up redefining things without knowing you are doing so.

Code:
static slot OFFHAND = $slot[ off-hand ];
item offhand = equipped_item( OFFHAND );
equip( OFFHAND, $item[ none ] );
yields

Code:
[color=red]Variable offhand is already defined (redef.ash, line 2)[/color]
When juxtaposed like that, you can see it. But what about this one?

Code:
static slot OFFHAND = $slot[ off-hand ];
{
    item offhand = equipped_item( OFFHAND );
    equip( OFFHAND, $item[ none ] );
}
yields

Code:
[color=red]Function 'equip( item, item )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (redef.ash, line 4)[/color]
That had me staring and going "Huh?" for a long time before I figured it out.

You are allowed to redefine symbols originally defined in an outer scope. Java does not allow that, but ASH does. I wonder why we decided that?
And in this case, we are redefining a slot variable with an item variable.

When we look for function redefinitions, it's similarly all based on parameter lists, not return value.

I'm not sure what change I am proposing - if any - but since that second example confused even me, would could be done to clarify things?
What scripts would break if nested redefinitions were not allowed?
What scripts would break if symbols were case-sensitive?
 

Veracity

Developer
Staff member
We have the "since" directive. What if we had

pragma DIRECTIVE[,DIRECTIVE]*;

Where DIRECTIVE might be WORD or WORD=VALUE.

We could implement compiler modifications like those I mentioned that are not simply adding to the language or fixing bugs but are changing how the language is processed. Scripts can opt in, if they are willing to adapt. Or opt out, if they are not ready to adapt, although they'd have to add one line at the top.
 
Top