[racket] please i need your help using DrRacket

From: FIRAS MOHAMMAD NIMER ABU HASAN (fhassan at science.alquds.edu)
Date: Tue Mar 15 12:49:10 EDT 2011

Dear all

how can i edit this code in order to compute the 2 power any number as 
argument for example 2 power 5 = 32:

#lang plai
;; (interp (parse '5)(list (fundef 'null 'n (id 'n))))
;; (interp (parse '{+ 5 5})(list (fundef 'null 'n (id 'n))))
;; (interp (parse '{with {x {+ 5 5}} {+ x x}})(list (fundef 'null 'n 
(id 'n))))
;; (interp (parse '{with {x 5} {+ x x}})(list (fundef 'null 'n (id 'n))))
;; (interp (parse '{with {x {+ 5 5}} {with {y {- x 3}} {+ y y}}})(list 
(fundef 'null 'n (id 'n))))
;; (interp (parse '{with {x 5} {with {y {- x 3}} {+ y y}}}) (list 
(fundef 'null 'n (id 'n))))
;; (interp (parse '{with {x 5} {+ x {with {x 3} 10}}})(list (fundef 'null 'n 
(id 'n))) )
;; (interp (parse '{with {x 5} {+ x {with {x 3} x}}})(list (fundef 'null 'n 
(id 'n))))
;; (interp (parse '{with {x 5} {+ x {with {y 3} x}}})(list (fundef 'null 'n 
(id 'n))))
;; (interp (parse '{with {x 5} {with {y x} y}})(list (fundef 'null 'n 
(id 'n))))
;; (interp (parse '{with {x 5} {with {x x} x}})(list (fundef 'null 'n 
(id 'n))))
(define-type F1WAE
   [num (n number?)]
   [add (lhs F1WAE?)(rhs F1WAE?)]
   [mul (lhs F1WAE?)(rhs F1WAE?)]
   [with (name symbol?) (named-expr F1WAE?) (body F1WAE?)]
   [id (name symbol?)]
   [app (fun-name symbol?) (arg F1WAE?)]

 (define-type FunDef
   [fundef (fun-name symbol?)
           (arg-name symbol?)
           (body F1WAE?)])
 ;; newest form of parse, with apply added in.
 (define parse
   (lambda (sexp)
    [(number? sexp) (num sexp)]
    [(symbol? sexp) (id sexp)]
    [(list? sexp)
     (case (first sexp)
       [(+)(add (parse (second sexp))
                (parse (third sexp)))]
       [(*) (mul (parse (second sexp))
                 (parse (third sexp)))]
       [(with) (with (first (second sexp))
                     (parse (second (second sexp)))
                     (parse (third sexp)))]
       [else (app (first sexp)
                   (parse (second sexp)))]
 ;; interp: F1WAE listof(fundef) -> number
 ;; evaluates F1WAE expressions by reducing them to their corresponding 
 (define interp
   (lambda (expr fundefs)
     (type-case F1WAE expr
                [num (n) n]
                [add (l r) (+ (interp l fundefs) (interp r fundefs))]
                [mul (l r) (* (interp l fundefs) (interp r fundefs))]
                [with (bound-id named-expr bound-body)
                      (interp (subst bound-body
                                   (num (interp named-expr fundefs)))
                [id (v) (error 'interp "Free identifier")]
                [app (fun-name arg-expr)
                     (local ([define the-fun-def (lookup-fundef fun-name 
                            (interp (subst (fundef-body the-fun-def)
                                           (fundef-arg-name the-fun-def)
                                           (num (interp arg-expr fundefs)))
 ;; helper functions
 (define lookup-fundef
   (lambda (fun-name fundefs)
       [(empty? fundefs)
        (error 'lookup-fundef "Function does not exist")]
       [else (if (symbol=? fun-name (fundef-fun-name (first fundefs)))
                 (first fundefs)
                 (lookup-fundef fun-name (rest fundefs)))])))
 (define subst
   (lambda (expr sub-id val)
     (type-case F1WAE expr
                [num (n) expr]
                [add (l r) (add (subst l sub-id val)
                                (subst r sub-id val))]
                [mul (l r) (mul(subst l sub-id val)
                                (subst r sub-id val))]
                [with (bound-id named-expr bound-body)
                      (if (symbol=? bound-id sub-id)
                          (with bound-id
                                (subst named-expr sub-id val)
                          (with bound-id
                                (subst named-expr sub-id val) ;; added to 
take care of scope
                                (subst bound-body sub-id val)))]
                [id (v)(if (symbol=? v sub-id) val expr)]
                [app (fun-name arg-expr)
                     (app fun-name (subst arg-expr sub-id val))])))
 ;; test
 (interp (parse '{double 5})
         (list (fundef 'double   'n  
                       (add (id 'n) (id 'n))          

This message has been scanned for viruses and
dangerous content by SKITCE MailScanner, and is
believed to be clean.

Posted on the users mailing list.