📄 guile-procedures.txt
字号:
c-registered-modules - Scheme Procedure: c-registered-modules Return a list of the object code modules that have been imported into the current Guile process. Each element of the list is a pair whose car is the name of the module, and whose cdr is the function handle for that module's initializer function. The name is the string that has been passed to scm_register_module_xxx. c-clear-registered-modules - Scheme Procedure: c-clear-registered-modules Destroy the list of modules registered with the current Guile process. The return value is unspecified. *Warning:* this function does not actually unlink or deallocate these modules, but only destroys the records of which modules have been loaded. It should therefore be used only by module bookkeeping operations. dynamic-link - Scheme Procedure: dynamic-link filename Open the dynamic library called FILENAME. A library handle representing the opened library is returned; this handle should be used as the DOBJ argument to the following functions. dynamic-object? - Scheme Procedure: dynamic-object? obj Return `#t' if OBJ is a dynamic library handle, or `#f' otherwise. dynamic-unlink - Scheme Procedure: dynamic-unlink dobj Unlink the indicated object file from the application. The argument DOBJ must have been obtained by a call to `dynamic-link'. After `dynamic-unlink' has been called on DOBJ, its content is no longer accessible. dynamic-func - Scheme Procedure: dynamic-func name dobj Search the dynamic object DOBJ for the C function indicated by the string NAME and return some Scheme handle that can later be used with `dynamic-call' to actually call the function. Regardless whether your C compiler prepends an underscore `_' to the global names in a program, you should *not* include this underscore in FUNCTION. Guile knows whether the underscore is needed or not and will add it when necessary. dynamic-call - Scheme Procedure: dynamic-call func dobj Call the C function indicated by FUNC and DOBJ. The function is passed no arguments and its return value is ignored. When FUNCTION is something returned by `dynamic-func', call that function and ignore DOBJ. When FUNC is a string , look it up in DYNOBJ; this is equivalent to (dynamic-call (dynamic-func FUNC DOBJ #f)) Interrupts are deferred while the C function is executing (with `SCM_DEFER_INTS'/`SCM_ALLOW_INTS'). dynamic-args-call - Scheme Procedure: dynamic-args-call func dobj args Call the C function indicated by FUNC and DOBJ, just like `dynamic-call', but pass it some arguments and return its return value. The C function is expected to take two arguments and return an `int', just like `main': int c_func (int argc, char **argv); The parameter ARGS must be a list of strings and is converted into an array of `char *'. The array is passed in ARGV and its size in ARGC. The return value is converted to a Scheme number and returned from the call to `dynamic-args-call'. dynamic-wind - Scheme Procedure: dynamic-wind in_guard thunk out_guard All three arguments must be 0-argument procedures. IN_GUARD is called, then THUNK, then OUT_GUARD. If, any time during the execution of THUNK, the continuation of the `dynamic_wind' expression is escaped non-locally, OUT_GUARD is called. If the continuation of the dynamic-wind is re-entered, IN_GUARD is called. Thus IN_GUARD and OUT_GUARD may be called any number of times. (define x 'normal-binding) => x (define a-cont (call-with-current-continuation (lambda (escape) (let ((old-x x)) (dynamic-wind ;; in-guard: ;; (lambda () (set! x 'special-binding)) ;; thunk ;; (lambda () (display x) (newline) (call-with-current-continuation escape) (display x) (newline) x) ;; out-guard: ;; (lambda () (set! x old-x))))))) ;; Prints: special-binding ;; Evaluates to: => a-cont x => normal-binding (a-cont #f) ;; Prints: special-binding ;; Evaluates to: => a-cont ;; the value of the (define a-cont...) x => normal-binding a-cont => special-binding environment? - Scheme Procedure: environment? obj Return `#t' if OBJ is an environment, or `#f' otherwise. environment-bound? - Scheme Procedure: environment-bound? env sym Return `#t' if SYM is bound in ENV, or `#f' otherwise. environment-ref - Scheme Procedure: environment-ref env sym Return the value of the location bound to SYM in ENV. If SYM is unbound in ENV, signal an `environment:unbound' error. environment-fold - Scheme Procedure: environment-fold env proc init Iterate over all the bindings in ENV, accumulating some value. For each binding in ENV, apply PROC to the symbol bound, its value, and the result from the previous application of PROC. Use INIT as PROC's third argument the first time PROC is applied. If ENV contains no bindings, this function simply returns INIT. If ENV binds the symbol sym1 to the value val1, sym2 to val2, and so on, then this procedure computes: (proc sym1 val1 (proc sym2 val2 ... (proc symn valn init))) Each binding in ENV will be processed exactly once. `environment-fold' makes no guarantees about the order in which the bindings are processed. Here is a function which, given an environment, constructs an association list representing that environment's bindings, using environment-fold: (define (environment->alist env) (environment-fold env (lambda (sym val tail) (cons (cons sym val) tail)) '())) environment-define - Scheme Procedure: environment-define env sym val Bind SYM to a new location containing VAL in ENV. If SYM is already bound to another location in ENV and the binding is mutable, that binding is replaced. The new binding and location are both mutable. The return value is unspecified. If SYM is already bound in ENV, and the binding is immutable, signal an `environment:immutable-binding' error. environment-undefine - Scheme Procedure: environment-undefine env sym Remove any binding for SYM from ENV. If SYM is unbound in ENV, do nothing. The return value is unspecified. If SYM is already bound in ENV, and the binding is immutable, signal an `environment:immutable-binding' error. environment-set! - Scheme Procedure: environment-set! env sym val If ENV binds SYM to some location, change that location's value to VAL. The return value is unspecified. If SYM is not bound in ENV, signal an `environment:unbound' error. If ENV binds SYM to an immutable location, signal an `environment:immutable-location' error. environment-cell - Scheme Procedure: environment-cell env sym for_write Return the value cell which ENV binds to SYM, or `#f' if the binding does not live in a value cell. The argument FOR-WRITE indicates whether the caller intends to modify the variable's value by mutating the value cell. If the variable is immutable, then `environment-cell' signals an `environment:immutable-location' error. If SYM is unbound in ENV, signal an `environment:unbound' error. If you use this function, you should consider using `environment-observe', to be notified when SYM gets re-bound to a new value cell, or becomes undefined. environment-observe - Scheme Procedure: environment-observe env proc Whenever ENV's bindings change, apply PROC to ENV. This function returns an object, token, which you can pass to `environment-unobserve' to remove PROC from the set of procedures observing ENV. The type and value of token is unspecified. environment-observe-weak - Scheme Procedure: environment-observe-weak env proc This function is the same as environment-observe, except that the reference ENV retains to PROC is a weak reference. This means that, if there are no other live, non-weak references to PROC, it will be garbage-collected, and dropped from ENV's list of observing procedures. environment-unobserve - Scheme Procedure: environment-unobserve token Cancel the observation request which returned the value TOKEN. The return value is unspecified. If a call `(environment-observe env proc)' returns TOKEN, then the call `(environment-unobserve token)' will cause PROC to no longer be called when ENV's bindings change. make-leaf-environment - Scheme Procedure: make-leaf-environment Create a new leaf environment, containing no bindings. All bindings and locations created in the new environment will be mutable. leaf-environment? - Scheme Procedure: leaf-environment? object Return `#t' if object is a leaf environment, or `#f' otherwise. make-eval-environment - Scheme Procedure: make-eval-environment local imported Return a new environment object eval whose bindings are the union of the bindings in the environments LOCAL and IMPORTED, with bindings from LOCAL taking precedence. Definitions made in eval are placed in LOCAL. Applying `environment-define' or `environment-undefine' to eval has the same effect as applying the procedure to LOCAL. Note that eval incorporates LOCAL and IMPORTED by reference: If, after creating eval, the program changes the bindings of LOCAL or IMPORTED, those changes will be visible in eval. Since most Scheme evaluation takes place in eval environments, they transparently cache the bindings received from LOCAL and IMPORTED. Thus, the first time the program looks up a symbol in eval, eval may make calls to LOCAL or IMPORTED to find their bindings, but subsequent references to that symbol will be as fast as references to bindings in finite environments. In typical use, LOCAL will be a finite environment, and IMPORTED will be an import environment eval-environment? - Scheme Procedure: eval-environment? object Return `#t' if object is an eval environment, or `#f' otherwise. eval-environment-local - Scheme Procedure: eval-environment-local env Return the local environment of eval environment ENV. eval-environment-set-local! - Scheme Procedure: eval-environment-set-local! env local Change ENV's local environment to LOCAL. eval-environment-imported - Scheme Procedure: eval-environment-imported env Return the imported environment of eval environment ENV. eval-environment-set-imported! - Scheme Procedure: eval-environment-set-imported! env imported Change ENV's imported environment to IMPORTED. make-import-environment - Scheme Procedure: make-import-environment imports conflict_proc Return a new environment IMP whose bindings are the union of the bindings from the environments in IMPORTS; IMPORTS must be a list of environments. That is, IMP binds a symbol to a location when some element of IMPORTS does. If two different elements of IMPORTS have a binding for the same symbol, the CONFLICT-PROC is called with the following parameters: the import environment, the symbol and the list of the imported environments that bind the symbol. If the CONFLICT-PROC returns an environment ENV, the conflict is considered as resolved and the binding from ENV is used. If the CONFLICT-PROC returns some non-environment object, the conflict is considered unresolved and the symbol is treated as unspecified in the import environment. The checking for conflicts may be performed lazily, i. e. at the moment when a value or binding for a certain symbol is requested instead of the moment when the environment is created or the bindings of the imports change. All bindings in IMP are immutable. If you apply `environment-define' or `environment-undefine' to IMP, Guile will signal an `environment:immutable-binding' error. However, notice that the set of bindings in IMP may still change, if one of its imported environments changes. import-environment? - Scheme Procedure: import-environment? object Return `#t' if object is an import environment, or `#f' otherwise. import-environment-imports - Scheme Procedure: import-environment-imports env Return the list of environments imported by the import environment ENV. import-environment-set-imports! - Scheme Procedure: import-environment-set-imports! env imports Change ENV's list of imported environments to IMPORTS, and check for conflicts. make-export-environment - Scheme Procedure: make-export-environment private signature Return a new environment EXP containing only those bindings in private whose symbols are present in SIGNATURE. The PRIVATE argument must be an environment. The environment EXP binds symbol to location when ENV does, and symbol is exported by SIGNATURE. SIGNATURE is a list specifying which of the bindings in PRIVATE should be visible in EXP. Each element of SIGNATURE should be a list of the form: (symbol attribute ...) where each attribute is one of the following: the symbol `mutable-location' EXP should treat the location bound to symbol as mutable. That is, EXP will pass calls to `environment-set!' or `environment-cell' directly through to private. the symbol `immutable-location' EXP should treat the location bound to symbol as immutable. If the program applies `environment-set!' to EXP and symbol, or calls `environment-cell' to obtain a writable value cell, `environment-set!' will signal an `environment:immutable-location' error. Note that, even if an export environment treats a location as immutable, the underlying environment may treat it as mutable, so its value may change. It is an error for an element of signature to specify both `mutable-location' and `immutable-location'. If neither is specified, `immutable-location' is assumed. As a special case, if an element of signature is a lone symbol SYM, it is equivalent to an element of the form `(sym)'. All bindings in EXP are immutable. If you apply `environment-define' or `environment-undefine' to EXP, Guile will signal an `environment:immutable-binding' error. However, notice that the set of bindings in EXP may still change, if the bindings in private change. export-environment? - Scheme Procedure: export-environment? object Return `#t' if object is an export environment, or `#f' otherwise. export-environment-private - Scheme Procedure: export-environment-private env Return the private environment of export environment ENV. export-environment-set-private! - Scheme Procedure: export-environment-set-private! env private Change the private environment of export environment ENV. export-environment-signature - Scheme Procedure: export-environment-signature env Return the signature of export environment ENV.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -