方案评估 [英] Evaluation in Scheme

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

问题描述

好的,我在这里有这个问题.我被要求在Scheme中编写一个函数,该函数需要一个环境"和一个表达式,并返回该表达式的值,用于在环境中找到的变量绑定.

ok, i have this problem here. i was asked to write a function in Scheme, that takes an "environment", and an expression and it returns the value of this expression, for the variable bindings found in the enviroment.

根据下面的问题,这是一个布尔表达式的定义.

and a definition of a boolean expression is this according to the question below.

edit 抱歉,我的问题是需要一个环境"作为参数是什么意思,该功能到底需要做什么?

edit sorry my question is what does it mean by "it takes an environment" as an argument and what exactly does the function need to do?

评估例如"T OR F"并返回"F" ???

evaluate for example "T OR F" and return "F" ???

"<expr> ::= <boolean>
          |<variable>
          |(not <expr>)
          |(or <expr> <expr>)
          |(and <expr> <expr>"

推荐答案

环境基本上是变量名到值的字典.因此,考虑到环境

An environment is basically a dictionary of variable names to values. So given the environment

var1 = #t
var2 = #f
var3 = #t

和一个表达式

(or var2 (and T (or var1 var3)))

您需要将给定的var1var2var3值替换为表达式,然后对表达式求值.

You would need to substitute the given values of var1, var2, and var3 into the expression, and then evaluate the expression.

您的函数可能会以某种Lisp结构(可能是列表)作为其参数之一而被赋予环境.

Your function will probably be given the environment as some sort of Lisp structure, probably an alist, as one of its parameters.

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

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