-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7225823
commit af9e8d8
Showing
20 changed files
with
264 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
import * as pkg from '../../../package.json'; | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: Dusa helpers | ||
--- | ||
|
||
In addition to the [Dusa class and solution iterator](/docs/api/dusa/) and the | ||
the [DusaSolution class](/docs/api/dusasolution/), the Dusa API includes a | ||
couple of other utility functions. | ||
|
||
### `compareTerm()` and `compareTerms()` | ||
|
||
Provides a consistent comparison function for sorting Dusa terms or list of | ||
Dusa terms. | ||
|
||
```typescript | ||
function compareTerm(t1: Term | BigTerm, t2: Term | BigTerm): number; | ||
function compareTerms(t: (Term | BigTerm)[], s: (Term | BigTerm)[]): number; | ||
``` | ||
|
||
### `termToString()` | ||
|
||
Provides a consistent way of making terms into strings. If `true` is passed | ||
as the `parens` argument, then structured terms with arguments will be | ||
surrounded by parentheses. | ||
|
||
```typescript | ||
function termToString(tm: Term | BigTerm, parens = false): string; | ||
``` | ||
|
||
### `check()` and `compile()` | ||
|
||
The `check()` function runs just static checks on a Dusa program, and returns | ||
a list of any issues that exist. | ||
|
||
```typescript | ||
interface Issue { | ||
type: 'Issue'; | ||
msg: string; | ||
severity: 'warning' | 'error'; | ||
loc?: SourceLocation; | ||
} | ||
function check(source: string): Issue[] | null; | ||
``` | ||
|
||
The `compile()` function transforms a Dusa source program into an | ||
intermediate "bytecode" representation which can be passed to the Dusa | ||
constructor instead of a source program. If there are any issues, the | ||
`DusaCompileError` exception will be thrown. | ||
|
||
```typescript | ||
interface DusaCompileError extends Error { | ||
issues: Issue[]; | ||
} | ||
function compile(source: string): BytecodeProgram; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
title: Using Dusa in your JavaScript programs | ||
--- | ||
|
||
As Julia Evans describes, in 2024 | ||
[there are basically three ways use JavaScript code in your project](https://jvns.ca/blog/2024/11/18/how-to-import-a-javascript-library/). | ||
|
||
1. A "classic" module that just defines a global variable | ||
2. An ES module | ||
3. Use a build system | ||
|
||
### Classic modules | ||
|
||
To use Dusa in your random web page, include the UMD module in a script tag in | ||
the head of your file, for example with unpkg like this: | ||
|
||
```html | ||
<script src="https://unpkg.com/dusa@0.1.6"></script> | ||
``` | ||
|
||
or with jsdelivr like this: | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/dusa@0.1.6"></script> | ||
``` | ||
|
||
This defines the `Dusa` name, which can be used to make new Dusa classes or | ||
access the various [helpers](/docs/api/helpers/). | ||
|
||
```javascript | ||
const dusa = new Dusa('fact is { mortal socrates, man socrates }.'); | ||
function handleClick() { | ||
const fact = Dusa.termToString(dusa.sample().get("fact")); | ||
document.getElementById("facts").innerText = fact; | ||
} | ||
``` | ||
|
||
* [Example 1: Glitch site](https://glitch.com/edit/#!/dusa-use-umd) | ||
* [Example 2: p5js sketch](https://editor.p5js.org/robsimmons/sketches/xcHwiBh2H) | ||
|
||
### ES modules | ||
|
||
ES modules can be used to access the [`Dusa` class](/docs/api/dusa/) and the | ||
[helpers](/docs/api/helpers/) in any development using ES modules, without | ||
requiring any build system. | ||
|
||
```javascript | ||
import { Dusa, termToString } from 'https://unpkg.com/dusa@0.1.6/lib/client.js'; | ||
const dusa = new Dusa('fact is { mortal socrates, man socrates }.'); | ||
console.log(termToString(dusa.solution.get('fact'))); | ||
``` | ||
|
||
The val.town examples used elsewhere in the docs use this way of importing | ||
Dusa. [Here's the example above on val.town](https://www.val.town/v/robsimmons/fieryPlumLeopon). | ||
|
||
### Build system imports | ||
|
||
If import `dusa` through NPM (or a similar package manager/build system), then | ||
you can import the [core `Dusa` class](/docs/api/dusa/) as well as the | ||
[helpers](/docs/api/helpers/) through the `'dusa'` import. | ||
|
||
```javascript | ||
// example.mjs | ||
import { Dusa, termToString } from 'dusa'; | ||
const dusa = new Dusa('fact is { mortal socrates, man socrates }.'); | ||
console.log(termToString(dusa.solution.get('fact'))); | ||
``` | ||
|
||
```javascript | ||
// example.cjs | ||
const { Dusa, termToString } = require('dusa'); | ||
const dusa = new Dusa('fact is { mortal socrates, man socrates }.'); | ||
console.log(termToString(dusa.solution.get('fact'))); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.