Skip to content

Commit

Permalink
Remove $ get/set syntax
Browse files Browse the repository at this point in the history
Fixes #50

Remove `$` get/set syntax from Insitux.

* Remove `$` syntax handling from `getExe` and `exeOp` functions in `src/index.ts`.
* Remove `$` syntax handling from `set`, `get`, and `exe` functions in `src/web.ts`.
* Remove mention of `$` get/set syntax from `README.md`.
* Remove tests related to `$` syntax in `src/test.ts`.
* Bump version to 24.10.30 in `package.json` and `package-lock.json`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/phunanon/Insitux/issues/50?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
phunanon committed Oct 31, 2024
1 parent dbf760d commit a667e46
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 78 deletions.
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,6 @@ set-timeout set-interval

## Coding in Insitux

Like any programming language it is written down as _code_. Insitux takes your
code and follows it like complex instructions.
You and the Insitux app talk to each other in these ways:

| what | direction of data | example |
| ------ | ------------------------ | ----------------------------- |
| code | goes into the app | `(+ 2 2)` |
| return | comes out of the app | `4` |
| set | writes data | `($day.cycle_speed 100)` |
| get | reads data | `$day.cycle_speed` |
| exe | data goes both in an out | `(util.fire [0 0 0] [0 1 0])` |

### Writing the code

Most code is written as _expressions_ like `(+ 2 2)`. As you can see, values are
Expand Down Expand Up @@ -1138,16 +1126,6 @@ It can also be used as an identity function (i.e. `val`).

- Parameters take precedence over lets, vars, and functions.

- Insitux implementations are advised to support this behaviour:

```clj
($test.ing 123) → 123
$test.ing → 123
(ing "$test") → 123
(ing "$test" 456) → 456
$test.ing → 456
```

### Functions

**Named functions**
Expand Down
15 changes: 12 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "insitux",
"version": "24.10.21",
"version": "24.10.30",
"description": "Extensible scripting language written in portable TypeScript.",
"main": "dist/invoker.js",
"types": "dist/invoker.d.ts",
Expand Down
28 changes: 1 addition & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const insituxVersion = 241021;
export const insituxVersion = 241030;
import { asBoo } from "./checks";
import { arityCheck, keyOpErr, numOpErr, typeCheck, typeErr } from "./checks";
import { isLetter, isDigit, isSpace, isPunc } from "./checks";
Expand Down Expand Up @@ -1417,22 +1417,6 @@ function getExe(
if (name in ctx.env.vars) {
return getExe(ctx, ctx.env.vars[name], errCtx);
}
if (starts(name, "$")) {
return (params: Val[]) => {
if (!len(params)) {
_throw(monoArityError(op.t, errCtx));
}
if (!ctx.set) {
const m = `"set" feature not implemented on this platform`;
return _throw([{ e: "External", m, errCtx }]);
}
const err = ctx.set(substr(name, 1), params[0]);
if (err) {
_throw([{ e: "External", m: err, errCtx }]);
}
return params[0];
};
}
return (params: Val[]) => {
if (!ctx.exe) {
const m = `operation "${name}" does not exist"`;
Expand Down Expand Up @@ -1648,16 +1632,6 @@ function exeFunc(
stack.push(ctx.env.vars[name]);
} else if (name in ctx.env.funcs) {
stack.push(_fun(name));
} else if (starts(name, "$")) {
if (!ctx.get) {
const m = `"get" feature not implemented on this platform`;
return _throw([{ e: "External", m, errCtx }]);
}
const valAndErr = ctx.get(substr(name, 1));
if ("err" in valAndErr) {
return _throw([{ e: "External", m: valAndErr.err, errCtx }]);
}
stack.push(valAndErr);
} else {
_throw([{ e: "Reference", m: `"${name}" did not exist`, errCtx }]);
}
Expand Down
5 changes: 0 additions & 5 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,6 @@ const tests: {
out: `{"1" 4, "2" 4}`,
},
//Test environment functions
{
name: "set get",
code: `[($globals.time_offset 5.5) $globals.time_offset]`,
out: `[5.5 5.5]`,
},
{ name: "exe", code: `(test.function 123)`, out: `123\nnull` },
//Syntax errors
{ name: "Empty parens", code: `()`, err: ["Parse"] },
Expand Down
20 changes: 0 additions & 20 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,7 @@ import { Ctx, defaultCtx, ExternalFunctions, Val, ValOrErr } from "./types";
import { num, str, val2str, _nul, _str, _num, _boo } from "./val";
import { jsToIx } from "./val-translate";

let state = new Map<string, Val>();

const get = (key: string): ValOrErr =>
state.has(key) ? state.get(key)! : _nul();
const set = (key: string, val: Val) => {
state.set(key, val);
localStorage.setItem("insitux-state", JSON.stringify([...state.entries()]));
return undefined;
};

function exe(name: string, args: Val[]): ValOrErr {
if (args.length && args[0].t == "str" && args[0].v.startsWith("$")) {
if (args.length === 1) {
return get(`${args[0].v.substring(1)}.${name}`);
} else {
set(`${args[0].v.substring(1)}.${name}`, args[1]);
return args[1];
}
}
return { err: `operation ${name} does not exist` };
}

Expand Down Expand Up @@ -253,8 +235,6 @@ const loadScript = async (scriptEl: HTMLScriptElement) => {
};

window.onload = async () => {
const savedState = localStorage.getItem("insitux-state");
state = new Map<string, Val>(savedState ? JSON.parse(savedState) : []);
const scripts = Array.from(document.querySelectorAll("script")).filter(
el => el.type === "text/insitux",
);
Expand Down

0 comments on commit a667e46

Please sign in to comment.