[racket] convert string to evaluatable code
hello
I have made kind of calculator
as like following code
#lang scheme
(define ns (make-base-namespace))
(define (calc)
(let ((expression (read)))
(if (eq? expression 'exit)
(exit)
(printf "~A ~n" (eval expression ns))))
(calc))
(calc)
since I learned big-bang function,
I am intending to making more graphical program
which read from user and display texts and when user hit the enter button,
the written string evaluated and pop out to the window
(without command line prompt)
but I still stuck at convert string to evaluatable data
my source code(still underconstruction) is looks like this
#lang scheme
(require 2htdp/image)
(require 2htdp/universe)
(define ns (make-base-namespace))
(define result "")
(define command "")
(define input (open-input-string command))
(define output (open-output-string))
(define (draw n)
(overlay (text (string-append command "=" result)15 "blue") (square 400
"outline" "black")))
(define (keyboard n key)
(cond
[(not (equal? key "\r")) (set! command (string-append command key))]
[(equal? key "\r") (begin
(write command output)
(set! result (eval (read input) ns)))])n)
(big-bang 0
(on-tick add1)
(on-draw draw)
(on-key keyboard))
I dare not ask for correcting my whole source code
I need an little advice from you
what I have to do for change string to evaluatable code?
thanks in advanced
sorry for messy code
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101012/baf84f55/attachment.html>