[Grace-core] RFC: Compile-time constants

Michael Homer mwh at ecs.vuw.ac.nz
Sun May 4 19:01:29 PDT 2014


On Mon, May 5, 2014 at 12:10 PM, Timothy Jones <tim at ecs.vuw.ac.nz> wrote:
> On 03/05, Michael Homer wrote:
>> On Sat, May 3, 2014 at 12:43 AM, Timothy Jones <tim at ecs.vuw.ac.nz> wrote:
>> > On 02/05, Michael Homer wrote:
>> >> It seems like these are what you want for inheritance ("definitively
>> >> static") too, so it's worth factoring in what that needs as well.
>> >
>> > I disagree (with the spec, I suppose) that this should even be a thing. An
>> > invalid inheritance chain should be a runtime error. If a dialect wants to check
>> > this (as the type checking dialect should) then it can, and in that context
>> > "definitively static" means whatever the dialect wants it to mean (presumably
>> > whether it can see the definition site).
>> Where does identifier resolution occur in this system?
>
> Runtime, at the call site. I understand that the C compilation prevents this
> from happening though.
So this complete program:
  method greet {
    def hello = "Hello!"
    print(ehllo)
  }
raises no errors?

How is this:
  var useString := true
  method foo {
    if (useString) then {
      object {
        def greeting = "Hello"
      }
    } else {
      object {
        def succ = { x -> x + 1 }
      }
    }
  }
  object {
    inherits foo
    print(greeting)
  }
  useString := false
  object {
    inherits foo
    print(succ.apply 2)
  }
?

How far does this go towards, say, Ruby's instance_eval? How dynamic
is the scoping you're thinking of?
>> >> - Can it be inherited?
>> >
>> > No, for similar reasons as 'let'.
>> Hang on, I can see how there's a case for lets to be top-level-only,
>> but methods? How is this code:
>>   method foo {
>>     object {
>>       method x is public, static { 1 }
>>       let y = x + 1
>>     }
>>   }
>>   object {
>>     inherits foo
>>    }.x
>> ?
>
> I'm not sure what you're asking here. I answered this as 'can it be overriden',
> so we might be on a different page here.
Is that code a static or dynamic error? Can I access x on the
subobject? If I let that to a static binding, can I access x in static
context?
>> On the other hand, if it can be inherited, can it refer to self?
>
> If self is static, I guess.
If the method can be inherited, we don't know which object "self" will
be at the execution. Does that matter?
>> >> - What is it allowed to return?
>> >
>> > A request for another static value, or a fresh object (like a brand -- this is
>> > why you can annotate a class as static).
>> These are a lot like the inheritance rules.
>>
>> Can you inherit from a static method?
>
> Do you mean if the inheriting object is also static?
I mean is this valid code:
  method foo(x) is static {
    object {
      method blah { x }
    }
  }
  method bar is static {
    foo(1)
  }
  object {
    inherits bar
  }
? I assume it can, but I'm not clear on just how if at all that
interacts with staticness.
-Michael


More information about the Grace-core mailing list