项目作者: technoblogy

项目描述 :
A query language and ATtiny database written in uLisp.
高级语言: Common Lisp
项目地址: git://github.com/technoblogy/query-language.git
创建时间: 2019-04-06T11:38:41Z
项目社区:https://github.com/technoblogy/query-language

开源协议:

下载


A query language and ATtiny database written in uLisp

This application is a simple query language to allow you to create a database of information about a particular domain, and then write queries to find answers to questions about that domain. It’s written in uLisp, so you could run it on a microcontroller board such as the Adafruit ItsyBitsy M4. Because uLisp is compatible with Common Lisp you could alternatively run it on any Common Lisp implementation.

It includes a sample database of information about Microchip ATtiny processors, to allow you to choose the best processor meeting the requirements of a particular project. Note that it doesn’t include information about the new ATtiny 0-Series or 1-Series families.

Alternatively you could use the query language to build an information system for your own application.

It’s a simplified version of a popular type of example given in several Lisp books, including: Paul Graham’s “On Lisp” (pp. 246-254), available as a PDF on his site: Download On Lisp, his “ANSI Common Lisp” (pp. 247-256), and Peter Norvig’s “Paradigms of Artificial Intelligence Programming” (pp 348-387), available as a PDF on GitHub: paip-lisp.

Running the query language

To install the query language on uLisp:

  • Copy the file query-language.lisp, paste it into the Arduino IDE Serial Monitor input field, and press Return.

  • Copy the file attiny-database.lisp, paste it into the Arduino IDE Serial Monitor input field, and press Return.

  • Give the command:

    1. (read-data)
  • Try out the examples below.

Submitting a query

To query the database you give a query of the form:

  1. (answer '(query) '(output))

where query is a query you want to submit to the database, and output is a list to format the output.

The query can contain variables beginning with a question mark, such as ?x, which will be set to matching values in the database. So, for example, the query:

  1. (flash ?c ?x)

will match every rule in the database starting with flash, such as:

  1. (flash attiny85 8192)

After this successful match the variable ?c will be set to attiny85 and ?x will be set to 8192. These values can be referred to later in the query, or in the output list.

You can combine queries with and, or, and not, and you can test values using test.

The output list can consist of a series of strings and variables to print the variables in each successful match. For example, after the above match the output list:

  1. ("Chip:" ?c "has flash:" ?x)

will print:

  1. Chip: attiny85 has flash: 8192

Examples

For example, the database allows you to ask questions such as:

  • Find the price (in pence) of each chip with 8 Kbytes of flash:
  1. > (answer '(and (flash ?c ?x) (price ?c ?k ?p) (test (= ?x 8192))) '("Chip:" ?c "Package:" ?k "Price:" ?p))
  2. Chip: attiny828 Package: tqfp Price: 84
  3. Chip: attiny88 Package: pdip Price: 143
  4. Chip: attiny88 Package: tqfp Price: 76
  5. Chip: attiny861 Package: pdip Price: 110
  6. Chip: attiny861 Package: soic Price: 92
  7. Chip: attiny841 Package: soic Price: 78
  8. Chip: attiny84 Package: pdip Price: 87
  9. Chip: attiny84 Package: soic Price: 60
  10. Chip: attiny85 Package: pdip Price: 90
  11. Chip: attiny85 Package: soic Price: 72
  • Find all chips with at least 10 Kbytes of flash:
  1. > (answer '(and (flash ?c ?x) (test (> ?x 10240))) '("Flash > 10K:" ?c))
  2. Flash > 10K: attiny1634
  3. Flash > 10K: attiny167
  • Find all chips that have I2C slave support in hardware:
  1. > (answer '(and (family ?c ?f) (i2c ?f slave)) '("I2C Slave support:" ?c))
  2. I2C Slave support: attiny828
  3. I2C Slave support: attiny1634
  4. I2C Slave support: attiny48
  5. I2C Slave support: attiny88
  6. I2C Slave support: attiny441
  7. I2C Slave support: attiny841
  • Find all chips that have at least three timers (8-bit or 16-bit):
  1. > (answer '(and (family ?c ?f) (timer8 ?f ?x) (timer16 ?f ?y) (test (>= (+ ?x ?y) 3)))
  2. '("3 Timers:" ?c))
  3. 3 Timers: attiny441
  4. 3 Timers: attiny841

For more information see http://www.ulisp.com/show?2I60.