[racket] rackunit errors when trying to test string-math-eval

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Aug 20 19:24:50 EDT 2013

1. eval does not work as you imagine and possibly know from old Lisps and/or Lisp-like languages (say JS). I have fixed the code and added two links. 

2. I recommend a small change to your testing submodule. See below. 

(define (string-eval-math s)
      (tokenize (open-input-string s)))))
;; see http://docs.racket-lang.org/guide/eval.html?q=eval
;; and http://blog.racket-lang.org/search/label/eval

(define ((string-with-variable var-s val) s)
   (regexp-replace* (regexp var-s) s (number->string val)) 

(module+ test
  (check-equal? (string-eval-math "1+1") 2))

On Aug 20, 2013, at 5:15 PM, Andrews, Kyle (KC) wrote:

> Hi,
> I'm trying to create unit tests for some code that parses simple infix mathematical expressions in strings.  Despite my informal testing in the REPL showing my function 'string-math-eval' works for what I'm trying to use it for, when I try making tests using check-true or check-equal? from rackunit in a sub-module I get the error:
>  +: unbound identifier;
>   also, no #%app syntax transformer is bound in: +
> ; an example of a test which gives the error
> (module+ test
>  (check-true (= (string-eval-math "1+1") 2)))
> I've attached my code to this message.  What is causing this to work in the main module but not in the sub-module, and in general how would I go about fixing problems like this in the future?
> Regards,
> Kyle Andrews
> <string.rkt>____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

Posted on the users mailing list.