In many programming languages, bracket-notation is commonly associated with array subscripting. For instance, A[i] is a left-value in C that refers to array-cell i in the array referred to by A. There is support in ATS for overloading brackets with multiple function names so that bracket-notation can be employed to call these functions, resulting in code that reads like some form of subscripting. It is expected that this style of calling functions can, sometimes, make the code written in ATS more easily accessible.
Let us now see a simple example of bracket-notation in overloading. In the followng code, a linear abstract type lock is introduced together with two functions:
// absvtype lock(a:vt@ype) // extern fun{a:vt0p} lock_acquire(!lock(a)): a extern fun{a:vt0p} lock_release(!lock(a), a): void //
Suppose that we now introduce the following overloading declarations:
With these declarations, the following code typechecks:// val mylock = $extval(lock(int), "mylock") // val x0 = mylock[] // = lock_acquire (mylock) val () = mylock[] := x0 // = lock_release (mylock, x0) //
In ATS, bracket-notation is already overloaded with functions performing list-subscripting, array-subscripting and matrix-subscripting, and it can also be used to access and update a given reference.
Please find on-line the entirety of the code presented in this chapter.