Skip to content

Commit c693eb6

Browse files
committed
rename ref.modify -> ref.access
1 parent 199a5ad commit c693eb6

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

kklib/include/kklib/ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static inline kk_unit_t kk_ref_set_borrow(kk_ref_t r, kk_box_t value, kk_context
8484
}
8585

8686
// In Koka we can constrain the argument of f to be a local-scope reference.
87-
static inline kk_box_t kk_ref_modify(kk_ref_t r, kk_function_t f, kk_context_t* ctx) {
87+
static inline kk_box_t kk_ref_access(kk_ref_t r, kk_function_t f, kk_context_t* ctx) {
8888
return kk_function_call(kk_box_t,(kk_function_t,kk_ref_t,kk_context_t*),f,(f,r,ctx),ctx);
8989
}
9090

lib/std/core/types.kk

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,22 @@ pub inline extern ref/(!) : forall<h,a,e> ( ref : ref<h,a>) -> <read<h>|e> a wit
355355
cs inline "#1.Value"
356356
js inline "#1.value"
357357

358-
// Modify the value of a reference.
359-
// This is especially useful when the reference contains a vector, because
358+
// Access the value of a reference, by evaluating a function with the reference as a local-var.
359+
// Assigning to this var within the block using `:=` will modify the underlying reference.
360+
//
361+
// e.g. `counter.access(fn(i) { i := i + 1 })`
362+
//
363+
// This function is especially useful when the reference contains a vector, because
360364
// getting the vector into a local variable and then setting it back into the reference later
361365
// would mean that we hold on to a copy (and we can't update the vector in place then!).
362366
// In contrast, this function passes the ownership to the given function.
367+
pub inline extern access : forall<h,a,b,e> ( ref : ref<h,a>, f : forall<s> local-var<s,a> -> <local<s>|e> b) -> <read<h>,write<h>|e> b with(hdiv<h,a,e>)
368+
c "kk_ref_access"
369+
js inline "((#2)(#1))"
370+
371+
// Deprecated: alias for `access`
363372
pub inline extern modify : forall<h,a,b,e> ( ref : ref<h,a>, f : forall<s> local-var<s,a> -> <local<s>|e> b) -> <read<h>,write<h>|e> b with(hdiv<h,a,e>)
364-
c "kk_ref_modify"
373+
c "kk_ref_access"
365374
js inline "((#2)(#1))"
366375

367376
// If a heap effect is unobservable, the heap effect can be erased by using the `run` fun.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fun main() {
22
val r = ref(0)
3-
r.modify fn(l) {
3+
r.access fn(l) {
44
l := 1
55
}
66
(!r).println
7-
}
7+
}

0 commit comments

Comments
 (0)