在Chicken Scheme中使用vs导入vs需要vs需要扩展 [英] Use vs Import vs Require vs Require-extension in Chicken Scheme

查看:35
本文介绍了在Chicken Scheme中使用vs导入vs需要vs需要扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Chicken 中(use)(import) 之间的区别有点模糊.同样,(load)(require)(require-extension) 有什么不同?

I'm a little hazy on the differences between (use) and (import) in Chicken. Similarly, how do (load), (require) and (require-extension) differ?

网站上似乎很少提到这些事情.

These things don't seem to be mentioned much on the website.

推荐答案

Loadrequire 是纯粹的运行时程序操作.Load 接受一个字符串参数并将具有该名称的文件(可以是源代码或编译代码)加载到正在运行的 Scheme 中,以便它定义的任何内容都可用.Require 做同样的事情,但检查文件是否已经被加载,通过查看 provide 是否已经以相同的名称被调用(通常是被加载的文件).在Scheme编程中比较少见,对应其他语言的插件,需要加载编译时未知的代码.有关详细信息,请参阅单元 eval 的手册页.

Load and require are purely run-time, procedural actions. Load accepts a string argument and loads the file with that name (which can be source or compiled code) into the running Scheme, so that whatever it defines becomes available. Require does the same thing, but checks if the file has already been loaded by seeing if provide has been called on the same name (typically by the file as it is loaded). They are relatively rare in Scheme programming, corresponding to plug-ins in other languages, where code unknown at compile time needs to be loaded. See the manual page for unit eval for more details.

Import 关注模块而不是文件.它查找必须已加载的命名模块(但请参阅下面的小鸡 5),并使从该模块导出的名称在当前上下文中可见.为了成功导入一个模块,必须有一个导入库.这是语法,因此模块名称必须显式出现在调用中,并且不能在运行时计算.有关更多详细信息,请参阅有关模块的手册页.

Import is concerned with modules rather than files. It looks for the named module, which must have already been loaded (but see below for Chicken 5), and makes the names exported from that module visible in the current context. In order to successfully import a module, there must be an import library for it. It is syntax, so the module name must appear explicitly in the call and cannot be computed at run time. See the manual page on modules for more details.

Require-library 做正确的事情来加载代码.如果代码已经是正在运行的 Scheme 的一部分,或者因为它内置在 Chicken 中,它什么都不做.否则它将加载一个核心库单元(如果有),或者将调用 require 作为最后的手段.在编译时,它会做类似的事情来确保环境在运行时是正确的.详情请参阅手册中的非标准宏和特殊表格"页面.

Require-library does the Right Thing to load code. If the code is already part of the running Scheme, either because it is built into Chicken, it does nothing. Otherwise it will load a core library unit if there is one, or will call require as a last resort. At compile time, it does analogous things to make sure that the environment will be correct at run time. See the "Non-standard macros and special forms" page in the manual for more details.

Use 执行 require-library 后跟同名的 import .这是向 Chicken 程序添加功能的最常见方法.但是,我们编写(import scheme)(import chicken) 是因为这些模块的功能已经加载了.Require-extensionuse 的同义词,提供 SRFI 55 兼容性.在 R7RS 模式下,import 也是 use 的同义词.

Use does a require-library followed by an import on the same name. It is the most common way to add functionality to your Chicken program. However, we write (import scheme) and (import chicken) because the functionality of these modules is already loaded. Require-extension is an exact synonym for use, provided for SRFI 55 compatibility. In R7RS mode, import is also a synonym for use.

鸡 5 的更新

Use 已从语言中删除,import 现在执行 use 过去所做的:加载(如果需要)然后进口.Require-extension 因此现在是 import 的同义词.

Use has been removed from the language, and import now does what use used to do: it loads (if necessary) and then imports. Require-extension is consequently now a synonym for import.

此外,Chicken 特定的程序和宏已被分解为名称如 (chicken base)(chicken bitwise) 的模块.

In addition, Chicken-specific procedures and macros have been broken into modules with names like (chicken base) and (chicken bitwise).

这篇关于在Chicken Scheme中使用vs导入vs需要vs需要扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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