How do i test my language

I made a language in racket and i don't know how to test it

Here's my directory:

langtest/
lang/
reader.rkt
main.rkt

2 Likes

Hi, @Mrdev88.

I am still learning how to test effectively myself, but a method I have found to be quite helpful, is to go and look at what others have done.

As an example, I am currently interested in reader macros myself, so I went and looked up some of the sources for meta-languages (which is related but unimportant, really).

AlexKnauth/exact-decimal-lang: a racket lang-extension that reads decimals as exact rationals by default

You'll see in @AlexKnauth's setup there, the tests live in a similar place to where they usually would in a Racket package, i.e. their own little directory, called for argument's sake, tests.

I hope this helps. Kudos on writing your own language! Be sure to share if you do get it working.

1 Like

I tried installing it to test it out but i got this error:

Error
lang/reader.rkt:7:1: module-reader: unbound identifier
  in: module-reader
  compilation context...:
   /Users/mahdiruiz1/Documents/DrRacket/circlecode/lang/reader.rkt
  location...:
   lang/reader.rkt:7:1
  context...:
   /Applications/Racket v8.16/collects/compiler/private/cm-minimal.rkt:700:0: compile-zo*
   /Applications/Racket v8.16/collects/compiler/private/cm-minimal.rkt:634:0: compile-zo*/cross-compile
   /Applications/Racket v8.16/collects/compiler/private/cm-minimal.rkt:450:15
   /Applications/Racket v8.16/collects/compiler/private/cm-minimal.rkt:436:12: build
   /Applications/Racket v8.16/collects/compiler/private/cm-minimal.rkt:407:0: maybe-compile-zo
   /Applications/Racket v8.16/collects/compiler/private/cm-minimal.rkt:210:0: compile-root
   /Applications/Racket v8.16/collects/compiler/private/cm-minimal.rkt:105:4

Here's my code:

Summary
main.rkt:

#lang racket

(provide (all-defined-out))
(require (for-syntax syntax/parse))

(define-syntax (begin-program stx)
  (syntax-parse stx
    [(_ body ...)
     #'(begin body ...)]))

(provide (rename-out [begin-program #%module-begin]))
reader.rkt:

#lang racket

(require syntax/module-reader)

(provide (all-from-out syntax/module-reader))

(module-reader "langtest/main")

The error:

lang/reader.rkt:7:1: module-reader: unbound identifier
  in: module-reader

says that on line 7 column 1 there is an identifier module-reader that is unbound.

In your code we see:

(module-reader "langtest/main")

Checking the docs for syntax/module-reader:

https://docs.racket-lang.org/syntax/reader-helpers.html#%28part._module-reader%29

we see no export named module-reader.