Description

An interface to the programming language Q

Author

John Cowan

Version

Requires

Usage

(require-extension q-lang)

Download

q-lang.egg

Documentation

The q-lang egg provides a procedural interface to Q, a functional programming language based on equational term rewriting. It allows loading a file of equations or specifying them from within Scheme, and allows you to encode Q expressions in native source, native binary, or S-expression formats. You have access to the Q reduction interpreter and can set and clear Q variables.

The primitives of Q expressions are symbols, numbers, and booleans, which are represented in the obvious way in S-expression format. Q lists are likewise represented as Scheme lists, and Q tuples as Scheme vectors. Q function applications, however, are Scheme lists whose car is q:call, an illegal Q symbol; likewise, improper Q tuples are represented as improper Scheme lists whose car is q:tuple.

Q native source is represented using Scheme strings, and Q native binary objects are Chicken Scheme tagged pointers; the q:obj? predicate returns #t on these. Q binary objects can be embedded in S-expressions, and in particular a Q binary object may be passed to any routine that expects an S-expression.

procedure: (q:obj? OBJECT)

Returns #t if OBJECT is a Q binary object.

procedure: (q:to-obj EXP)

Returns a Q binary object representing EXP interpreted as a Q expression in S-expression format.

procedure: (q:code-to-obj STRING)

Returns a Q binary object representing STRING interpreted as Q native source code.

procedure: (q:to-exp EXP)

Returns a Scheme value in S-expression format representing EXP, which can be a Q binary object or a Scheme value representing a Q expression in S-expression format.

procedure: (q:code-to-exp STRING)

Returns a Scheme value in S-expression format representing STRING, which is interpreted as Q native source code.

procedure: (q:to-code EXP)

Returns a string in Q native source code format representing EXP, which can be a Q binary object or a Scheme value representing a Q expression in S-expression format.

procedure: (q:code-to-code STRING)

Returns a string in Q native source code format representing STRING, representing a string in Q native code format. This is not a no-op, because it syntax-checks the string and uses any unparsing rules specified in the Q program.

procedure: (q:reduce-to-obj EXP)

Returns a Q binary object representing the fully reduced form of EXP interpreted as a Q expression in S-expression format.

procedure: (q:code-reduce-to-obj STRING)

Returns a Q binary object representing the fully reduced form of STRING interpreted as Q native source code.

procedure: (q:reduce-to-exp EXP)

Returns a Scheme value in S-expression format representing the fully reduced form of EXP, which can be a Q binary object or a Scheme value representing a Q expression in S-expression format.

procedure: (q:code-reduce-to-exp STRING)

Returns a Scheme value in S-expression format representing the fully reduced form of STRING, which is interpreted as Q native source code.

procedure: (q:reduce-to-code EXP)

Returns a string in Q native source code format representing the fully reduced form of EXP, which can be a Q binary object or a Scheme value representing a Q expression in S-expression format.

procedure: (q:code-reduce-to-code STRING)

Returns a string in Q native source code format representing the fully reduced form of STRING, representing a string in Q native code format.

procedure: (q:load-rules! FILENAME)

Loads Q equations from the file named FILENAME. Any equations loaded by previous calls to q:load-rules! or q:set-rules! are discarded.

procedure: (q:set-rules! STRING)

Loads Q equations from STRING. Any equations loaded by previous calls to q:load-rules! or q:set-rules! are discarded.

procedure: (q:set-args! . ARGS

Loads the value of the Q tuple ARGV from the arguments ARGS. If an argument is not a string, it is converted to a string as if by display.

procedure: (q:define-exp VAR VALUE)

Defines the Q variable VAR, specified with a Scheme symbol, to have the value VALUE, specified as a Q expression in S-expression format.

procedure: (q:define-code VAR VALUE)

Defines the Q variable VAR, specified with a Scheme symbol, to have the value VALUE, specified as a Q expression in source code format.

procedure: (q:undefine VAR)

Causes the Q variable VAR, specified with a Scheme symbol, to have no value.

License

Copyright 2006 John Cowan.

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.