Pointers and references: Difference between revisions

Content added Content deleted
Line 927: Line 927:
p := k + 1; (* set the value inside to a new value *)
p := k + 1; (* set the value inside to a new value *)
</lang>
</lang>

=={{header|Racket}}==

As in many other functional languages, Racket doesn't have pointers to its own values. Instead, Racket uses "boxes" that are similar to "ref" types in *ML:
<lang racket>
#lang racket

(define (inc! b) (set-box! b (add1 (unbox b))))

(define b (box 0))
(inc! b)
(inc! b)
(inc! b)
(unbox b) ; => 3
</lang>

In addition, Racket has a representation of traditional C pointers as part of its FFI, but this is intended only for dealing with foreign code.


=={{header|Tcl}}==
=={{header|Tcl}}==