Echo-streams and concatenated-streams are not available. Predefined streams are following:
input-stream-p object [function]
output-stream-p object [function]
open [function]
path &key (direction :input)
(if-exists :new-version)
(if-does-not-exist 'default)
(permission #o644)
(buffer-size 512)
with-open-file (svar path &rest open-options) &rest forms [macro]
make-string-input-stream string [function]
make-string-output-stream &optional size [function]
get-output-stream-string string-stream [function]
make-broadcast-stream &rest output-streams [function]
Reader's global variables:
Reader's default macro characters:
( read list
" read string
' read quoted expression
# dispatch macro
; comment until end of line
` back-quote
, list-time eval
@ append
% read C-like mathematical forms
Escape characters:
single character escape
multiple character escape
When an unescaped symbol is read, all the constituent characters are converted to upcase by default, and upcase-character symbol is stored internally. For example, 'abc and 'ABC are regarded as the same symbol. Escape is necessary to distinguish between them. 'ABC, 'ABC and 'abc are identical, while 'abc and 'abc are different symbols. By default, even if you enter a symbol with upcase letters, When symbols are printed, EusLisp's printer converts them into lowercase from internal upcase representation. This conversion is suppressed by setting *print-case* to :UPCASE.
Note that 10. is read as integer 10, not floating 10.0. Since ':' is reserved for package marker, it must be escaped when used as a constituent of a symbol, like '. This restriction is imposed not by the syntax of the character ':', but by the attribute which determines the alphabetical order and the meaning of the letter. The attributes of characters are hardwired in the reader. Thus, although you may change the syntax of a certain character by creating a new readtable by copy-readtable and resetting the syntactic meaning for the character by set-syntax-from-char, you cannot change its attribute anyway. In other words, digits are always digits, alphabets are alphabets, and we cannot use letters like '#$%@' to represent numbers.
String is denoted by two double quotes '"' at the beginning and at the end.
No case conversion is taken inside the quotes.
A back-slash 'ís used as an escape to include a double quote.
Therefore, "He said, Ï like Lisp.SPMquot;" is read as a string
including two double quotes.
To enter a back-slash, two back-slashes are needed.
Note that shift-JIS encoding of Japanese text is inadequate for this
read-string convention, since some characters happen to have the
code of a back-slash (#x5c
) as their second byte.
Use of EUC coding is preferrable.
% is an extended read-macro character specific to EusLisp. Preceding % to a mathematical formula written in infix notation, the formula is converted to lisp's prefix form. For an instance, %(1 + 2 * 3 / 4.0) is transformed to (+ 1 (/ (* 2 3) 4.0)) and 2.5 is resulted. C-like function calls and array references are converted to lisp forms, too, thus, %(sin(x) + a[1]) is evaluated to (+ (sin x) (aref a 1)). Functions having more than one arguments and arrays of more than two dimeisions are notated as func(a b c ...) and ary[1 2 3 ...], not func(a,b,c) nor ary[1][2][3]. Relative expressions and assignments are also properly handled, so, %(a b) is converted to ( a b), and %(a[0] = b[0] * c[0]) is to (setf (aref b 0) (* (aref b 0) (aref c 0))). A simple optimization is performed to reduce duplicated function calls and array references. %(sin(x) + cos(x) / sin(x)) is converted into (let* ((temp (sin x))) (+ temp (/ (cos x) temp))).
Dispatch macros are preceeded by the #
character.
A number (integer) argument can be given between #
and a dispatch macro
character.
This means that any digits (0 .. 9) cannot be defined as dispatch
macro characters.
Reader's standard dispatch macro characters follow:
Some reader functions have eof-error-p, eof-value and recursive-p parameters. The first two parameters control the behavior when the reader encounters with end-of-file. The default of eof-error-p is t, which causes an error at eof. If you want to know the occurrence of eof and don't want the system's error-handler to snatch control, specify nil to eof-error-p. Thus, when an eof appears during reading, the reader returns the eof-value instead of entering an error loop. Eof-value is defaulted to nil. So, you cannot know if nil is actually read, or eof appears. To distinguish them, give a value which can never appear in the stream. Use cons or gensym to make such unique data object.
Recursive-p is often used in read-macro functions, which call reader recursively. Non-nil value of recursive-p tells the reader that the read operation has been started somewhere else and it should not reset the internal table for reading forms labeled by #n= and #n#.
read &optional stream (eof-error-p t) (eof-value nil) recursive-p [function]
read-delimited-list delim-char &optional stream recursive-p [function]
read-line &optional stream (eof-error-p t) (eof-value nil) [function]
read-char &optional stream (eof-error-p t) (eof-value nil) [function]
read-from-string string &optional (eof-error-p t) (eof-value nil) [function]
unread-char char &optional stream [function]
peek-char &optional stream (eof-error-p t) (eof-value nil) [function]
y-or-n-p &optional format-string &rest args [function]
yes-or-no-p &optional stream [function]
In the readtable manipulating functions, the default value of readtable is the value of the global variable *readtable*.
copy-readtable &optional from-readtable to-readtable [function]
set-syntax-from-char from-char to-char &optional to-readtable from-readtable [function]
set-macro-character char func &optional non-teminating-p readtable [function]
get-macro-character char &optional readtable [function]
set-dispatch-macro-character dispchar char func &optional readtable [function]
get-dispatch-macro-character dispchar char &optional readtable [function]
The followings are special variables controlling printer's behaviors.
In order to print objects containing recursive references so that they can be read back again, print the objects with both *print-circle* and *print-structure* set to T. Although most of the user defined objects can be printed in re-readable forms, classes, compiled-codes and packages cannot be dumped in that way, because classes and compiled-code include unrelocatable executable codes, and the rereading packages damages the consistency among symbols.
print obj &optional stream [function]
prin1 obj &optional stream [function]
princ obj &optional stream [function]
terpri &optional stream [function]
finish-output &optional stream [function]
princ-to-string x &optional (l 16) [function]
prin1-to-string x &optional (l 16) [function]
format stream format-string &rest args [function]
(format t "~s ~s ~a ~a ~10,3f~%" "abc" 'a#b "abc" 'a#b 1.2) ---> "abc" |A#B| abc a#b 1.200
pprint obj &optional (stream *standard-output*) (tab 0) (platen 75) [function]
print-functions file &rest fns [function]
write-byte integer stream [function]
write-word integer stream [function]
write-long integer stream [function]
spaces n &optional stream [function]
pf func &optional stream *standard-output*) [macro]
pp-method class selector &optional (stream *standard-output*) [function]
tprint obj tab &optional (indent 0) (platen 79) (cpos 0) [function]
EusLisp provides four kinds of IPC facilities, shared memory, message-queue, FIFO and socket. 2Normally, efficiency decreases in this order. If you are using multithread facility, synchronization functions described in the section 14 are also used for communications. Availability of these facilities depends on the configuration and the version of Unix.
Example programs to share a file of 64 byte length between two euslisp are shown below.
;; Create a file of 64 bytes (with-open-file (f "afile" :direction :output) (princ (make-string 64) f)) ;; Map it (setq shared-string1 (map-file "afile" :direction :io)) ;; ;; In another process (setq shared-string2 (map-file "afile" :direction :io))
Then, data written to shared-string1 immediately appears in shared-string2, and vice versa. Writing to a foreign string can be made by replace or setf in conjunction with aref.
map-file filename &key (direction :input) length (offset 0) (share t) (address 0) [function]
To make a stream to FIFO, you first create a FIFO node with unix:mknod function by setting its second argument mode=#o10000, and you open it as a normal file. Message-queues and FIFOs are created locally on a machine and only provide communication channels within the machine.
Note that message-queues and FIFOs are not removed from the system even after the owner process terminates. Explicit use of unix:msgctl or ipcrm command is needed to delete them.
make-msgq-input-stream key &optional (buffer-size 128) [function]
make-msgq-output-stream key &optional (buffer-size 128) [function]
Although connected streams provide bidirectional communication channels, the connection establishment operation is asymmetric. One endpoint is refered to server and other to client. The endpoint on the behalf of the server (service access point) must be first established. It is created by make-socket-port function which returns an instance of socket-port. The socket-port object is then used to accept connections from one or more clients by make-server-socket-stream. A call to make-server-socket-stream may be blocked until a connection request from a client really happens. Clients can make socket streams by make-client-socket-stream specifying a socket-address.
;;; an example of IPC through a socket stream: ;;; server side (setq saddr (make-socket-address :domain af_inet :host "etlic2" :port 2000)) (setq sport (make-socket-port saddr)) (setq sstream (make-server-socket-stream sport)) ;;; ;;; client side (setq caddr (make-socket-address :domain af_inet :host "etlic2" :port 2000)) (setq cstream (make-client-socket-stream caddr))
In applications like a database or an environment simulator for mobile robots, multiple connection service between one server and many clients is required. This type of server can be programmed by the open-server function. From the current host name and given port number, open-server creates a socket port (service access point) on which connection requests are listened for. Since this port is attributed to be asynchronous, open-server is not blocked and returns immediately. Thereafter, each connection request interrupts EusLisp's main loop, and an socket-stream is created asynchronously. This socket-stream also works in asynchronous mode: the asynchronous input processing function which is the second argument to open-server is invoked whenever new data appear in this stream. Up to 30 connections can be established so that as many clients can access the server's data at the same time.
;; server side (defun server-func (s) (case (read s) ... ;do appropriate jobs according to inputs (open-server 3000 #'server-func) ... do other jobs in parallel ;; client-1 through client-N (setq s (connect-server "etlmmd" 3000)) (format s "..." ...) (finish-output s) ;issue a command to the server (read s) ;receive response
In contrast to the connection-oriented streams which provide reliable communication channels, the connectionless sockets are unreliable: messages may be lost, duplicated, and may arrive out-of-order. The connectionless sockets, however, have advantages that they do not need to assign file descriptor to each connection, and sending process is never blocked even if the receiver is not reading data and the buffer overflows.
To make connectionless sockets, use the following procedures. Messages are transferred by the unix:sendto and unix:recvfrom.
;;; receiver side (setq saddr (make-socket-address :domain af_inet :host "etlic2" :port 2001)) (setq sock (make-dgram-socket saddr)) (unix:recvfrom sock) ;;; ;;; client side (setq caddr (make-socket-address :domain af_inet :host "etlic2" :port 2001)) (setq sock (unix:socket (send caddr :domain) 2 0)) (unix:sendto sock caddr "this is a message") ;;; ;;; how to use echo service which is registered in /etc/services. (setq caddr (make-socket-address :domain af_inet :host "etlic2" :port (car (unix:getservbyname "echo")))) (setq echosock (unix:socket (send caddr :domain) 2 0)) (unix:sendto echosock caddr "this is a message") (unix:recvfrom echosock) --> "this is a message"
make-socket-address &key domain pathname host port proto service [function]
make-socket-port sockaddr [function]
make-server-socket-stream sockport &optional (size 100) [function]
make-client-socket-stream sockaddr &optional (timeout 5) (size 512) [function]
open-server port remote-func [function]
connect-server host port [function]
select-stream stream-list timeout [function]
def-async stream function [macro]
Pathnames give the way to analyze and compose file names OS-independently. A typical path name is assumed to be consisted of following components: host:device/directory1/.../directory-n/name.type.version. Since EusLisp only runs on Unix, host, device and version fields are ignored. The pathname function decomposes a string into a list of directory components, name and type, and returns a pathname object, which is printed as a string prefixed by #P.
pathname-directory path [function]
make-pathname &key host device directory name type version defaults [function]
merge-pathnames name &optional (defaults *default-pathname-defaults*) [function]
parse-namestring name [function]
URL-Pathname is an extension of pathname to have slots for a protocol
and a port.
A URL is composed of six components;
protocol, server, port, directories, filename, and file-type, like
http://shock2.etl.go.jp/matsui/index.html
.
digits-string n digits &optional (base 10)) [function]
sequential-file-name head num extension &optional (digits 4)) [function]
timed-file-name head extension &optional (dt (unix:localtime))) [function]
dated-file-name head extension &optional (dt (unix:localtime))) [function]
find-executable file [function]
file-write-date file [function]
directory &optional (path ".") [function]
dir &optional (dir ".") [function]
This document was generated using the LaTeX2HTML translator on Sat Feb 5 14:36:57 JST 2022 from EusLisp version 138fb6ee Merge pull request #482 from k-okada/apply_dfsg_patch