title: Adding sqrt function to the language of racket pl 03
body: <p>my assignment is to add new function called sqrt+ to my racket language.</p>
  
  <p>the sqrt+ function return list with the root of the number and the negtive root of him.</p>
  
  <p>The way to call to the sqrt+ function i by Sqrt syntax:</p>
  
  <pre><code>#lang pl 03
  
  #| BNF for the MUWAE language:
       &lt;MUWAE&gt; ::= &lt;num&gt;
               | { + &lt;MUWAE&gt; &lt;MUWAE&gt; }
               | { - &lt;MUWAE&gt; &lt;MUWAE&gt; }
               | { * &lt;MUWAE&gt; &lt;MUWAE&gt; }
               | { / &lt;MUWAE&gt; &lt;MUWAE&gt; }
               | { Sqrt &lt;MUWAE&gt;      }
               | { with { &lt;id&gt; &lt;WAE&gt; } &lt;MUWAE&gt; }
               | &lt;id&gt;
  |#
  
  ;; MUWAE abstract syntax trees
  (define-type MUWAE
    [Num  Number]
    [Add  MUWAE MUWAE]
    [Sub  MUWAE MUWAE]
    [Mul  MUWAE MUWAE]
    [Div  MUWAE MUWAE]
    [Sqrt MUWAEE]
    [Id   Symbol]
    [With Symbol MUWAE MUWAE])
  
  (: parse-sexpr : Sexpr -&gt; MUWAE)
  ;; to convert s-expressions into MUWAEs
  (define (parse-sexpr sexpr)
    (match sexpr
      [(number: n)    (Num n)]
      [(symbol: name) (Id name)]
      [(cons 'with more)
       (match sexpr
         [(list 'with (list (symbol: name) named) body)
          (With name (parse-sexpr named) (parse-sexpr body))]
         [else (error 'parse-sexpr "bad `with' syntax in ~s" sexpr)])]
      [(list '+ lhs rhs) (Add (parse-sexpr lhs) (parse-sexpr rhs))]
      [(list '- lhs rhs) (Sub (parse-sexpr lhs) (parse-sexpr rhs))]
      [(list '* lhs rhs) (Mul (parse-sexpr lhs) (parse-sexpr rhs))]
      [(list '/ lhs rhs) (Div (parse-sexpr lhs) (parse-sexpr rhs))]
      [(list 'Sqrt s) (sqrt+ (parse-sexpr s))]
      [else (error 'parse-sexpr "bad syntax in ~s" sexpr)]))
  
  (: parse : String -&gt; MUWAE)
  ;; parses a string containing a MUWAE expression to a MUWAE AST
  (define (parse str)
    (parse-sexpr (string-&gt;sexpr str)))
  
  #| Formal specs for `subst':
     (`N' is a &lt;num&gt;, `E1', `E2' are &lt;MUWAE&gt;s, `x' is some &lt;id&gt;,
     `y' is a *different* &lt;id&gt;)
        N[v/x]                = N
        {+ E1 E2}[v/x]        = {+ E1[v/x] E2[v/x]}
        {- E1 E2}[v/x]        = {- E1[v/x] E2[v/x]}
        {* E1 E2}[v/x]        = {* E1[v/x] E2[v/x]}
        {/ E1 E2}[v/x]        = {/ E1[v/x] E2[v/x]}
        y[v/x]                = y
        x[v/x]                = v
        {with {y E1} E2}[v/x] = {with {y E1[v/x]} E2[v/x]}
        {with {x E1} E2}[v/x] = {with {x E1[v/x]} E2}
  |#
  
  (: subst : MUWAE Symbol MUWAE -&gt; MUWAE)
  ;; substitutes the second argument with the third argument in the
  ;; first argument, as per the rules of substitution; the resulting
  ;; expression contains no free instances of the second argument
  (define (subst expr from to)
    (cases expr
      [(Num n) expr]
      [(Add l r) (Add (subst l from to) (subst r from to))]
      [(Sub l r) (Sub (subst l from to) (subst r from to))]
      [(Mul l r) (Mul (subst l from to) (subst r from to))]
      [(Div l r) (Div (subst l from to) (subst r from to))]
      [(Sqrt s) (sqrt+ (subst s from to))]
      [(Id name) (if (eq? name from) to expr)]
      [(With bound-id named-expr bound-body)
       (With bound-id
             (subst named-expr from to)
             (if (eq? bound-id from)
               bound-body
               (subst bound-body from to)))]))
  
  #| Formal specs for `eval':
       eval(N)         = N
       eval({+ E1 E2}) = eval(E1) + eval(E2)
       eval({- E1 E2}) = eval(E1) - eval(E2)
       eval({* E1 E2}) = eval(E1) * eval(E2)
       eval({/ E1 E2}) = eval(E1) / eval(E2)
       eval(id)        = error!
       eval({with {x E1} E2}) = eval(E2[eval(E1)/x])
  |#
  
  (: eval : MUWAE -&gt; Number)
  ;; evaluates MUWAE expressions by reducing them to numbers
  (define (eval expr)
    (cases expr
      [(Num n) n]
      [(Add l r) (+ (eval l) (eval r))]
      [(Sub l r) (- (eval l) (eval r))]
      [(Mul l r) (* (eval l) (eval r))]
      [(Div l r) (/ (eval l) (eval r))]
      [(Sqrt s) (sqrt+ (eval s))]
      [(With bound-id named-expr bound-body)
       (eval (subst bound-body
                    bound-id
                    (Num (eval named-expr))))]
      [(Id name) (error 'eval "free identifier: ~s" name)]))
  
  (: run : String -&gt; Number)
  ;; evaluate a MUWAE program contained in a string
  (define (run str)
    (eval (parse str)))
  
  (: sqrt+ : (Listof Number) -&gt; (Listof Number))
  ;; a version of `sqrt' that takes a list of numbers, and return a list
  
  ;; with twice the elements, holding the two roots of each of the inputs;
  
  ;; throws an error if any input is negative.
  (define (sqrt+ ns)
  (cond [(null? ns) 0]
  [(&lt; (first ns) 0) (error 'ns "`sqrt' requires a nonnegative input ~s")]
  [else (sqrt ns (* (sqrt ns) -1))]))
  </code></pre>
  
  <p>but when i try to run the language i get:</p>
  
  <blockquote>
    <p>cases: missing cases for the following variants: (Sqrt ...)</p>
  </blockquote>
  
  <p>What did i miss and needed to make change?</p>