Functions | |
| muse_cell | fn_port_p (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_close (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_eof_p (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_print (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_write (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_read (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_read_line (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_flush (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_mickey (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_load (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_file_has_attached_code_p (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_write_xml (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_read_xml (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_xml (muse_env *env, void *context, muse_cell args) |
| {xml} | |
| muse_cell | fn_write_json (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_read_json (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_json (muse_env *env, void *context, muse_cell args) |
| {json} | |
| muse_cell | fn_exit (muse_env *env, void *context, muse_cell args) |
| muse_cell | fn_tab_syntax (muse_env *env, void *context, muse_cell args) |
| {tab-syntax} Changes the syntax of the currently reading port to the EZSCHEME syntax. | |
| muse_cell | fn_scheme_syntax (muse_env *env, void *context, muse_cell args) |
| {scheme-syntax} Changes the syntax of the currently reading port to the normal syntax. | |
(eof? port)
Returns T if the port has reached end of stream. Returns () if it hasn't reached end of stream.
References _t, MUSE_NIL, and port_eof().
(print ...expressions...)
Prints each expression to the standard output in sequence. Strings are printed without the quotes, so print can be used to print out messages for the user.
(write ...expressions...)
Writes the s-expressions to the standard output in sequence. Tries to write an s-expression such that it can be read back in using read, meaning strings will be enclosed in double quotes.
References muse_pwrite().
(read [port])
Reads a single sexpr from the standard input stream.
Supports the
References fn_read(), muse_add_recent_item(), MUSE_NIL, and muse_pread().
Referenced by fn_read().
(read-line [port])
Reads a single line from the given port or the standard input stream and returns it as a single string.
Supports the
References buffer_alloc(), buffer_free(), buffer_length(), buffer_putc(), buffer_to_string(), fn_read_line(), muse_add_recent_item(), MUSE_NIL, port_eof(), and port_getchar().
Referenced by fn_read_line().
(flush [port])
Flushes the accumulated output on the given port. If no port is given, flushes stdout.
References port_flush().
(mickey inport outport)
Reads in the stream from the input port, expands all mickey expressions and outputs to the output port.
References muse_mickey(), and MUSE_NIL.
(load "file.lisp")
(load port)
(load #nnn[...bytes...])
Reads and evaluates all expressions in the given file and returns the value of the last expression. You can pass it either a filename, or a port or a byte array. If you pass a filename, the file will be read in and loaded. If you pass a port, the port will be read in and loaded until you reach end-of-port. If you pass a byte array, it will be loaded just as though it were the byte contents of some file.
| error:load | Handler format:
(fn (resume 'error:load path) ...)
If the file is not found or could not be opened for some reason, this exception is raised. Resuming the exception with another file name will cause load to load that file instead. This exception is similar to |
References fn_load(), fn_with_bytes_as_port(), muse_fopen(), muse_functional_object_data(), muse_load(), muse_message(), MUSE_NIL, muse_pload(), muse_port(), muse_raise_error(), MUSE_TEXT_CELL, and muSEexec_check().
Referenced by fn_load().
(file-has-attached-code? path)
Some files such as exes, jpg and png can have muSE code attached at the end for special purposes. This function looks at the contents of the file and determines if the file has any attached code. If it does, the attached code can be loaded using load.
References muse_fopen(), MUSE_NIL, MUSE_T, MUSE_TEXT_CELL, muse_text_contents(), and muSEexec_check().
(write-xml [port] xml-node [object] [flags])
Converts an s-expr representation of an XML node (a tag, not an arbitrary node such as attribute nodes) into XML form and writes it out to the given port. The XML node representation is as follows -
(tag ((attr1 . "value1") (attr2 . "value2") ...) body1 body2 ... )
The flags is a list of symbols that indicate features to use. The only one feature you can indicate is 'with-header which will cause
<?xml version="1.0" encoding="UTF-8"?>
to be written out before the node is written out.
References muse_find_list_element(), muse_functional_object_data(), MUSE_NIL, and port_write().
(read-xml [port])
Reads one xml node (a simple subset of xml) and returns it in the canonical form:
<tag attr1="v1" attr2="v2">hello <b>world</b></tag>
is read in as -
(fn (@) '(tag ((attr1 . "v1") (attr2 . "v2")) "hello" (b () "world")))
For constant xml expressions, the following simple rules apply -
For constant xml expressions, the overhead of calling the function with nil argument is negligible since the entire constant part appears quoted.
For variable xml expressions, the function serves as a compiler for the xml template. The following templating facilities are available -
<tag attr=(format @.count)/>
(fn (@) (list 'tag (list (cons 'attr (format @.count)))))
<@style-string label="STYLENAME"/>
'@style-string
(fn (@) (@ '@style-string '((label . "STYLENAME"))))
Supports the
References fn_read_xml(), and muse_add_recent_item().
Referenced by fn_read_xml().
{xml}
Reads the XML expression immediately following {xml} as a value. This way you can use XML data inline in muSE code.
References muse_current_port().
(write-json [port] thing)
thing is either a number, string, vector or a hashtable. Writes the object in JSON format to the given port, or to the current output port (usually stdout) if the port is omitted.
References muse_current_port(), MUSE_NIL, muse_pop_recent_scope(), muse_port(), muse_push_recent_scope(), and MUSE_T.
(read-json [port])
Reads and returns a JSON compatible object - which is either a number, a string, a vector or a hashtable. The values in the vectors and hashtables themselves must be JSON compatible objects.
If you have nested containers expressed in JSON, you can use the (get ...) function to index deeply into the structure. For example,
> (define j (read-json))
{"kind":"prime-numbers","message":[2,3,5,7,11,13,17]}
{hashtable '((message . {vector 2 3 5 7 11 13 17}) (kind . "prime-numbers"))}
> (get j 'message 4)
11
References fn_read_json(), muse_current_port(), muse_pop_recent_scope(), muse_port(), and muse_push_recent_scope().
Referenced by fn_read_json().
{json}
Switches the reader temporarily to the JSON reader so that the next expression is treated as a JSON object. After one JSON item is read in, it returns the reader to the original Scheme reader. So you can use {json} and then follow with an inline definition of a complex nested data structure you need as a value in Scheme.
The difference between (read-json) and {json} is that (read-json) reads a constant JSON expression which is therefore useful to parse query results from servers. OTOH, {json} treats the following JSON expression as a template from which it synthesizes a muSE expression which *when evaluated* will yield the JSON object. This means you can use {json} within function bodies as well. When using {json}, you can insert arbitrary muSE expressions in the value positions of objects and arrays. The JSON keywords 'true' and 'false' will end up as quoted symbols and the keyword 'null' will end up being translated as (). Other than that, value positions can use full Scheme expressions. Here is an example -
> (define (info name)
{json}
{ "name" : name,
"kind" : "nice guy",
"email" : (format name "@muvee.com"),
"age" : [94] } )
The onus is on the coder to make sure that muSE sub-expressions evaluate to valid JSON objects. Otherwise it will not be possible to write the object using write-json.
Note that if any part of the object expression doesn't contain variables or muSE sub-expressions, then it is treated as a constant and pre-evaluated at read-time so that it won't have to be evaluated repeatedly. This also means that constant parts of a JSON object will end up being shared with other JSON objects. You need to be aware of this only if you want to modify the JSON objects you create.
References fn_json(), muse_current_port(), muse_pop_recent_scope(), and muse_push_recent_scope().
Referenced by fn_json().
1.6.3