The chemical-compounds Reference Manual

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 4.0 beta 2 "William Riker" on Mon Aug 15 03:24:33 2022 GMT+0.

Table of Contents


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 .

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 (system).

Source

chemical-compounds.asd.

Child Components

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


3.1.1 chemical-compounds/chemical-compounds.asd

Source

chemical-compounds.asd.

Parent Component

chemical-compounds (system).

ASDF Systems

chemical-compounds.

Packages

chemical-compounds-system.


3.1.2 chemical-compounds/parsing.lisp

Source

chemical-compounds.asd.

Parent Component

chemical-compounds (system).

Packages

compound-parsing.

Public Interface
Internals

3.1.3 chemical-compounds/compounds.lisp

Dependency

parsing.lisp (file).

Source

chemical-compounds.asd.

Parent Component

chemical-compounds (system).

Packages

compounds.

Public Interface
Internals

element-number-pair-p (function).


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.

4.2 compounds

Source

compounds.lisp.

Use List
  • common-lisp.
  • elements.
Public Interface
Internals

element-number-pair-p (function).


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

4.3 compound-parsing

Source

parsing.lisp.

Use List

common-lisp.

Public Interface

parse-compound (function).

Internals

5 Definitions

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


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

5.1 Public Interface


5.1.1 Ordinary functions

Function: formula-weight (compound)

The number of grams per mole of a compound

Package

compounds.

Source

compounds.lisp.

Function: get-compound (compound)

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

Package

compounds.

Source

compounds.lisp.

Function: parse-compound (string)

Parse a compound string, such as C6 H12 O6

Package

compounds.

Source

compounds.lisp.

Function: parse-compound (string &optional index end)
Package

compound-parsing.

Source

parsing.lisp.

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

compounds.

Source

compounds.lisp.


5.1.2 Standalone methods

Method: print-object ((object meta) stream)
Source

parsing.lisp.


5.2 Internals


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

5.2.1 Special variables

Special Variable: *meta-debug*

Should META output debugging information?

Package

compound-parsing.

Source

parsing.lisp.


5.2.2 Macros

Macro: defmeta (name other-args &body body)
Package

compound-parsing.

Source

parsing.lisp.

Macro: match (x)
Package

compound-parsing.

Source

parsing.lisp.

Macro: match-type (x v)
Package

compound-parsing.

Source

parsing.lisp.

Macro: matchit (x)
Package

compound-parsing.

Source

parsing.lisp.

Macro: meta-labels (functions &body body)
Package

compound-parsing.

Source

parsing.lisp.

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

compound-parsing.

Source

parsing.lisp.


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

5.2.3 Ordinary functions

Function: compileit (x)
Package

compound-parsing.

Source

parsing.lisp.

Function: copy-meta (instance)
Package

compound-parsing.

Source

parsing.lisp.

Function: ctoi (d)
Package

compound-parsing.

Source

parsing.lisp.

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

compounds.

Source

compounds.lisp.

Function: end-of-string-p (string index)

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

Package

compound-parsing.

Source

parsing.lisp.

Function: make-meta (&key char form)
Package

compound-parsing.

Source

parsing.lisp.

Reader: meta-char (instance)
Writer: (setf meta-char) (instance)
Package

compound-parsing.

Source

parsing.lisp.

Target Slot

char.

Reader: meta-form (instance)
Writer: (setf meta-form) (instance)
Package

compound-parsing.

Source

parsing.lisp.

Target Slot

form.

Function: meta-p (object)
Package

compound-parsing.

Source

parsing.lisp.

Function: meta-reader (s c)
Package

compound-parsing.

Source

parsing.lisp.

Function: parse-int (string &optional index end)
Package

compound-parsing.

Source

parsing.lisp.

Function: parse-query-string (string &optional index end)
Package

compound-parsing.

Source

parsing.lisp.

Function: parse-x-and-y (string &optional index end)
Package

compound-parsing.

Source

parsing.lisp.

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

compound-parsing.

Source

parsing.lisp.


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

5.2.4 Structures

Structure: meta
Package

compound-parsing.

Source

parsing.lisp.

Direct superclasses

structure-object.

Direct methods

print-object.

Direct slots
Slot: char
Package

common-lisp.

Readers

meta-char.

Writers

(setf meta-char).

Slot: form
Readers

meta-form.

Writers

(setf meta-form).


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

5.2.5 Types

Type: digit ()
Package

compound-parsing.

Source

parsing.lisp.

Type: non-rparen-char ()
Package

compound-parsing.

Source

parsing.lisp.

Type: nonspace-char ()
Package

compound-parsing.

Source

parsing.lisp.

Type: number-char ()
Package

compound-parsing.

Source

parsing.lisp.

Type: space-char ()
Package

compound-parsing.

Source

parsing.lisp.


Appendix A Indexes


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

A.1 Concepts


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

A.2 Functions

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

(
(setf meta-char): Private ordinary functions
(setf meta-form): Private ordinary functions

C
compileit: Private ordinary functions
copy-meta: Private ordinary functions
ctoi: Private ordinary functions

D
defmeta: Private macros

E
element-number-pair-p: Private ordinary functions
end-of-string-p: Private ordinary functions

F
formula-weight: Public ordinary functions
Function, (setf meta-char): Private ordinary functions
Function, (setf meta-form): Private ordinary functions
Function, compileit: Private ordinary functions
Function, copy-meta: Private ordinary functions
Function, ctoi: Private ordinary functions
Function, element-number-pair-p: Private ordinary functions
Function, end-of-string-p: Private ordinary functions
Function, formula-weight: Public ordinary functions
Function, get-compound: Public ordinary functions
Function, make-meta: Private ordinary functions
Function, meta-char: Private ordinary functions
Function, meta-form: Private ordinary functions
Function, meta-p: Private ordinary functions
Function, meta-reader: Private ordinary functions
Function, parse-compound: Public ordinary functions
Function, parse-compound: Public ordinary functions
Function, parse-int: Private ordinary functions
Function, parse-query-string: Private ordinary functions
Function, parse-x-and-y: Private ordinary functions
Function, pprint-compound: Public ordinary functions
Function, strings->element-list: Private ordinary functions

G
get-compound: Public ordinary functions

M
Macro, defmeta: Private macros
Macro, match: Private macros
Macro, match-type: Private macros
Macro, matchit: Private macros
Macro, meta-labels: Private macros
Macro, with-string-accumulation: Private macros
make-meta: Private ordinary functions
match: Private macros
match-type: Private macros
matchit: Private macros
meta-char: Private ordinary functions
meta-form: Private ordinary functions
meta-labels: Private macros
meta-p: Private ordinary functions
meta-reader: Private ordinary functions
Method, print-object: Public standalone methods

P
parse-compound: Public ordinary functions
parse-compound: Public ordinary functions
parse-int: Private ordinary functions
parse-query-string: Private ordinary functions
parse-x-and-y: Private ordinary functions
pprint-compound: Public ordinary functions
print-object: Public standalone methods

S
strings->element-list: Private ordinary functions

W
with-string-accumulation: Private macros

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