Cannot use eval when entering user in Racket

I am currently studying a circuit (using Racket), but one of the problems I am facing is trying to execute the following bit of code, which is designed to execute Racket code from user input with eval:

(display (eval (read)))

 

Here are some of the weird activities I've seen so far:

  • (display (eval (read)))in the definition window asks for keyboard input, as expected, when executing the definitions. However, subject to data entry ((lambda (x) (+ x 1)) 1)
     
    gives an error
    ?: function application is not allowed; no #%app syntax transformer is bound in: ((lambda (x) (+ x 1)) 1)

  • On the other hand, using (display ((eval (read)) 1))and providing input (lambda (x) (+ x 1))
     
    returns an error
    lambda: unbound identifier; also, no #%app syntax transformer is bound in: lambda

  • However, by launching (display (eval (read)))and providing ((lambda (x) (+ x 1)) 1)in the console panel, unlike the definition panel, it will display 2as expected.

?

+4
2

, . (eval (read)) , , current-namespace . racket/base, (current-namespace (make-base-namespace)):

#lang racket
(current-namespace (make-base-namespace))
(println (eval (read)))

((lambda (x) (+ x 1)) 1) 2.

, ( 3 ), , current-namespace .

, , current-namespace eval:

#lang racket
(define ns (make-base-namespace))
(println (eval (read) ns))
+7

Racket, , R5RS, R6RS , , R7RS. Racket, Scheme, . , , Scheme, , Scheme, , Racket, , eval.

eval - , , R5RS. :

#!r6rs

(import (rnrs)
        (rnrs eval))

(display (eval '((lambda (x) (+ x 1)) 1) 
               (environment '(rnrs)))) 
; ==> undefined, prints 2

, R5RS:

#!r5rs

(display (eval '((lambda (x) (+ x 1)) 1) 
               (scheme-report-environment 5))) 
; ==> undefined, prints 2

R7RS, :

#!r7rs

(import (scheme)
        (scheme eval))

(display (eval '((lambda (x) (+ x 1)) 1) 
               (environment '(scheme)))) 
; ==> undefined, prints 2
+1

All Articles