# The chemical-compounds Reference Manual

## Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

# The chemical-compounds Reference Manual

This is the chemical-compounds Reference Manual, version 1.0.1, generated automatically by Declt version 2.4 "Will Decker" on Wed Jun 20 10:55:07 2018 GMT+0.

Next: , Previous: , Up: Top   [Contents][Index]

## 1 Introduction

```chemical-compounds -- parsing, pretty-printing, and formula weights of
chemical compounds.

Copyright 2004 Peter Scott
Released under the LLGPL (see
http://opensource.franz.com/preamble.html).

Introduction
============

Sometimes you want to be able to parse chemical formulas in a
normal, user-friendly syntax. For example, water is usually written
"H2O". This representation is good for users, but for Lisp code, you
need a different representation. In chemical-compounds, H2O would be
represented as ((H 2) O).

A more complicated molecule is glucose, C6H12O6. This is
((C 6) (H 12) (O 6)) in our internal representation. You may have
noticed that "C6H12O6" is ugly and hard to read, due to the clunky way
that plain text deals with the subscripts. Therefore, in the format
used by chemical-compounds, glucose is "C6 H12 O6", with spaces.

Some chemical formulas parenthesize parts of the compound and add a
subscript. The formula "(C O2)4 H2" would be parsed as
(((C (O 2)) 4) (H 2)).

Functions
=========

The :compounds package exports four functions:

(pprint-compound compound stream): takes a compound in the Lisp
internal representation and prints it to a stream in the pretty
syntax.

Example:

(with-output-to-string (s) (pprint-compound '((H 2) O) s))
=> "H2 O"

-----------

(parse-compound string): parse a compound string and return the
internal Lisp representation of it.

Examples:

(parse-compound "C6 H12 O6") => ((C 6) (H 12) (O 6))
(parse-compound "(C O2)4 H2") => (((C (O 2)) 4) (H 2))

-----------

(formula-weight compound): Calculate the number of grams per mole of a
compound.

Examples:

(formula-weight '((C 6) (H 12) (O 6))) => 180.15768
(formula-weight (parse-compound "C6 H12 O6")) => 180.15768

-----------

(get-compound compound): Return a compound designator given either a
compound designator or a string in compound syntax.

Examples:

(get-compound "C6 H12 O6") => ((C 6) (H 12) (O 6))
(get-compound '((C 6) (H 12) (O 6))) => ((C 6) (H 12) (O 6))

-----------

If you have any questions, please ask them on the chemboy-devel mailing list
at .
```

Next: , Previous: , Up: Top   [Contents][Index]

## 2 Systems

The main system appears first, followed by any subsystem dependency.

Previous: , Up: Systems   [Contents][Index]

### 2.1 chemical-compounds

Author

Peter Scott

License

LLGPL

Version

1.0.1

Dependency

periodic-table

Source

chemical-compounds.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

## 3 Files

Files are sorted by type and then listed depth-first from the systems components trees.

Previous: , Up: Files   [Contents][Index]

### 3.1 Lisp

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.1 chemical-compounds.asd

Location

chemical-compounds.asd

Systems

chemical-compounds (system)

Packages

#### 3.1.2 chemical-compounds/parsing.lisp

Parent

chemical-compounds (system)

Location

parsing.lisp

Packages
Exported Definitions

parse-compound (function)

Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.3 chemical-compounds/compounds.lisp

Dependency

parsing.lisp (file)

Parent

chemical-compounds (system)

Location

compounds.lisp

Packages
Exported Definitions
Internal Definitions

element-number-pair-p (function)

Next: , Previous: , Up: Top   [Contents][Index]

## 4 Packages

Packages are listed by definition order.

Next: , Previous: , Up: Packages   [Contents][Index]

### 4.1 chemical-compounds-system

Source

chemical-compounds.asd

Use List
• asdf/interface
• common-lisp

Next: , Previous: , Up: Packages   [Contents][Index]

### 4.2 compound-parsing

Source

parsing.lisp (file)

Use List

common-lisp

Exported Definitions

parse-compound (function)

Internal Definitions

Previous: , Up: Packages   [Contents][Index]

### 4.3 compounds

Source

compounds.lisp (file)

Use List
• elements
• common-lisp
Exported Definitions
Internal Definitions

element-number-pair-p (function)

Next: , Previous: , Up: Top   [Contents][Index]

## 5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.

Next: , Previous: , Up: Definitions   [Contents][Index]

### 5.1 Exported definitions

Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.1 Functions

Function: formula-weight COMPOUND

The number of grams per mole of a compound

Package
Source

compounds.lisp (file)

Function: get-compound COMPOUND

Return a compound designator given either a compound designator or a string in compound syntax

Package
Source

compounds.lisp (file)

Function: parse-compound STRING &optional INDEX END &aux COMPONENT-LIST COMPONENT-LIST-STACK ELEMENT-SYMBOL NUMBER C
Package
Source

parsing.lisp (file)

Function: parse-compound STRING

Parse a compound string, such as C6 H12 O6

Package
Source

compounds.lisp (file)

Function: pprint-compound COMPOUND &key STREAM PARENS

Pretty print a compound, putting parens around it if ‘parens’ is t. This is so ugly that I’ve come to despise it, but it works. Don’t touch it unless you want it to shatter into a million little pieces.

Package
Source

compounds.lisp (file)

Previous: , Up: Definitions   [Contents][Index]

### 5.2 Internal definitions

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.1 Special variables

Special Variable: *meta-debug*

Should META output debugging information?

Package
Source

parsing.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.2 Macros

Macro: defmeta NAME OTHER-ARGS &body BODY
Package
Source

parsing.lisp (file)

Macro: match X
Package
Source

parsing.lisp (file)

Macro: match-type X V
Package
Source

parsing.lisp (file)

Macro: matchit X
Package
Source

parsing.lisp (file)

Macro: meta-labels FUNCTIONS &body BODY
Package
Source

parsing.lisp (file)

Macro: with-string-accumulation STRINGS &body BODY

Given a list of symbols, create character output streams bound to the symbols given in ‘strings’ with -STREAM appended, execute ‘body’ in this environment, and SETF all the symbol-values of the symbols in ‘strings’ to the values of their respective string output streams.

It also defines a local function FORCE-STRING-ACCUMULATION which will do the SETFing when it is called. It is called automatically at the end of the block, but you can call it earlier, as many times as you like. It clears the string streams, so be careful when using it.

The utility of this macro may not be readily apparent, but is can be very handy in META parsers which need to accumulate characters into strings.

Package
Source

parsing.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.3 Functions

Function: compileit X
Package
Source

parsing.lisp (file)

Function: copy-meta INSTANCE
Package
Source

parsing.lisp (file)

Function: ctoi D
Package
Source

parsing.lisp (file)

Function: element-number-pair-p COMPOUND

Return t if ‘compound’ is a pair of an element and a number of that element, such as (C 6)

Package
Source

compounds.lisp (file)

Function: end-of-string-p STRING INDEX

Is index above the maximum index allowed for a given string?

Package
Source

parsing.lisp (file)

Function: make-meta &key (CHAR CHAR) (FORM FORM)
Package
Source

parsing.lisp (file)

Function: meta-char INSTANCE
Function: (setf meta-char) VALUE INSTANCE
Package
Source

parsing.lisp (file)

Function: meta-form INSTANCE
Function: (setf meta-form) VALUE INSTANCE
Package
Source

parsing.lisp (file)

Function: meta-p OBJECT
Package
Source

parsing.lisp (file)

Function: meta-reader S C
Package
Source

parsing.lisp (file)

Function: parse-int STRING &optional INDEX END &aux S D N
Package
Source

parsing.lisp (file)

Function: parse-query-string STRING &optional INDEX END &aux AMOUNT UNIT ELEMENT BASE-TRIPLE CONDITIONS C
Package
Source

parsing.lisp (file)

Function: parse-x-and-y STRING &optional INDEX END &aux VERB NOUN C
Package
Source

parsing.lisp (file)

Function: strings->element-list ELEMENT NUMBER

Convert an element (which may be a string or a compound designator) and a number given as a string into a proper compound designator.

Package
Source

parsing.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.4 Structures

Structure: meta ()
Package
Source

parsing.lisp (file)

Direct superclasses

structure-object (structure)

Direct methods

print-object (method)

Direct slots
Slot: char
Readers

meta-char (function)

Writers

(setf meta-char) (function)

Slot: form
Readers

meta-form (function)

Writers

(setf meta-form) (function)

Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.5 Types

Type: digit ()
Package
Source

parsing.lisp (file)

Type: non-rparen-char ()
Package
Source

parsing.lisp (file)

Type: nonspace-char ()
Package
Source

parsing.lisp (file)

Type: number-char ()
Package
Source

parsing.lisp (file)

Type: space-char ()
Package
Source

parsing.lisp (file)

Previous: , Up: Top   [Contents][Index]

## Appendix A Indexes

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.1 Concepts

Jump to: C   F   L
Jump to: C   F   L

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.2 Functions

Jump to: (   C   D   E   F   G   M   P   S   W
Jump to: (   C   D   E   F   G   M   P   S   W

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.3 Variables

Jump to: *   C   F   S
Jump to: *   C   F   S

Previous: , Up: Indexes   [Contents][Index]

### A.4 Data types

Jump to: C   D   M   N   P   S   T
Jump to: C   D   M   N   P   S   T