<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML> <HEAD> <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9"> <TITLE> S-Lang Run-Time Library Reference: Version 1.4.0: Eval Functions</TITLE> <LINK HREF="slangfun-16.html" REL=next> <LINK HREF="slangfun-14.html" REL=previous> <LINK HREF="slangfun.html#toc15" REL=contents> </HEAD> <BODY> <A HREF="slangfun-16.html">Next</A> <A HREF="slangfun-14.html">Previous</A> <A HREF="slangfun.html#toc15">Contents</A> <HR> <H2><A NAME="s15">15. Eval Functions</A></H2> <P> <H2><A NAME="autoload"></A> <A NAME="ss15.1">15.1 <B>autoload</B></A> </H2> <P> <DL> <DT><B> Synopsis </B><DD><P>Load a function from a file <DT><B> Usage </B><DD><P><CODE>autoload (String_Type funct, String_Type file)</CODE> <DT><B> Description </B><DD><P>The <CODE>autoload</CODE> function is used to declare <CODE>funct</CODE> to the interpreter and indicate that it should be loaded from <CODE>file</CODE> when it is actually used. <DT><B> Example </B><DD><P>Suppose <CODE>bessel_j0</CODE> is a function defined in the file <CODE>bessel.sl</CODE>. Then the statement <BLOCKQUOTE><CODE> <PRE> autoload ("bessel_j0", "bessel.sl"); </PRE> </CODE></BLOCKQUOTE> will cause <CODE>bessel.sl</CODE> to be loaded prior to the execution of <CODE>bessel_j0</CODE> <DT><B> See Also </B><DD><P><CODE>evalfile</CODE> </DL> <P> <P> <H2><A NAME="byte_compile_file"></A> <A NAME="ss15.2">15.2 <B>byte_compile_file</B></A> </H2> <P> <DL> <DT><B> Synopsis </B><DD><P>Compile a file to byte-code for faster loading. <DT><B> Usage </B><DD><P><CODE>byte_compile_file (String_Type file, Integer_Type method)</CODE> <DT><B> Description </B><DD><P>The <CODE>byte_compile_file</CODE> function byte-compiles <CODE>file</CODE> producing a new file with the same name except a <CODE>'c'</CODE> is added to the output file name. For example, <CODE>file</CODE> is <CODE>"site.sl"</CODE>, then the function produces a new file named <CODE>site.slc</CODE>. <DT><B> Notes </B><DD><P>The <CODE>method</CODE> parameter is not used in the current implementation. Its use is reserved for the future. For now, set it to <CODE>0</CODE>. <DT><B> See Also </B><DD><P><CODE>evalfile</CODE> </DL> <P> <P> <H2><A NAME="eval"></A> <A NAME="ss15.3">15.3 <B>eval</B></A> </H2> <P> <DL> <DT><B> Synopsis </B><DD><P>Interpret a string as <B>S-lang</B> code <DT><B> Usage </B><DD><P><CODE>eval (String_Type expression)</CODE> <DT><B> Description </B><DD><P>The <CODE>eval</CODE> function parses a string as S-Lang code and executes the result. This is a useful function in many contexts such as dynamically generating function definitions where there is no way to generate them otherwise. <DT><B> Example </B><DD><P> <BLOCKQUOTE><CODE> <PRE> if (0 == is_defined ("my_function")) eval ("define my_function () { message (\"my_function\"); }"); </PRE> </CODE></BLOCKQUOTE> <DT><B> See Also </B><DD><P><CODE>is_defined, autoload, evalfile</CODE> </DL> <P> <P> <H2><A NAME="evalfile"></A> <A NAME="ss15.4">15.4 <B>evalfile</B></A> </H2> <P> <DL> <DT><B> Synopsis </B><DD><P>Interpret a file containing <B>S-lang</B> code. <DT><B> Usage </B><DD><P><CODE>Integer_Type evalfile (String_Type file)</CODE> <DT><B> Description </B><DD><P>The <CODE>evalfile</CODE> function loads <CODE>file</CODE> into the interpreter. If no errors were encountered, <CODE>1</CODE> will be returned; otherwise, a <B>S-lang</B> error will be generated and the function will return zero. <DT><B> Example </B><DD><P> <BLOCKQUOTE><CODE> <PRE> define load_file (file) { ERROR_BLOCK { _clear_error (); } () = evalfile (file); } </PRE> </CODE></BLOCKQUOTE> <DT><B> See Also </B><DD><P><CODE>eval, autoload</CODE> </DL> <P> <P> <P> <HR> <A HREF="slangfun-16.html">Next</A> <A HREF="slangfun-14.html">Previous</A> <A HREF="slangfun.html#toc15">Contents</A> </BODY> </HTML>