2020-02-20 12:43:52 +03:00
|
|
|
-- Emulation of first-class references.
|
|
|
|
|
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
|
|
|
|
|
--
|
|
|
|
|
-- This unit provides an implementation for first-class references emulation.
|
|
|
|
|
|
|
|
|
|
-- Creates a new reference cell with contents x
|
2020-01-20 03:38:43 +03:00
|
|
|
public fun ref (x) {
|
|
|
|
|
[x]
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 12:43:52 +03:00
|
|
|
-- Returns the contents of the cell x
|
2020-01-20 03:38:43 +03:00
|
|
|
public fun deref (x) {
|
|
|
|
|
x[0]
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 12:43:52 +03:00
|
|
|
-- Assigns a new value y into the cell x
|
2020-01-20 03:38:43 +03:00
|
|
|
public infix ::= before := (x, y) {
|
|
|
|
|
x[0] := y
|
|
|
|
|
}
|