如何评估球拍中的弦 [英] How to eval strings in racket

查看:59
本文介绍了如何评估球拍中的弦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何获取eval函数以读取字符串并评估字符串内部的内容.

I'm trying to understand how to get the eval function to read a string and evaluate the content that's inside the string.

目前我知道

> (eval '(+ 1 2))
   3

但是我对球拍的使用并不了解.因此,目前我正在尝试获取它,以便可以执行此操作:

but I'm not that knowledgeable with the use of racket. So at the moment I'm trying to get it so that I can do this:

> (eval "(+ 1 2)")
   3

任何建议或指向有用资源的链接都将不胜感激.

Any advice or links to useful resources would be appreciated.

推荐答案

您要与open-input-string一起使用read.像这样:

You want to use read together with open-input-string. Like so:

-> (eval (read (open-input-string "(+ 1 2)")))
3

您还可以使用with-input-from-string:

-> (with-input-from-string "(+ 1 2)"
     (lambda () (eval (read))))
3

这篇关于如何评估球拍中的弦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆