# How to run REPL in command-line Racket with another language?

**URL:** https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848
**Category:** Questions & Answers
**Created:** [March 30, 2023, 6:41pm UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848 "2023-03-30T18:41:00Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)
#### Post date: [March 30, 2023, 6:41pm UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/1 "2023-03-30T18:41:00Z")

</div>

In DrRacket I can simply set #lang basic-demo-3, then in REPL say

```scheme
> let x = 5
> print x
5

```

In command line I tried

```scheme
racket -I basic-demo-3

```

but it doesn't work.

```scheme
$ racket -I basic-demo-3
Welcome to Racket v8.7 [cs].
> let x = 5
; let: undefined;
; cannot reference an identifier before its definition
; in module: top-level
; [,bt for context]
> ; x: undefined;
; cannot reference an identifier before its definition
; in module: top-level
; [,bt for context]
> ; =: undefined;
; cannot reference an identifier before its definition
; in module: top-level
; [,bt for context]
> 5
>

```

---

<div class="post-metadata">

### Author: ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)
#### Post date: [March 30, 2023, 7:55pm UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/2 "2023-03-30T19:55:40Z")

</div>

My understanding is that using a non sexp reader in the command-line REPL is a relatively new feature ([https://docs.racket-lang.org/reference/interaction-info.html](https://docs.racket-lang.org/reference/interaction-info.html), added in Racket 8.3). So far, Rhombus ([https://github.com/racket/rhombus-prototype/blob/master/rhombus/private/runtime-config.rkt](https://github.com/racket/rhombus-prototype/blob/master/rhombus/private/runtime-config.rkt)) seems to be the only language that uses this feature.

Chance is that this basic-demo-3 doesn't support the command-line REPL.

Note that DrRacket REPL has the capability to support a non sexp reader if the language cooperates. So you might want to try that.

---

<div class="post-metadata">

### Author: ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)
#### Post date: [March 31, 2023, 3:38am UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/3 "2023-03-31T03:38:08Z")

</div>

But it supports: [Beautiful Racket: Closing the loop: basic](https://beautifulracket.com/basic-3/the-repl.html#a_aEkiA)

> <https://github.com/mbutterick/beautiful-racket/blob/b0d133f4ba4149ea506d8b0dbd3845c915efdd06/beautiful-racket-demo/basic-demo-3/setup.rkt#L19>

> Note that DrRacket REPL has the capability to support a non sexp reader if the language cooperates. So you might want to try that.

The same code works in DrRacket, but I cannot use DrRacket in text mode.

---

<div class="post-metadata">

### Author: ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)
#### Post date: [April 15, 2023, 10:21am UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/4 "2023-04-15T10:21:36Z")

</div>

> So far, Rhombus

Could you show, how to user Rhombus in text-mode Racket?

---

<div class="post-metadata">

### Author: ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)
#### Post date: [April 17, 2023, 2:10pm UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/5 "2023-04-17T14:10:32Z")

</div>

You can run `racket -I rhombus` after installing the `rhombus-prototype` package.

---

<div class="post-metadata">

### Author: ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)
#### Post date: [August 26, 2023, 7:01pm UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/6 "2023-08-26T19:01:04Z")

</div>

I have found. One need to write `configure-expand` submodule for console Racket.

> <https://github.com/racket/rhombus-prototype/blob/4835965cf8d765a1fcc4b0acb48f5121aa27c8e6/rhombus/main.rkt#L20>

---

<div class="post-metadata">

### Author: ![wurmli](https://avatars.discourse-cdn.com/v4/letter/w/dbc845/32.png) [@wurmli](https://racket.discourse.group/u/wurmli)
#### Post date: [August 27, 2023, 3:21am UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/7 "2023-08-27T03:21:56Z")

</div>

If you want to use the "basic" language from Beautiful Racket in the command-line REPL, you need to require "setup.rkt" and "elements.rkt" and provide the bindings of "elements.rkt" as well as #%top-interaction #%app #%top #%datum to the expander macro "b-module-begin" in "expander.rkt". If you change the xrepl to use readline, you can enter basic expressions in the REPL, have them be evaluated and use REPL-history. Coloring doesn't work.

```scheme
; "expander.rkt"

#lang br/quicklang
(require "struct.rkt" "run.rkt" "elements.rkt" "setup.rkt")
(provide (rename-out [b-module-begin #%module-begin])
         (all-from-out "elements.rkt"))

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([((b-line NUM STMT ...) ...) #'(LINE ...)]
       [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
       [(VAR-ID ...) (find-property 'b-id #'(LINE ...))]
       [(IMPORT-NAME ...)
        (find-property 'b-import-name #'(LINE ...))]
       [(EXPORT-NAME ...)
        (find-property 'b-export-name #'(LINE ...))]
       [((SHELL-ID SHELL-IDX) ...)
        (make-shell-ids-and-idxs caller-stx)] 
       [(UNIQUE-ID ...)
        (unique-ids
         (syntax->list #'(VAR-ID ... SHELL-ID ...)))])
    #'(#%module-begin
       (module configure-runtime br
         (require basic/setup)
         (do-setup!))
;;;;;;;;;;;;;;;;; this is added! ;;;;;;;;;;;;;;;;;;;;;;;
       (require
         "setup.rkt"
         "elements.rkt")
       (provide
        (all-from-out "elements.rkt")
        #%top-interaction #%app #%top #%datum)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       (require IMPORT-NAME) ...
       (provide EXPORT-NAME ...)
       (define UNIQUE-ID 0) ...
       (let ([clargs (current-command-line-arguments)])
         (set! SHELL-ID (get-clarg clargs SHELL-IDX)) ...)
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (parameterize
           ([current-output-port (basic-output-port)])
         (void (run line-table))))))

(define (get-clarg clargs idx)
  (if (<= (vector-length clargs) idx)
      0
      (let ([val (vector-ref clargs idx)])
        (or (string->number val) val))))

(begin-for-syntax
  (require racket/list)

  (define (unique-ids stxs)
    (remove-duplicates stxs #:key syntax->datum))

  (define (find-property which line-stxs)
    (unique-ids
     (for/list ([stx (in-list (stx-flatten line-stxs))]
                #:when (syntax-property stx which))
       stx)))

  (define (make-shell-ids-and-idxs ctxt)
    (define arg-count 10)
    (for/list ([idx (in-range arg-count)])
      (list (suffix-id #'arg idx #:context ctxt) idx))))

```

```scheme
wurmli@cirrus7:~$ racket -I basic/sample
Welcome to Racket v8.10 [cs].
1
2
3
> div(7,6)
1.1666666666666667
> let z = 99
> z
99
> 

```

---

<div class="post-metadata">

### Author: ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)
#### Post date: [August 27, 2023, 3:40am UTC](https://racket.discourse.group/t/how-to-run-repl-in-command-line-racket-with-another-language/1848/8 "2023-08-27T03:40:30Z")

</div>

Nice catch! I was wrong about this. I see now that `current-interaction-info` is really about “syntax coloring and indentation support” in the REPL, but the REPL functionality doesn’t require it. Using `configure-runtime` suffices.
