问题标签 [eval-when]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2340 浏览

compilation - eval-when 使用?

在阅读了大量有关 Lispeval-when运算符的文档后,我仍然无法理解它的用途,我知道使用此运算符我可以控制表达式的评估时间,但我无法找出任何适用的示例?

最好的问候,utxeee。

0 投票
1 回答
1381 浏览

emacs - Common Lisp:如何让(包内...)在 Emacs Slime 中工作

64 位 Windows 7
Clozure Common Lisp 版本 1.9 WindowsX8632
Emacs 24.3.1
Slime 更新日志日期 2014-06-17

我有一个示例 .lisp 文件,其开头如下:

程序的其余部分显示一个对话框。当我从命令行运行它时,wx86cl -load helloqt.lisp它似乎工作正常。当我从 Emacs Slime ( C-x C-k) 运行它时,它说没有包“QT”。C-x C-e但是,如果我首先单独评估第一行(

如何制作它,以便我可以从 emacs 编译/运行文件,而不必先手动评估第一行?

另外,为什么不在(in-package ...)Slime 会话中更改当前包?如果我想与包内容交互,我必须手动更改它。

0 投票
1 回答
407 浏览

drools - 在drools 6 when子句中比较不同的项目

我在互联网上搜索过,但找不到解决我们目前面临的口水问题(6.2.0)的解决方案。

假设我有这样的规则:

如果 $list 包含 2 个产品 A 和 B,则此规则将针对组合触发:

  1. AB
  2. 文学学士

出于某种原因,我无法只触发一次规则(仅 AB 或仅 BA)

有谁知道是否有一种标准的方法来达到预期的结果?

提前谢谢了!

问候,

0 投票
1 回答
688 浏览

common-lisp - 加载 quicklisp 包以在另一个 lisp 文件中使用

我下载了一个大型软件项目FriCAS,我从源代码编译并使用 SBCL。这只是使用 GNU .configure 的问题——我是一个完整的 Lisp 新手。

但是,为了添加一些进一步的功能,我已经非常仔细地按照说明安装了 quicklisp 和一些额外的包。到目前为止,一切都很好。

这是我的问题:我正在尝试编译一个外部 lisp 文件以在系统中使用。我需要让 quicklisp 及其包对编译器可见。因此,我将 .sbclrc 文件复制到了 lisp 文件的顶部:

我跟着这个

我已经安装f2cl-lib了 quicklisp。但是,我的编译器(在 FriCAS 内)立即中止

我在这里有点难过 - 可能缺少一些微不足道和明显的东西,但正如我从新手的角度说的那样,我不知道它是什么。

0 投票
1 回答
332 浏览

if-statement - 圈复杂度 - Cobol

我必须为仅包含像这样的 EVALUATE 的 Cobol 程序计算圈复杂度:

我还必须为仅包含这样一个 IF 语句的 Cobol 程序计算圈复杂度:`

计算CC的算法是什么?谢谢你的时间。

0 投票
1 回答
2746 浏览

common-lisp - In Common Lisp, when do you need to use eval-when, and how do you know?

A required use of eval-when is to ensure that functions which a macro depends on are available at the time the macro is compiled and is used. However, I can't think of an example that would demonstrate the consequences of not using eval-when.

If I understand correctly, the (defun util-fun ...) should be wrapped with eval-when.

EDIT: As you'll see from the Answer, there's a problem with this example: it doesn't actually call UTIL-FUN at compile time. This explains why no error is given, because it's not an error. But the question is still valid in that it highlights a new user's confusion.

However, from the REPL, no error or warning is issued during compilation, load or usage (SBCL 1.3.20):

Note that normally I use C-c C-k to eval and load a file to the repl, but here, I'm using the compile-file and load commands to demonstrate that no error occurs. (I do receive an error when I try to use the functions after they're compiled but before they are loaded, but that would occur with any unloaded code.)

There are prior questions and comments that relate to this:

  • This previous StackOverflow answer seems to very plainly say that any function which is used by a macro must be enclosed by the eval-when form, or loaded in a separate file.

  • This comment from coredump is also very clear:

    When the macro is expanded, any function that the macro calls must be defined. If you have a compilation unit which defines a macro, which calls functions, but you don't actually use the macro in the same compilation unit, you don't need eval-when. If however, you define an aux. function, a macro and want to use your macro right off after you define it, then the implementation might complain that the aux. function is unknown – coredump

Given that, why does my example not generate an error? Will my example fail under other scenarios? An example of the compile-time, load-time, or run-time error generated when failing to properly use eval-when would be helpful to my understanding.

Thank you for your patience!