English 中文(简体)
• 如何将封锁落实到一名LISP口译员
原标题:How to implement closures into a LISP interpreter

目前在贾瓦撰写的LISP译员上工作。 现在,我坐在关闭时。 我希望能够结束这样的局面:

(define a 1000)
(define closure (lambda (a) (lambda (b) (+ a b))))
(define x (closure 10))
(x 20) --> 30

因此,(x 20)>应当交回30。 但是,我猜想的是,1020名口译人员返回。 我认为,这一错误属于我的伊斯兰堡垒。 它希望:

public class LLambda extends LOperation {

    private LList parameters;
    private LList definitions;

    public LLambda(LList parameters, LList definitions) {

        this.parameters = parameters;
        this.definitions = definitions;
    } 

    public LObject eval(Environment environment, LObject tokens) {

        environment = environment.copy();

        for(int i = 0; i < parameters.size(); i++) {

            LSymbol key = LSymbol.create(parameters.get(i));
            LObject object = ((LList) tokens).get(i);
            object = object.eval(environment, tokens);  
            environment.put(key, object);
        }

        return definitions.eval(environment, tokens);
    }
}

这一班级的工作是罚款的,但它没有储存环境价值,以便能够关闭。 是否有人的想法? 以及在哪里这样做? 在构造或电子阀法中?

而且,如果我不执行:

environment = environment.copy();

关闭是行之有效的,但中断了其他一些试验。

感谢。

(我也可以上载整个源头,或在GIT中免费提供。)

最佳回答

www.un.org/spanish/ecosoc 这一班级的工作是罚款的,但它没有储存环境价值,以便能够关闭。 是否有人的想法? 以及在哪里这样做? 在构造或电子阀法中?

是的,这个类别应当储存环境。 一般而言,成员变量:

它应当放在构造中,因为环境在构造时是受约束的,而不是在老时。

At eval time, the original environment is not available: the new environment is.

如果你的方言完全具有灵活性,那么你的方言就不需要环境参数。 什么是lam? 这是一项职能。 对forms的评价需要一种环境。 评价功能不是;对职能的评价是职能要求,只是理由。 环境不会变成功能;功能体在有其自身私人环境的封顶空间进行评估。 (“eval”在“lambda”上的功能似乎是错误的;你希望将其命名为et/code>或类似内容。 解释的《公约》条款 (a) 评价员的服务;

Inside your lambda, the action will be to evaluate the forms of the lambda body. Those will use the stored environment (not anything that was passed in).

你们必须营造一种环境,使lam泥参数对论点价值具有约束力。 这在被捕获的环境中被nes。 (一) 所谓<代码>x的论点 页: 1

(你必须具备某种放任环境,即建造一些新的具有约束力的文书,其中涉及外部环境。)

如果你想要支持除弹性外的有活力的扩展,就没有必要为此而通过一个环境;可以默示地这样做。 一种现成的变量可以保持动态环境或像这样的环境。

(细节取决于口译设计;在有些设计中,总是有一些背景物体绕过(代表口译员)。 如果说,你要用一个直截了当的密码虚拟机器,你就需要这样做。

问题回答

我强烈建议阅读基督教书。 小型项目许可证,其中非常详细地描述了多种执行Lisp(或类似计划)评价员、口译员、汇编员的方式。

你们需要从地方价值观中处理不同的封闭价值。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签