Racket file io
If ' bits is supplied as the second argument, the result is a platform-specific integer encoding of the file or directory properties mostly permissions , and the result is independent of the current user and group. See also user-read-bit , etc. On Windows, permissions from all three owner, group, and others are always the same, and read and execute permission are always available.
On Unix and Mac OS, higher bits have a platform-specific meaning. If an integer is supplied as the second argument, it is used as an encoding of properties mostly permissions to install for the file.
In all modes, the exn:fail:filesystem exception is raised on error e. If as-link? On Windows XP and earlier, the exn:fail:unsupported exception is raised. On later versions of Windows, the creation of links tends to be disallowed by security policies. Furthermore, a relative-path link is parsed specially by the operating system; see Windows Paths for more information. When make-file-or-directory-link succeeds, it creates a symbolic link as opposed to a junction or hard link.
Beware that directory links must be deleted using delete-directory instead of delete-file. See also: rename-file-or-directory , file-or-directory-modify-seconds , file-or-directory-permissions. Thus, the current value of current-directory is always a cleansed, simplified, complete, directory path.
Normally, current-directory-for-user should stay at its initial value, reflecting the directory where a user started a process. A tool such as DrRacket, however, implicitly lets a user select a directory for the file being edited , in which case updating current-directory-for-user makes sense. See also the in-directory sequence constructor. Returns a list of all files and directories in the directory specified by path.
If build? Many operating systems provide notifications for filesystem changes, and those notifications are reflected in Racket by filesystem change events. If path refers to a directory, the event becomes ready for synchronization if a file or subdirectory is added, renamed, or removed within the directory. The event also becomes ready for synchronization if it is passed to filesystem-change-evt-cancel. Finally, depending on the precision of information available from the operating system, the event may become ready for synchronization under other circumstances.
For example, on Windows, an event for a file becomes ready when any file changes within in the same directory as the file. After a filesystem change event becomes ready for synchronization , it stays ready for synchronization.
If the current platform does not support filesystem-change notifications, then the exn:fail:unsupported exception is raised if failure-thunk is not provided as a procedure, or failure-thunk is called in tail position if provided. Similarly, if there is any operating-system error when creating the event such as a non-existent file , then the exn:fail:filesystem exception is raised or failure-thunk is called. Creation of a filesystem change event allocates resources at the operating-system level.
The resources are released at latest when the event is sychronized and ready for synchronization , when the event is canceled with filesystem-change-evt-cancel , or when the garbage collector determine that the filesystem change event is unreachable. See also system-type in ' fs-change mode. A filesystem change event is placed under the management of the current custodian when it is created.
If the custodian is shut down, filesystem-change-evt-cancel is applied to the event. Unlike using collection-path , define-runtime-path exposes each run-time path to tools like the executable and distribution creators, so that files and directories needed at run time are carried along in a distribution. For run time, id is bound to a path that is based on the result of expr. The path is normally computed by taking a relative path result from expr and adding it to a path for the enclosing file which is computed as described below.
If expr produces an absolute path, it is normally returned directly, but again may be replaced by an executable creator.
In all cases, the executable creator preserves the relative locations of all paths within a given package treating paths outside of any package as being together. When expr produces a relative or absolute path, then the path bound to id is always an absolute path. If expr produces a list of the form list ' lib str The path refers to a collection-based file similar to using the value as a module path.
If expr produces a list of the form list ' so str or list ' so str vers , the value bound to id can be either str or an absolute path; it is an absolute path when searching in the Racket-specific shared-object library directories as determined by get-lib-search-dirs locates the path.
In this way, shared-object libraries that are installed specifically for Racket get carried along in distributions. The search tries each directory in order; within a directory, the search tries using str directly, then it tries adding each version specified by vers — which defaults to ' f — along with a platform-specific shared-library extension— as produced by system-type ' so-suffix.
A vers can be a string, or it can be a list of strings and f. If expr produces a list of the form list ' share str , the value bound to id can be either str or an absolute path; it is an absolute path when searching in the directories reported by find-user-share-dir and find-share-dir in that order locates the path. If expr produces a list of the form list ' module module-path var-ref or list ' so str list str-or-false In an executable, the corresponding module is carried along, including all of its dependencies.
For compile-time, the expr result is used by an executable creator— but not the result when the containing module is compiled. Instead, expr is preserved in the module as a compile-time expression in the sense of begin-for-syntax.
Later, at the time that an executable is created, the compile-time portion of the module is executed again , and the result of expr is the file or directory to be included with the executable. The reason for the extra compile-time execution is that the result of expr might be platform-dependent, so the result should not be stored in the platform-independent bytecode form of the module; the platform at executable-creation time, however, is the same as at run time for the executable.
Note that expr is still evaluated at run time; consequently, avoid procedures like collection-path , which depends on the source installation, and instead use relative paths and forms like list ' lib str If a path is needed only on some platforms and not on others, use define-runtime-path-list with an expr that produces an empty list on platforms where the path is not needed.
Also beware that define-runtime-path in a phase level other than 0 does not cooperate properly with an executable creator. To work around that limitation, put define-runtime-path in a separate module— perhaps a submodule created by module — then export the definition, and then the module containing the definition can be require d into any phase level.
Using define-runtime-path in a phase level other than 0 logs a warning at expansion time. The enclosing path for a define-runtime-path is determined as follows from the define-runtime-path syntactic form:. If the form has a source module according to syntax-source-module , then the source location is determined by preserving the original expression as a syntax object, extracting its source module path at run time again using syntax-source-module , and then resolving the resulting module path index.
If the expression has no source module, the syntax-source location associated with the form is used, if is a string or path. If no source module is available, and syntax-source produces no path, then current-load-relative-directory is used if it is not f.
Finally, current-directory is used if all else fails. In the latter two cases, the path is normally preserved in platform-specific byte form, but if the enclosing path corresponds to a result of collection-file-path , then the path is record as relative to the corresponding module path.
Use define-runtime-module-path-index to bind a module path that is passed to a reflective function like dynamic-require while also creating a module dependency for building and distributing executables. The define-runtime-module-path-index form is usually preferred, because it creates a weaker link to the referenced module.
Unlike define-runtime-module-path-index , the define-runtime-module-path form creates a for-label dependency from an enclosing module to module-path. Since the dependency is merely for-label , module-path is not instantiate d or visit ed when the enclosing module is instantiate d or visit ed unless such a dependency is created by other require s , but the code for the referenced module is loaded when the enclosing module is loaded.
If keep-modify-seconds? If must-exist? If the move attempt fails e. The predicate procedure is called with a single argument for each file or directory. If start-path is f , the argument is a pathname string that is relative to the current directory. Otherwise, it is a path building on start-path. Consequently, supplying current-directory for start-path is different from supplying f , because predicate receives complete paths in the former case and relative paths in the latter. Another difference is that predicate is not called for the current directory when start-path is f.
If skip-filtered-directory? If follow-links? If start-path does not refer to an existing file or directory, then predicate will be called exactly once with start-path as the argument. The find-files procedure raises an exception if it encounters a directory for which directory-list fails. If path-filter is a procedure, then it is applied to each descendant of a directory. If path-filter returns f , then the descendant and any of its descendants, in the case of a subdirectory are omitted from the result.
The proc procedure is called with three arguments for each file, directory, or link:. If start-path is f , the first argument is a pathname string that is relative to the current directory. Otherwise, the first argument is a pathname that starts with start-path. Consequently, supplying current-directory for start-path is different from supplying f , because proc receives complete paths in the former case and relative paths in the latter. Another difference is that proc is not called for the current directory when start-path is f.
The second argument is a symbol, either ' file , ' dir , or ' link. The second argument can be ' link when follow-links? The third argument is the accumulated result. For the first call to proc , the third argument is init-val. For the second call to proc if any , the third argument is the result from the first call, and so on.
The result of the last call to proc is the result of fold-files. The proc argument is used in an analogous way to the procedure argument of foldl , where its result is used as the new accumulated result. There is an exception for the case of a directory when the second argument is ' dir : in this case the procedure may return two values, the second indicating whether the recursive scan should include the given directory or not.
If it returns a single value, the directory is scanned. In the cases of files or links when the second argument is ' file or ' link , a second value is permitted but ignored. If the start-path is provided but no such path exists, or if paths disappear during the scan, then an exception is raised. If path is a filesystem root or a relative path with a single path element, then no directory is created.
The template argument must be a format string suitable for use with format and one additional string argument where the string contains only digits. After evaluating this examples, the file named "output. The function returns f if the web page does not exist Note: this form is under development and will be documented in a precise manner after it is finalized and useful for a wide audience. How to Design Programs Teachpacks.
Ht DP Teachpacks. Images: "image. Worlds and the Universe: "universe. Web IO: "web- io. Abstraction: "abstraction. Planet Cute Images. Porting World Programs to Universe. Use define-runtime-module-path to bind a module path that is passed to a reflective function like dynamic-require while also creating a module dependency for building and distributing executables. The resolved module path for id corresponds to module-path with the same syntax as a module path for require , which can be relative to the enclosing module.
The define-runtime-module-path-index form is usually preferred, because it creates a weaker link to the referenced module. Unlike define-runtime-module-path-index , the define-runtime-module-path form creates a for-label dependency from an enclosing module to module-path. Since the dependency is merely for-label , module-path is not instantiate d or visit ed when the enclosing module is instantiate d or visit ed unless such a dependency is created by other require s , but the code for the referenced module is loaded when the enclosing module is loaded.
It expands to a quoted list containing the run-time paths declared by module-path , returning the compile-time results of the declaration expr s, except that paths are converted to byte strings. The enclosing module must require directly or indirectly the module specified by module-path , which is an unquoted module path. The resulting list does not include module paths bound through define-runtime-module-path. The mode-flag argument is the same as for open-input-file.
The line-mode argument is the same as the second argument to read-line , but the default is ' any instead of ' linefeed. The mode-flag and exists-flag arguments are the same as for open-output-file. Copies the file or directory src to dest , raising exn:fail:filesystem if the file or directory cannot be copied, possibly because dest exists already. If a source is a link, the target of the link is copied rather than the link itself. Deletes the file or directory specified by path , raising exn:fail:filesystem if the file or directory cannot be deleted.
If start-path is f , then the traversal starts from current-directory. In the resulting list, each directory precedes its content. The predicate procedure is called with a single argument for each file or directory. If start-path is f , the argument is a pathname string that is relative to the current directory. Otherwise, it is a path building on start-path. Consequently, supplying current-directory for start-path is different from supplying f , because predicate receives complete paths in the former case and relative paths in the latter.
Another difference is that predicate is not called for the current directory when start-path is f. The find-files traversal follows soft links. To avoid following links, use the more general fold-files procedure. If start-path does not refer to an existing file or directory, then predicate will be called exactly once with start-path as the argument.
The find-files procedure raises and exception if it encounters a directory for which directory-list fails. Given a list of paths, either absolute or relative to the current directory, returns a list such that. The proc procedure is called with three arguments for each file, directory, or link:.
If start-path is f , the first argument is a pathname string that is relative to the current directory. Otherwise, the first argument is a pathname that starts with start-path. Consequently, supplying current-directory for start-path is different from supplying f , because proc receives complete paths in the former case and relative paths in the latter.
Another difference is that proc is not called for the current directory when start-path is f. The second argument is a symbol, either ' file , ' dir , or ' link. The second argument can be ' link when follow-links?
If follow-links? The third argument is the accumulated result. For the first call to proc , the third argument is init-val. For the second call to proc if any , the third argument is the result from the first call, and so on. The result of the last call to proc is the result of fold-files. The proc argument is used in an analogous way to the procedure argument of foldl , where its result is used as the new accumulated result.
There is an exception for the case of a directory when the second argument is ' dir : in this case the procedure may return two values, the second indicating whether the recursive scan should include the given directory or not. If it returns a single value, the directory is scanned. In the cases of files or links when the second argument is ' file or ' link , a second value is permitted but ignored. If the start-path is provided but no such path exists, or if paths disappear during the scan, then an exception is raised.
Creates directory specified by path , creating intermediate directories as necessary. Instead of merely generating a fresh file name, the file is actually created; this prevents other threads or processes from picking the same temporary name. The template argument must be a format string suitable for use with format and one additional string argument where the string contains only digits. If the resulting string is a relative path, it is combined with the result of find-system-path ' temp-dir , unless directory is provided and non- f , in which case the file name generated from template is combined with directory to obtain a full path.
If there is such information, then the template string is based on the source location. If copy-from-filename is provided as path, the temporary file is created as a copy of the named file using copy-file.
If copy-from-filename is f , the temporary file is created as empty. When a temporary file is created, it is not opened for reading or writing when the pathname is returned. The client program calling make-temporary-file is expected to open the file with the desired access and flags probably using the ' truncate flag; see open-output-file and to delete it when it is no longer needed.
If none of those files exists, the preference set is empty. The preference file should contain a list of symbol—value lists written with the default parameter settings. Keys starting with racket: , mzscheme: , mred: , and plt: in any letter case are reserved for use by Racket implementers. If the preference file does not contain a list of symbol—value lists, an error is logged via log-error and failure-thunk is called. The result of get-preference is the value associated with name if it exists in the association list, or the result of calling failure-thunk otherwise.
If flush-mode is provided as f , the cache is used instead of re-consulting the preferences file. If flush-mode is provided as ' timestamp the default , then the cache is used only if the file has a timestamp that is the same as the last time the file was read. Otherwise, the file is re-consulted. On platforms for which preferences-lock-file-mode returns ' file-lock and when use-lock? If the preferences file cannot be read because the lock is unavailable, lock-there is called on the path of the lock file; if lock-there is f , an exception is raised.
The default lock-there handler retries about 5 times with increasing delays between each attempt before trying timeout-lock-there , and the default timeout-lock-there triggers an exception.
See also put-preferences. For a more elaborate preference system, see preferences:get. Old preferences files : When a filename is not provided and the file indicated by find-system-path ' pref-file does not exist, the following paths are checked for compatibility with old versions of Racket:. Windows: build-path find-system-path ' pref-dir ' up "PLT Scheme" "plt-prefs.
Mac OS X: build-path find-system-path ' pref-dir "org. The names argument supplies the preference names, and vals must have the same length as names. Each element of vals must be an instance of a built-in data type whose write output is read able i.
Current preference values are read from the preference file before updating, and a write lock is held starting before the file read, and lasting until after the preferences file is updated. The lock is implemented by the existence of a file in the same directory as the preference file; see preferences-lock-file-mode for more information.
0コメント