# Call by reference

**URL:** <https://racket.discourse.group/t/call-by-reference/1665>\
**Category:** General\
**Created:** [January 26, 2023, 11:01pm UTC](https://racket.discourse.group/t/call-by-reference/1665 "2023-01-26T23:01:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![devosalain](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/devosalain/32/546_2.png) [@devosalain](https://racket.discourse.group/u/devosalain)\
**Post date:** [January 26, 2023, 11:01pm UTC](https://racket.discourse.group/t/call-by-reference/1665/1 "2023-01-26T23:01:33Z")

</div>

What do you think of following demo code demostrating call-by-reference.

```scheme
#lang typed/racket

( : addone : [Boxof Integer] -> Void )
(define addone
  (lambda (x)
    [begin
      (: ux : Integer )
      (define ux (unbox x))
      (set-box! x (+ 1 ux ))
      ]
    );lambda
  );define

(define abox (box 1))
(addone abox)
(define anumber (unbox abox))
(write anumber)

```

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [January 27, 2023, 12:30am UTC](https://racket.discourse.group/t/call-by-reference/1665/2 "2023-01-27T00:30:28Z")

</div>

I'd be inclined to format it like this...

```scheme
#lang typed/racket

(define (addone [x : (Boxof Integer)]) : Void
  (set-box! x (+ 1 (unbox x) )))

(define abox (box 1))
(addone abox)
(define anumber (unbox abox))
(write anumber)

```

Not sure if that's what you're asking.
