# Image-Based development and Interactive Experience

**URL:** https://racket.discourse.group/t/image-based-development-and-interactive-experience/3679
**Category:** General
**Created:** [April 7, 2025, 8:09am UTC](https://racket.discourse.group/t/image-based-development-and-interactive-experience/3679 "2025-04-07T08:09:06Z")
**Posts on this page:** 1
**Showing post:** 18

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [May 6, 2025, 11:37am UTC](https://racket.discourse.group/t/image-based-development-and-interactive-experience/3679/18 "2025-05-06T11:37:26Z")

</div>

@ungsams

> Is there something that allows to recompile just specific parts of the code without re-compiling everything?

Here is a proof-of-concept.  
Put the following in a file "defun.rkt".  
Whenever you expect you will need to redefine a function, use `defun` instead of `define`.  
Then in the repl, you can use `defun` to redefine the function.  
Other functions referring to the function will pick up the new definition.

`defun.rkt`

```scheme
#lang racket
(provide defun)

(define globals (make-hasheq))

(define-syntax ref
  (syntax-rules ()
    [(_ref id)
     (hash-ref globals 'id)]))
     
(define-syntax defun
  (syntax-rules ()
    [(_defun (id arg ...) body0 body ...)
     (begin
       (define (id arg ...)
         ((ref id) arg ...))
       (hash-set! globals 'id (λ (arg ...) body0 body ...)))]
    [(_defun (id arg ... . rest-args) body0 body ...)
     (begin
       (define (id arg ... . rest-args)
         (apply (ref id) (list* arg ... rest-args)))
       (hash-set! globals 'id (λ (arg ... . rest-args) body0 body ...)))]))

```

An Example:  
`example.rkt`

```scheme
#lang racket
(provide fact foo)
(define (fact n)
  42)

(define (foo n)
   (fact n))

```

Running this gives us a repl.

```scheme
> (fact 5)
42
> (foo 5)
42
> (defun (fact n) (if (= n 0) n (* n (fact (- n 1)))))
> (fact 5)
120
> (foo 5)
120
> (defun (fact n) 7)
(foo 5)
7

```

This proof of concept just uses a global "namespace" for all functions defined with `defun`.  
The same technique can be used if one needs "packages" in Common Lisp sense.

---

_[View the full topic](https://racket.discourse.group/t/image-based-development-and-interactive-experience/3679)._
