Skip to content

Commit e42356d

Browse files
committed
pattern naming for crouch and pounce #15
1 parent f81f997 commit e42356d

File tree

5 files changed

+84
-13
lines changed

5 files changed

+84
-13
lines changed

dist/index.ems.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { is, keys, omit, path, map, zipObj, reverse, head, tail, init, last, propOr, findIndex, mergeRight, concat } from 'ramda';
1+
import { is, keys, omit, path, map, reverse, head, tail, init, last, propOr, findIndex, mergeRight, concat } from 'ramda';
22
import NP from 'number-precision';
33
import Prando from 'prando';
44

@@ -2731,6 +2731,25 @@ var subInWD = function (localWD, words) {
27312731
var resolveWord = consReslover(localWD);
27322732
return map(resolveWord, words);
27332733
};
2734+
var deepZipObj = function (n, s) {
2735+
if (!n.length || !s.length) {
2736+
return {};
2737+
}
2738+
var name = n.pop();
2739+
if (is(String, name)) {
2740+
var value = s.pop();
2741+
var def = {};
2742+
def[name] = value;
2743+
return __assign(__assign({}, deepZipObj(n, s)), def);
2744+
}
2745+
if (is(Array, name)) {
2746+
var value = s.pop();
2747+
if (is(Array, name)) {
2748+
return __assign(__assign({}, deepZipObj(n, s)), deepZipObj(name, value));
2749+
}
2750+
}
2751+
return null;
2752+
};
27342753
var coreWords = {
27352754
'words': {
27362755
compose: function (s) {
@@ -3392,15 +3411,17 @@ var coreWords = {
33923411
return [s, pl];
33933412
}
33943413
},
3395-
// binds names to stack values within one phrase of words
3414+
// binds names to stack values within a phrase of words
33963415
'crouch': {
33973416
dt: '[[[S+]F][F]]',
33983417
compose: function (s, pl) {
33993418
var words = toPLOrNull(s === null || s === void 0 ? void 0 : s.pop());
34003419
var argList = toArrOfStrOrNull(s === null || s === void 0 ? void 0 : s.pop());
34013420
if (words !== null && argList) {
34023421
var values = map(function () { return s === null || s === void 0 ? void 0 : s.pop(); }, argList);
3403-
var localWD = zipObj(reverse(argList), values);
3422+
// const localWD: { [index: string]: Word } =
3423+
// r.zipObj(r.flatten(r.reverse(argList)), r.flatten(values));
3424+
var localWD = deepZipObj(reverse(argList), values);
34043425
var newWords = toPLOrNull(subInWD(localWD, words));
34053426
if (newWords) {
34063427
s.push(newWords);
@@ -3416,7 +3437,9 @@ var coreWords = {
34163437
var argList = toArrOfStrOrNull(s === null || s === void 0 ? void 0 : s.pop());
34173438
if (words !== null && argList) {
34183439
var values = map(function () { return s === null || s === void 0 ? void 0 : s.pop(); }, argList);
3419-
var localWD = zipObj(reverse(argList), values);
3440+
// const localWD: { [index: string]: Word } =
3441+
// r.zipObj(r.flatten(r.reverse(argList)), r.flatten(values));
3442+
var localWD = deepZipObj(reverse(argList), values);
34203443
var newWords = toPLOrNull(subInWD(localWD, words));
34213444
if (newWords) {
34223445
pl = newWords.concat(pl);

dist/index.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,25 @@ var subInWD = function (localWD, words) {
27372737
var resolveWord = consReslover(localWD);
27382738
return r.map(resolveWord, words);
27392739
};
2740+
var deepZipObj = function (n, s) {
2741+
if (!n.length || !s.length) {
2742+
return {};
2743+
}
2744+
var name = n.pop();
2745+
if (r.is(String, name)) {
2746+
var value = s.pop();
2747+
var def = {};
2748+
def[name] = value;
2749+
return __assign(__assign({}, deepZipObj(n, s)), def);
2750+
}
2751+
if (r.is(Array, name)) {
2752+
var value = s.pop();
2753+
if (r.is(Array, name)) {
2754+
return __assign(__assign({}, deepZipObj(n, s)), deepZipObj(name, value));
2755+
}
2756+
}
2757+
return null;
2758+
};
27402759
var coreWords = {
27412760
'words': {
27422761
compose: function (s) {
@@ -3398,15 +3417,17 @@ var coreWords = {
33983417
return [s, pl];
33993418
}
34003419
},
3401-
// binds names to stack values within one phrase of words
3420+
// binds names to stack values within a phrase of words
34023421
'crouch': {
34033422
dt: '[[[S+]F][F]]',
34043423
compose: function (s, pl) {
34053424
var words = toPLOrNull(s === null || s === void 0 ? void 0 : s.pop());
34063425
var argList = toArrOfStrOrNull(s === null || s === void 0 ? void 0 : s.pop());
34073426
if (words !== null && argList) {
34083427
var values = r.map(function () { return s === null || s === void 0 ? void 0 : s.pop(); }, argList);
3409-
var localWD = r.zipObj(r.reverse(argList), values);
3428+
// const localWD: { [index: string]: Word } =
3429+
// r.zipObj(r.flatten(r.reverse(argList)), r.flatten(values));
3430+
var localWD = deepZipObj(r.reverse(argList), values);
34103431
var newWords = toPLOrNull(subInWD(localWD, words));
34113432
if (newWords) {
34123433
s.push(newWords);
@@ -3422,7 +3443,9 @@ var coreWords = {
34223443
var argList = toArrOfStrOrNull(s === null || s === void 0 ? void 0 : s.pop());
34233444
if (words !== null && argList) {
34243445
var values = r.map(function () { return s === null || s === void 0 ? void 0 : s.pop(); }, argList);
3425-
var localWD = r.zipObj(r.reverse(argList), values);
3446+
// const localWD: { [index: string]: Word } =
3447+
// r.zipObj(r.flatten(r.reverse(argList)), r.flatten(values));
3448+
var localWD = deepZipObj(r.reverse(argList), values);
34263449
var newWords = toPLOrNull(subInWD(localWD, words));
34273450
if (newWords) {
34283451
pl = newWords.concat(pl);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pounce-lang/core",
3-
"version": "2.5.3",
3+
"version": "2.5.4",
44
"description": "A concatenative programming language written in Javascript, Pounce has roots in Forth, Joy, Cat and Kitten.",
55
"main": "dist/index.js",
66
"module": "dist/index.ems.js",

src/words/core.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ const subInWD = (localWD: { [index: string]: Word }, words: Word[]): Word[] => {
9595
return r.map(resolveWord, words);
9696
}
9797

98+
const deepZipObj = (n: Word[], s: Word[]): { [index: string]: Word } => {
99+
if(!n.length || !s.length) {
100+
return {};
101+
}
102+
const name = n.pop();
103+
if (r.is(String, name)) {
104+
const value = s.pop();
105+
let def: { [index: string]: Word } = {};
106+
def[name as string] = value;
107+
return {...deepZipObj(n, s), ...def};
108+
}
109+
if (r.is(Array, name)) {
110+
const value = s.pop();
111+
if (r.is(Array, name)) {
112+
return {...deepZipObj(n, s), ...deepZipObj(name as Word[], value as Word[])};
113+
}
114+
}
115+
return null;
116+
};
98117

99118
export const coreWords: WordDictionary = {
100119
'words': {
@@ -757,16 +776,18 @@ export const coreWords: WordDictionary = {
757776
return [s, pl];
758777
}
759778
},
760-
// binds names to stack values within one phrase of words
779+
// binds names to stack values within a phrase of words
761780
'crouch': {
762781
dt: '[[[S+]F][F]]',
763782
compose: (s, pl) => {
764783
const words = toPLOrNull(s?.pop());
765784
const argList = toArrOfStrOrNull(s?.pop());
766785
if (words !== null && argList) {
767786
const values: Word[] = r.map(() => s?.pop(), argList);
768-
const localWD: { [index: string]: Word } =
769-
r.zipObj(r.reverse(argList), values);
787+
// const localWD: { [index: string]: Word } =
788+
// r.zipObj(r.flatten(r.reverse(argList)), r.flatten(values));
789+
const localWD: { [index: string]: Word } =
790+
deepZipObj(r.reverse(argList), values);
770791
const newWords: ProgramList =
771792
toPLOrNull(subInWD(localWD, words));
772793

@@ -784,8 +805,10 @@ export const coreWords: WordDictionary = {
784805
const argList = toArrOfStrOrNull(s?.pop());
785806
if (words !== null && argList) {
786807
const values: Word[] = r.map(() => s?.pop(), argList);
787-
const localWD: { [index: string]: Word } =
788-
r.zipObj(r.reverse(argList), values);
808+
// const localWD: { [index: string]: Word } =
809+
// r.zipObj(r.flatten(r.reverse(argList)), r.flatten(values));
810+
const localWD: { [index: string]: Word } =
811+
deepZipObj(r.reverse(argList), values);
789812
const newWords: ProgramList =
790813
toPLOrNull(subInWD(localWD, words));
791814

tests/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ allPassing &= testIt("1 2 3 4 [a b c x] [a x x * * b x * c + +] pounce", [27]);
294294
allPassing &= testIt("2 3 4 [slope y-intercept x] [slope x * y-intercept +] pounce", [11]);
295295

296296
allPassing &= testIt("2 3 4 [slope y-intercept x] [slope x * y-intercept +] crouch", [[2, 4, "*", 3, "+"]]);
297+
allPassing &= testIt("1 2 [3 4] [a b [c d]] [a b c d] crouch", [[1, 2, 3, 4]]);
298+
allPassing &= testIt("1 2 [3 4] [a b [c d]] [a b c d] pounce", [1, 2, 3, 4]);
297299

298300
allPassing &= testIt("3 type-of", ['Nat']);
299301
allPassing &= testIt("-3 type-of", ['Neg']);

0 commit comments

Comments
 (0)