Reader Functions

function read [handle]

read an Idio expression from handle

Param handle:

handle to read from, defaults to the current input handle

Type handle:

handle, optional

Return:

object

Reader Operators

Reader operators operate on the Abstract Syntax Tree. Their purpose is to rewrite the AST to normalize expressions.

Having read an expression in, the reader will scan it for operators and apply the operator to the “before” and “after” parts of the expression. The operators job is to return a re-written expression that has been normalised.

For example, commonly, arithmetic uses infix operators: 1 + 2. However, Idio only accepts functions as the first element of a form so the original expression needs to be rewritten.

For many infix operators you can imagine that it is easy enough to rewrite the expression with the symbol for the operator now in first place + 1 2 as the symbol + will evaluate to the arithmetic addition function.

The arithmetic + function handles a number of varargs possibilities whereas we know that the infix + operator is a binary addition function, that is it always has two arguments. So, in this particular case, the + infix operator rewrites the expressions as binary-+ 1 2 where binary-+ is expecting exactly two arguments.

Standard Operators

There are a number of standard operators and modules can define their own. An obvious operator for the job-control Module to define is |.

+ - * /

infix binary arithmetic

lt le eq ge gt

infix binary numeric comparison

and or

infix multiple logical sequence and and or

=+ +=

infix array-push! and array-unshift! operators

=- -=

postfix array-pop! and array-shift! operators

.

infix value-index

Comments

There are several comment forms in Idio – none of which are shell-like. That’s largely because the shell comment character, #, is used to tell the reader that some interesting construction is coming its way.

Line

You can comment everything to the end of the line with ;.

S-exp

You can comment out an entire s-exp with #;, including multi-line s-exps.

S-exps are usually parenthesised expressions, (...), which, noting that Idio doesn’t always use them, makes this kind of comment less useful.

a := 10

#;(and my-debug-flag
       (set! a 5))

a                    ; 10

Multi-line

There are two types of nestable multi-line comments:

  • #* ... *# for regular commentary

  • #| ... |# which is reserved for “semi-literate” comments

    These are a nod to Donald Knuth’s literate programming but inverted: code interspersed with natural language.

    That said, this form doesn’t do anything other than act as another form of multi-line comment. Some thought needs to be put into what to do with semi-literate commentary. Currently, junk it!

The multi-line part of these forms should be self-explanatory, the nestable part is more interesting.

In the first instance it means you can safely comment out any larger block of code that already contains a multi-line comment:

#*

a := 10

#*
if my-debug-flag {
  a = 5
}
*#

a
*#

These two forms are mutually nestable meaning you can comment out parts of your semi-literate commentary and put semi-literate commentary in your comments.

Escaping

There are always some corner cases where we might need to escape our way out:

WARNING: the web page language interpreter doesn’t handle these very well!

#*

; don't use the comment terminator, \*#, here

*#

If you want to use something other than \ for the escape character, put the graphic character (ie., not whitespace) immediately after the opening #* or #|:

#*%

; don't use the comment terminator, %*#, here

*#

Last built at 2024-12-21T07:10:43Z+0000 from 62cca4c (dev) for Idio 0.3.b.6