version 1.3, 2000/03/02 07:46:14 |
version 1.16, 2008/07/17 15:01:10 |
|
|
@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/io.texi,v 1.2 1999/12/21 02:47:33 noro Exp $ |
@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/io.texi,v 1.15 2003/12/20 13:38:04 ohara Exp $ |
\BJP |
\BJP |
@node $BF~=PNO(B,,, $BAH$_9~$_H!?t(B |
@node $BF~=PNO(B,,, $BAH$_9~$_H!?t(B |
@section $BF~=PNO(B |
@section $BF~=PNO(B |
|
|
* bsave bload:: |
* bsave bload:: |
* bload27:: |
* bload27:: |
* print:: |
* print:: |
* open_file close_file get_line:: |
* access:: |
|
* remove_file:: |
|
* open_file close_file get_line get_byte put_byte purge_stdin:: |
@end menu |
@end menu |
|
|
\JP @node end quit,,, $BF~=PNO(B |
\JP @node end quit,,, $BF~=PNO(B |
Line 96 line of the input file is strongly recommended. |
|
Line 98 line of the input file is strongly recommended. |
|
@itemize @bullet |
@itemize @bullet |
\BJP |
\BJP |
@item |
@item |
$B<B:]$N%W%m%0%i%`$N=q$-J}$O(B, @xref{$B%f!<%68@8l(B Asir}. |
$B<B:]$N%W%m%0%i%`$N=q$-J}$O(B, @pxref{$B%f!<%68@8l(B Asir}. |
$B%F%-%9%H%U%!%$%k$rFI$_9~$`>l9g(B, @code{cpp} |
$B%F%-%9%H%U%!%$%k$rFI$_9~$`>l9g(B, @code{cpp} |
$B$rDL$9$N$G(B, C $B$N%W%m%0%i%`F1MM(B @code{#include}, @code{#define} $B$r;H$&$3$H$,$G$-$k(B. |
$B$rDL$9$N$G(B, C $B$N%W%m%0%i%`F1MM(B @code{#include}, @code{#define} $B$r;H$&$3$H$,$G$-$k(B. |
@item |
@item |
Line 121 Windows $BHG$b%G%#%l%/%H%j$N%;%Q%l!<%?$H$7$F(B @samp |
|
Line 123 Windows $BHG$b%G%#%l%/%H%j$N%;%Q%l!<%?$H$7$F(B @samp |
|
\E |
\E |
\BEG |
\BEG |
@item |
@item |
@xref{User language Asir} for practical programming. |
See @ref{User language Asir} for practical programming. |
Since text files are read through @code{cpp}, |
Since text files are read through @code{cpp}, |
the user can use, as in C programs, @code{#include} and @code{#define} |
the user can use, as in C programs, @code{#include} and @code{#define} |
in @b{Asir} program source codes. |
in @b{Asir} program source codes. |
Line 140 On Windows, @code{get_rootdir()/lib} is searched if |
|
Line 142 On Windows, @code{get_rootdir()/lib} is searched if |
|
We recommend to write an @code{end} command at the last line of |
We recommend to write an @code{end} command at the last line of |
your program. If not, @b{Asir} will not give you a prompt after it |
your program. If not, @b{Asir} will not give you a prompt after it |
will have executed @code{load} command. |
will have executed @code{load} command. |
(Escape with an interrupt character (@pxref{Interruption}), |
(Escape with an interrupt character (@ref{Interruption}), |
if you have lost yourself.) |
if you have lost yourself.) |
Even in such a situation, |
Even in such a situation, |
@b{Asir} itself is still ready to read keyboard inputs as usual. |
@b{Asir} itself is still ready to read keyboard inputs as usual. |
|
|
@item bsave(@var{obj},"@var{filename}") |
@item bsave(@var{obj},"@var{filename}") |
\JP :: @var{filename} $B$K(B @var{obj} $B$r%P%$%J%j7A<0$G=q$-9~$`(B. |
\JP :: @var{filename} $B$K(B @var{obj} $B$r%P%$%J%j7A<0$G=q$-9~$`(B. |
\EG :: This function writes @var{obj} onto @var{filename} in binary form. |
\EG :: This function writes @var{obj} onto @var{filename} in binary form. |
@item bsave("@var{filename}") |
@item bload("@var{filename}") |
\JP :: @var{filename} $B$+$i?t<0$r%P%$%J%j7A<0$GFI$_9~$`(B. |
\JP :: @var{filename} $B$+$i?t<0$r%P%$%J%j7A<0$GFI$_9~$`(B. |
\EG :: This function reads an expression from @var{filename} in binary form. |
\EG :: This function reads an expression from @var{filename} in binary form. |
@end table |
@end table |
|
|
@findex bload27 |
@findex bload27 |
|
|
@table @t |
@table @t |
@item xxx(@var{filename}) |
@item bload27("@var{filename}") |
\JP :: $B5lHG$G:n$i$l$?(B bsave file $B$NFI$_9~$_(B |
\JP :: $B5lHG$G:n$i$l$?(B bsave file $B$NFI$_9~$_(B |
\EG :: Reads bsaved file created by older version of @b{Asir}. |
\EG :: Reads bsaved file created by older version of @b{Asir}. |
@end table |
@end table |
Line 492 On Windows one has to use @samp{/} as the separator of |
|
Line 494 On Windows one has to use @samp{/} as the separator of |
|
@var{obj} $B$rI>2A$7$FI=<($9$k(B. |
@var{obj} $B$rI>2A$7$FI=<($9$k(B. |
@item |
@item |
$BBh(B 2 $B0z?t$,$J$$$+(B, $B$^$?$O(B 0, 2 $B0J30$N>l9g(B, $B2~9T$9$k(B. |
$BBh(B 2 $B0z?t$,$J$$$+(B, $B$^$?$O(B 0, 2 $B0J30$N>l9g(B, $B2~9T$9$k(B. |
$BBh(B 2 $B0z?t$,(B 1 $B$N>l9g(B, $B2~9T$;$:(B, $B=PNO$O%P%C%U%!$K=q$-9~$^$l(B, |
$BBh(B 2 $B0z?t$,(B 0 $B$N>l9g(B, $B2~9T$;$:(B, $B=PNO$O%P%C%U%!$K=q$-9~$^$l(B, |
$B%P%C%U%!$O%U%i%C%7%e$5$l$J$$(B. |
$B%P%C%U%!$O%U%i%C%7%e$5$l$J$$(B. |
$BBh(B 2 $B0z?t$,(B 2 $B$N>l9g(B, $B2~9T$7$J$$$,%P%C%U%!$O%U%i%C%7%e$5$l$k(B. |
$BBh(B 2 $B0z?t$,(B 2 $B$N>l9g(B, $B2~9T$7$J$$$,%P%C%U%!$O%U%i%C%7%e$5$l$k(B. |
@item |
@item |
Line 521 The last 0 will not be printed. ) |
|
Line 523 The last 0 will not be printed. ) |
|
@item |
@item |
Formatted outputs are not currently supported. |
Formatted outputs are not currently supported. |
If one wishes to output multiple objects by a single @code{print()} command, |
If one wishes to output multiple objects by a single @code{print()} command, |
use list like @code{[@var{obj1,...}]}, which is not so beautiful, but |
use list like @code{[@var{obj1},...]}, which is not so beautiful, but |
convenient to minimize programming efforts. |
convenient to minimize programming efforts. |
\E |
\E |
@end itemize |
@end itemize |
|
|
@example |
@example |
[8] def cat(L) @{ while ( L != [] ) @{ print(car(L),0); L = cdr(L);@} print(""); @} |
[8] def cat(L) @{ while ( L != [] ) @{ print(car(L),0); L = cdr(L);@} |
|
print(""); @} |
[9] cat([xyz,123,"gahaha"])$ |
[9] cat([xyz,123,"gahaha"])$ |
xyz123gahaha |
xyz123gahaha |
@end example |
@end example |
|
|
\JP @node open_file close_file get_line,,, $BF~=PNO(B |
\JP @node access,,, $BF~=PNO(B |
\EG @node open_file close_file get_line,,, Inputs and Outputs |
\EG @node access,,, Inputs and Outputs |
@subsection @code{open_file}, @code{close_file}, @code{get_line} |
@subsection @code{access} |
|
@findex access |
|
|
|
@table @t |
|
@item access(@var{file}) |
|
\JP :: @var{file} $B$NB8:_$r%F%9%H$9$k(B. |
|
\EG :: testing an existence of @var{file}. |
|
@end table |
|
|
|
@table @var |
|
@item return |
|
(1|0) |
|
@item file |
|
\JP $B%U%!%$%kL>(B |
|
\EG filename |
|
@end table |
|
|
|
@itemize @bullet |
|
\BJP |
|
@item |
|
@var{file} $B$,B8:_$9$l$P(B 1, $BB8:_$7$J$1$l$P(B 0 $B$rJV$9(B. |
|
\E |
|
@end itemize |
|
|
|
\JP @node remove_file,,, $BF~=PNO(B |
|
\EG @node remove_file,,, Inputs and Outputs |
|
@subsection @code{remove_file} |
|
@findex remove_file |
|
|
|
@table @t |
|
@item remove_file(@var{file}) |
|
\JP :: @var{file} $B$r>C5n$9$k(B. |
|
\EG :: Delete an file @var{file}. |
|
@end table |
|
|
|
@table @var |
|
@item return |
|
1 |
|
@item file |
|
\JP $B%U%!%$%kL>(B |
|
\EG filename |
|
@end table |
|
|
|
\JP @node open_file close_file get_line get_byte put_byte purge_stdin,,, $BF~=PNO(B |
|
\EG @node open_file close_file get_line get_byte put_byte purge_stdin,,, Inputs and Outputs |
|
@subsection @code{open_file}, @code{close_file}, @code{get_line}, @code{get_byte}, @code{put_byte}, @code{purge_stdin} |
@findex open_file |
@findex open_file |
@findex close_file |
@findex close_file |
@findex get_line |
@findex get_line |
|
@findex get_byte |
|
@findex put_byte |
|
@findex purge_stdin |
|
|
@table @t |
@table @t |
@item open_file("@var{filename}") |
@item open_file("@var{filename}"[,"@var{mode}"]) |
\JP :: @var{filename} $B$rFI$_=P$7MQ$K%*!<%W%s$9$k(B. |
\JP :: @var{filename} $B$r%*!<%W%s$9$k(B. |
\EG :: Opens @var{filename} for reading. |
\EG :: Opens @var{filename} for reading. |
@item close_file(@var{num}) |
@item close_file(@var{num}) |
\JP :: $B<1JL;R(B @var{num} $B$N%U%!%$%k$r%/%m!<%:$9$k(B. |
\JP :: $B<1JL;R(B @var{num} $B$N%U%!%$%k$r%/%m!<%:$9$k(B. |
\EG :: Closes the file indicated by a descriptor @var{num}. |
\EG :: Closes the file indicated by a descriptor @var{num}. |
@item get_line(@var{num}) |
@item get_line([@var{num}]) |
\JP :: $B<1JL;R(B @var{num} $B$N%U%!%$%k$+$i(B 1 $B9TFI$`(B. |
\JP :: $B<1JL;R(B @var{num} $B$N%U%!%$%k$+$i(B 1 $B9TFI$`(B. |
\EG :: Reads a line from the file indicated by a descriptor @var{num}. |
\EG :: Reads a line from the file indicated by a descriptor @var{num}. |
|
@item get_byte(@var{num}) |
|
\JP :: $B<1JL;R(B @var{num} $B$N%U%!%$%k$+$i(B 1 $B%P%$%HFI$`(B. |
|
\EG :: Reads a byte from the file indicated by a descriptor @var{num}. |
|
@item put_byte(@var{num},@var{c}) |
|
\JP :: $B<1JL;R(B @var{num} $B$N%U%!%$%k$K(B 1 $B%P%$%H(B @var{c} $B$r=q$/(B. |
|
\EG :: Writes a byte @var{c} to the file indicated by a descriptor @var{num}. |
|
@item purge_stdin() |
|
\JP :: $BI8=`F~NO$N%P%C%U%!$r%/%j%"$9$k(B. |
|
\EG :: Clears the buffer for the standard input. |
@end table |
@end table |
|
|
@table @var |
@table @var |
@item return |
@item return |
\JP @code{open_file()} : $B@0?t(B ($B<1JL;R(B); @code{close_file()} : 1; @code{get_line()} : $BJ8;zNs(B |
\JP @code{open_file()} : $B@0?t(B ($B<1JL;R(B); @code{close_file()} : 1; @code{get_line()} : $BJ8;zNs(B; @code{get_byte()}, @code{put_byte()} : $B@0?t(B |
\EG @code{open_file()} : integer (fild id); @code{close_file()} : 1; @code{get_line()} : string |
\EG @code{open_file()} : integer (fild id); @code{close_file()} : 1; @code{get_line()} : string; @code{get_byte()}, @code{put_byte()} : integer |
@item filename |
@item filename |
\JP $B%U%!%$%kL>(B ($B%Q%9L>(B) |
\JP $B%U%!%$%kL>(B ($B%Q%9L>(B) |
\EG file (path) name |
\EG file (path) name |
|
@item mode |
|
\JP $BJ8;zNs(B |
|
\EG string |
@item num |
@item num |
\JP $BHsIi@0?t(B ($B%U%!%$%k<1JL;R(B) |
\JP $BHsIi@0?t(B ($B%U%!%$%k<1JL;R(B) |
\EG non-negative integer (file descriptor) |
\EG non-negative integer (file descriptor) |
|
|
|
|
@itemize @bullet |
@itemize @bullet |
\BJP |
\BJP |
@item @code{open_file()} $B$OFI$_=P$7MQ$K%U%!%$%k$r%*!<%W%s$9$k(B. $B@.8y$7$?(B |
@item @code{open_file()} $B$O%U%!%$%k$r%*!<%W%s$9$k(B. @var{mode} $B;XDj$,(B |
$B>l9g(B, $B%U%!%$%k<1JL;R$H$7$FHsIi@0?t$rJV$9(B. $B<:GT$N>l9g%(%i!<$H$J$k(B. |
$B$J$$>l9gFI$_=P$7MQ(B, @var{mode} $B;XDj$,$"$k>l9g$K$O(B, C $B$NI8=`F~=PNO(B |
|
$B4X?t(B @code{fopen()} $B$KBP$9$k%b!<%I;XDj$H$_$J$9(B. $B$?$H$($P?75,=q$-9~$_(B |
|
$BMQ$N>l9g(B @code{"w"}, $BKvHxDI2C$N>l9g(B @code{"a"} $B$J$I(B. |
|
$B@.8y$7$?>l9g(B, $B%U%!%$%k<1JL;R$H$7$FHsIi@0?t$rJV$9(B. $B<:GT$N>l9g%(%i!<$H$J$k(B. |
$BITMW$K$J$C$?%U%!%$%k$O(B @code{close_file()} $B$G%/%m!<%:$9$k(B. |
$BITMW$K$J$C$?%U%!%$%k$O(B @code{close_file()} $B$G%/%m!<%:$9$k(B. |
|
$BFCJL$J%U%!%$%kL>(B unix://stdin, unix://stdout, unix://stderr $B$rM?$($k$H(B |
|
$B$=$l$>$lI8=`F~NO(B, $BI8=`=PNO(B, $BI8=`%(%i!<=PNO$r%*!<%W%s$9$k(B. |
|
$B$3$N>l9g%b!<%I;XDj$OL5;k$5$l$k(B. |
@item @code{get_line()} $B$O8=:_%*!<%W%s$7$F$$$k%U%!%$%k$+$i(B 1 $B9TFI$_(B, |
@item @code{get_line()} $B$O8=:_%*!<%W%s$7$F$$$k%U%!%$%k$+$i(B 1 $B9TFI$_(B, |
$BJ8;zNs$H$7$FJV$9(B. |
$BJ8;zNs$H$7$FJV$9(B. $B0z?t$,$J$$>l9g(B, $BI8=`F~NO$+$i(B 1 $B9TFI$`(B. |
|
@item @code{get_byte()} $B$O8=:_%*!<%W%s$7$F$$$k%U%!%$%k$+$i(B 1 $B%P%$%HFI$_(B |
|
$B@0?t$H$7$FJV$9(B. |
|
@item @code{put_byte()} $B$O8=:_%*!<%W%s$7$F$$$k%U%!%$%k$K(B 1 $B%P%$%H=q$-(B, |
|
$B$=$N%P%$%H$r@0?t$H$7$FJV$9(B. |
@item $B%U%!%$%k$N=*$j$^$GFI$s$@8e$K(B @code{get_line()} $B$,8F$P$l$?>l9g(B, |
@item $B%U%!%$%k$N=*$j$^$GFI$s$@8e$K(B @code{get_line()} $B$,8F$P$l$?>l9g(B, |
$B@0?t$N(B 0 $B$rJV$9(B. |
$B@0?t$N(B 0 $B$rJV$9(B. |
@item $BFI$_=P$7$?J8;zNs$O(B, $BI,MW$,$"$l$P(B @code{sub_str()} $B$J$I$NJ8;zNs=hM}(B |
@item $BFI$_=P$7$?J8;zNs$O(B, $BI,MW$,$"$l$P(B @code{sub_str()} $B$J$I$NJ8;zNs=hM}(B |
$B4X?t$G2C9)$7$?$N$A(B @code{eval_str()} $B$K$h$jFbIt7A<0$KJQ49$G$-$k(B. |
$B4X?t$G2C9)$7$?$N$A(B @code{eval_str()} $B$K$h$jFbIt7A<0$KJQ49$G$-$k(B. |
|
@item @code{purge_stdin()} $B$O(B, $BI8=`F~NO%P%C%U%!$r6u$K$9$k(B. |
|
$B4X?tFb$G(B @code{get_line()} $B$K$h$jI8=`F~NO$+$iJ8;zNs$r<u$1<h$k>l9g(B, |
|
$B4{$K%P%C%U%!Fb$KB8:_$9$kJ8;zNs$K$h$k8mF0:n$rKI$0$?$a$K$"$i$+$8$a(B |
|
$B8F$S=P$9(B. |
\E |
\E |
\BEG |
\BEG |
@item @code{open_file()} opens a file for reading. |
@item @code{open_file()} opens a file. |
|
If @var{mode} is not specified, a file is opened for reading. |
|
If @var{mode} is specified, it is used as the mode specification for |
|
C standard I/O function @code{fopen()}. For example @code{"w"} requests |
|
that the file is truncated to zero length or created for writing. |
|
@code{"a"} requests that the file is opened for writing or created |
|
if it does not exist. |
|
The stream pointer is set at the end of the file. |
If successful, it returns a non-negative integer as the file descriptor. |
If successful, it returns a non-negative integer as the file descriptor. |
Otherwise the system error function is called. |
Otherwise the system error function is called. |
Unnecessary files should be closed by @code{close_file()}. |
Unnecessary files should be closed by @code{close_file()}. |
|
If the special file name unix://stdin or unix://stdout or unix://stderr |
|
is given, it returns the file descriptor for the standard input or |
|
the standard output or the standard error stream respectively. |
|
The mode argument is ignored in this case. |
@item @code{get_line()} reads a line from an opened file and returns the |
@item @code{get_line()} reads a line from an opened file and returns the |
line as a string. |
line as a string. If no argument is supplied, it reads a line from the |
|
standard input. |
|
@item @code{get_byte()} reads a byte from an opened file and returns the |
|
it as an integer. |
|
@item @code{put_byte()} writes a byte from an opened file and returns the |
|
the byte as an integer. |
@item A @code{get_line()} call after reading the end of file returns |
@item A @code{get_line()} call after reading the end of file returns |
an integer 0. |
an integer 0. |
@item Strings can be converted into internal forms with string manipulation |
@item Strings can be converted into internal forms with string manipulation |
functions such as @code{sub_str()}, @code{eval_str()}. |
functions such as @code{sub_str()}, @code{eval_str()}. |
|
@item @code{purge_stdin()} clears the buffer for the standard input. |
|
When a function receives a character string from @code{get_line()}, |
|
this functions should be called in advance in order to avoid |
|
an incorrect behavior which is caused by the characters already |
|
exists in the buffer. |
\E |
\E |
@end itemize |
@end itemize |
|
|
Line 602 functions such as @code{sub_str()}, @code{eval_str()}. |
|
Line 700 functions such as @code{sub_str()}, @code{eval_str()}. |
|
0 |
0 |
[189] type(@@@@); |
[189] type(@@@@); |
0 |
0 |
|
[190] close_file(Id); |
|
1 |
|
[191] open_file("test"); |
|
1 |
|
[192] get_line(1); |
|
12345 |
|
|
|
[193] get_byte(1); |
|
54 /* the ASCII code of '6' */ |
|
[194] get_line(1); |
|
7890 /* the rest of the last line */ |
|
[195] def test() @{ return get_line(); @} |
|
[196] def test1() @{ purge_stdin(); return get_line(); @} |
|
[197] test(); |
|
/* a remaining newline character has been read */ |
|
/* returns immediately */ |
|
[198] test1(); |
|
123; /* input from a keyboard */ |
|
123; /* returned value */ |
|
|
|
[199] |
|
|
@end example |
@end example |
|
|
@table @t |
@table @t |