LARA

Global Function Pointers

To pass global (static) functions, we simply pass their addresses

We need to know the calling convention for all function values that can be called

var exlaim = "!!!"
 
def simpleNotify(msg : String) = {
  println(msg)
}
def noisyNotify(msg : String) = {
  beep(1024)
  popUp(msg)
  beep(2048)
  popUp(msg + exclaim)
  beep(512)
}
def alarm(time : Int, notify : msg => unit) = {
  if (currentTime==time) {
    notify("Wake up!")
  }
}
alarm(0700, simpleNotify)
alarm(0800, noisyNotify)

When 'notify' is called in 'alarm', it will be passed string argument on stack

  • it knows how to access global variables

This works in e.g. C and Pascal