0

I followed the directions on the Rosette website to download rosette (https://docs.racket-lang.org/rosette-guide/ch_getting-started.html). It seems that I can run this program and get an output error free.

    #lang rosette/safe

; Compute the absolute value of `x`.
(define (absv x)
  (if (< x 0) (- x) x))

; Define a symbolic variable called y of type integer.
(define-symbolic y integer?)

; Solve a constraint saying |y| = 5.
(solve
  (assert (= (absv y) 5)))

However, when I try running this or any similar program using more than the basic racket keywords I get unclear (to me) errors.

#lang rosette

(struct plus (left right) #:transparent)
(struct mul (left right) #:transparent)
(struct square (arg) #:transparent)

(define prog (plus (square 7) 3))

(define (interpret p)
  (destruct p
    [(plus a b)  (+ (interpret a) (interpret b))]
    [(mul a b)   (* (interpret a) (interpret b))]
    [(square a)  (expt (interpret a) 2)]
    [_ p]))

(interpret prog)

This gives me an error destruct: unbound identifier in: destruct. What is going on? This code is not my own and is copy pasted from a tutorial so it should work I think. I have also tried example code copy pasted from the Rosette website and that gives similar errors. I've followed all the installation instructions and updated the environment path etc. Any help?

1 Answers1

1

destruct is not provided by #lang rosette by default. You need to require it by writing:

 (require rosette/lib/destruct)

after #lang rosette

Where did you find this code, by the way?

Sorawee Porncharoenwase
  • 6,305
  • 1
  • 14
  • 28
  • Thank you! I found the code from this article https://www.cs.utexas.edu/~bornholt/post/building-synthesizer.html – MathStudent Oct 22 '21 at 14:10
  • 1
    Ah, that post doesn't fully show all code, but the gist that is linked to from the post does have full code: https://gist.github.com/jamesbornholt/b51339fb8b348b53bfe8a5c66af66efe – Sorawee Porncharoenwase Oct 22 '21 at 14:38