Skip to content

Commit d361dcc

Browse files
committed
introduce new word crouch
1 parent 426f8db commit d361dcc

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

dist/index.ems.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,6 +3590,23 @@ var coreWords = {
35903590
return [s, pl];
35913591
}
35923592
},
3593+
'crouch': {
3594+
sig: [[{ type: 'list<string>', use: 'pop-each!' }, { type: 'P', use: 'run!' }], [{ type: 'runOf P' }]],
3595+
typeCompose: "compose",
3596+
compose: function (s, pl) {
3597+
var words = toPLOrNull(s === null || s === void 0 ? void 0 : s.pop());
3598+
var argList = toArrOfStrOrNull(s === null || s === void 0 ? void 0 : s.pop());
3599+
if (words !== null && argList) {
3600+
var values = map(function () { return s === null || s === void 0 ? void 0 : s.pop(); }, argList);
3601+
var localWD = zipObj(reverse(argList), values);
3602+
var newWords = toPLOrNull(subInWD(localWD, words));
3603+
if (newWords) {
3604+
s.push(newWords);
3605+
}
3606+
}
3607+
return [s, pl];
3608+
}
3609+
},
35933610
'pounce': {
35943611
sig: [[{ type: 'list<string>', use: 'pop-each!' }, { type: 'P', use: 'run!' }], [{ type: 'runOf P' }]],
35953612
typeCompose: "compose",

dist/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,6 +3596,23 @@ var coreWords = {
35963596
return [s, pl];
35973597
}
35983598
},
3599+
'crouch': {
3600+
sig: [[{ type: 'list<string>', use: 'pop-each!' }, { type: 'P', use: 'run!' }], [{ type: 'runOf P' }]],
3601+
typeCompose: "compose",
3602+
compose: function (s, pl) {
3603+
var words = toPLOrNull(s === null || s === void 0 ? void 0 : s.pop());
3604+
var argList = toArrOfStrOrNull(s === null || s === void 0 ? void 0 : s.pop());
3605+
if (words !== null && argList) {
3606+
var values = r.map(function () { return s === null || s === void 0 ? void 0 : s.pop(); }, argList);
3607+
var localWD = r.zipObj(r.reverse(argList), values);
3608+
var newWords = toPLOrNull(subInWD(localWD, words));
3609+
if (newWords) {
3610+
s.push(newWords);
3611+
}
3612+
}
3613+
return [s, pl];
3614+
}
3615+
},
35993616
'pounce': {
36003617
sig: [[{ type: 'list<string>', use: 'pop-each!' }, { type: 'P', use: 'run!' }], [{ type: 'runOf P' }]],
36013618
typeCompose: "compose",

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.3.0",
3+
"version": "2.3.1",
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,26 @@ export const coreWords: WordDictionary = {
948948
return [s, pl];
949949
}
950950
},
951+
'crouch': {
952+
sig: [[{ type: 'list<string>', use: 'pop-each!' }, { type: 'P', use: 'run!' }], [{ type: 'runOf P' }]],
953+
typeCompose: "compose",
954+
compose: (s, pl) => {
955+
const words = toPLOrNull(s?.pop());
956+
const argList = toArrOfStrOrNull(s?.pop());
957+
if (words !== null && argList) {
958+
const values: Word[] = r.map(() => s?.pop(), argList);
959+
const localWD: { [index: string]: Word } =
960+
r.zipObj(r.reverse(argList), values);
961+
const newWords: ProgramList =
962+
toPLOrNull(subInWD(localWD, words));
963+
964+
if (newWords) {
965+
s.push(newWords);
966+
}
967+
}
968+
return [s, pl];
969+
}
970+
},
951971
'pounce': {
952972
sig: [[{ type: 'list<string>', use: 'pop-each!' }, { type: 'P', use: 'run!' }], [{ type: 'runOf P' }]],
953973
typeCompose: "compose",

tests/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const testIt = (p, expected_result) => {
8686
let testCount = 0;
8787
let allPassing = 1;
8888
allPassing &= testIt("Hello Pounce", ["Hello", "Pounce"]);
89-
allPassing &= testIt("words", [["words","word","dup","dup2","swap","drop","round","+","-","/","%","*","&","|","^","~","&&","||","!","E","LN10","LN2","LOG10E","LOG2E","PI","SQRT1_2","SQRT2","abs","acos","acosh","asin","asinh","atan","atan2","atanh","cbrt","ceil","cos","cosh","exp","expm1","floor","hypot","log","log10","log1p","log2","max","min","pow","seedrandom","random","sign","sin","sinh","sqrt","tan","tanh","trunc","play","pounce","dip","dip2","rotate","rollup","rolldown","if-else","ifte","=","==","!=",">","<",">=","<=","concat","cons","uncons","push","pop","constrec","linrec","linrec5","binrec","times","map","map2","filter","reduce","split","size","outAt","inAt","depth","stack-copy"]]);
89+
allPassing &= testIt("words", [["words","word","dup","dup2","swap","drop","round","+","-","/","%","*","&","|","^","~","&&","||","!","E","LN10","LN2","LOG10E","LOG2E","PI","SQRT1_2","SQRT2","abs","acos","acosh","asin","asinh","atan","atan2","atanh","cbrt","ceil","cos","cosh","exp","expm1","floor","hypot","log","log10","log1p","log2","max","min","pow","seedrandom","random","sign","sin","sinh","sqrt","tan","tanh","trunc","play","crouch","pounce","dip","dip2","rotate","rollup","rolldown","if-else","ifte","=","==","!=",">","<",">=","<=","concat","cons","uncons","push","pop","constrec","linrec","linrec5","binrec","times","map","map2","filter","reduce","split","size","outAt","inAt","depth","stack-copy"]]);
9090
allPassing &= testIt("[dup2] word", [{"sig":[[{"type":"A","use":"observe"},{"type":"B","use":"observe"}],[{"type":"A"},{"type":"B"},{"type":"A"},{"type":"B"}]],"typeCompose":"compose","compose":[["dup"],"dip","dup",["swap"],"dip"]}]);
9191
allPassing &= testIt("[word] word", [{"sig":[[{"type":"list<string>)"}],[{"type":"record"}]],"typeCompose":"compose"}]);
9292
allPassing &= testIt("497 seedrandom random", [0.5311601270295587]);
@@ -250,6 +250,11 @@ allPassing &= testIt(`
250250
[size 1 <=] [] [uncons [>] split] [concat] binrec
251251
`, [["a", "b", "b", "c", "d", "e", "f", "g", "h", "j"]]);
252252

253+
allPassing &= testIt("0 0 [a b] [a b +] crouch", [[0, 0, '+']]);
254+
allPassing &= testIt("22 -3 [a b] [a b a + *] crouch", [[22, -3, 22, '+', '*']]);
255+
allPassing &= testIt(`0.5 1 [m b] [[x] [m x * b +] pounce] crouch`, [[['x'], [0.5, 'x', '*', 1, '+'], 'pounce']]);
256+
allPassing &= testIt(`4 0.5 1 [m b] [[x] [m x * b +] pounce] crouch play`, [3]);
257+
253258
allPassing &= testIt("0 0 [a b] [a b +] pounce", [0]);
254259
allPassing &= testIt("0 [a] [a] pounce", [0]);
255260

0 commit comments

Comments
 (0)