1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Add scoped functions

This commit is contained in:
Étienne Fildadut 2021-12-10 23:22:06 +01:00
parent 3d32f35d67
commit fef498b3d7
16 changed files with 1164 additions and 58 deletions

View file

@ -5,10 +5,14 @@ $ f
b
$ c
c
~ cycle("a","b","c")
~ cycle(&a,&b,&c)
~ f
~ f
~ f
~ f
~ f
~ f

View file

@ -0,0 +1,40 @@
:n = 0
$ f(c=1)
:a = []
start: {a}
~ a!insert(c)
~ n += 1
before recursion {c}: {a}
~ n < 5
~ f(c+1)
after recursion {c}: {a}
new list each time:
~ f
$ g(c=1, a=[])
start: {a}
~ a!insert(c)
~ n += 1
before recursion {c}: {a}
~ n < 5
~ g(c+1, a)
after recursion {c}: {a}
pass list:
~ n := 0
~ g

View file

@ -0,0 +1,566 @@
local _={}
_[249]={}
_[248]={}
_[247]={}
_[246]={}
_[245]={}
_[244]={}
_[243]={}
_[242]={}
_[241]={}
_[240]={}
_[239]={}
_[238]={}
_[237]={}
_[236]={}
_[235]={}
_[234]={}
_[233]={}
_[232]={}
_[231]={}
_[230]={}
_[229]={}
_[228]={}
_[227]={}
_[226]={}
_[225]={}
_[224]={}
_[223]={}
_[222]={}
_[221]={}
_[220]={}
_[219]={}
_[218]={}
_[217]={}
_[216]={}
_[215]={}
_[214]={}
_[213]={}
_[212]={}
_[211]={}
_[210]={}
_[209]={}
_[208]={}
_[207]={}
_[206]={}
_[205]={}
_[204]={}
_[203]={}
_[202]={}
_[201]={}
_[200]={}
_[199]={}
_[198]={}
_[197]={}
_[196]={}
_[195]={}
_[194]={}
_[193]={}
_[192]={}
_[191]={}
_[190]={}
_[189]={}
_[188]={}
_[187]={}
_[186]={}
_[185]={}
_[184]={}
_[183]={}
_[182]={}
_[181]={}
_[180]={}
_[179]={}
_[178]={}
_[177]={}
_[176]={}
_[175]={}
_[174]={}
_[173]={}
_[172]={}
_[171]={}
_[170]={}
_[169]={}
_[168]={}
_[167]={}
_[166]={}
_[165]={}
_[164]={}
_[163]={}
_[162]={}
_[161]={}
_[160]={}
_[159]={}
_[158]={}
_[157]={}
_[156]={}
_[155]={tags=_[249],text="[1, 2, 3, 4, 5]"}
_[154]={tags=_[248],text=": "}
_[153]={tags=_[247],text="1"}
_[152]={tags=_[246],text="after recursion "}
_[151]={tags=_[245],text="[1, 2, 3, 4, 5]"}
_[150]={tags=_[244],text=": "}
_[149]={tags=_[243],text="2"}
_[148]={tags=_[242],text="after recursion "}
_[147]={tags=_[241],text="[1, 2, 3, 4, 5]"}
_[146]={tags=_[240],text=": "}
_[145]={tags=_[239],text="3"}
_[144]={tags=_[238],text="after recursion "}
_[143]={tags=_[237],text="[1, 2, 3, 4, 5]"}
_[142]={tags=_[236],text=": "}
_[141]={tags=_[235],text="4"}
_[140]={tags=_[234],text="after recursion "}
_[139]={tags=_[233],text="[1, 2, 3, 4, 5]"}
_[138]={tags=_[232],text=": "}
_[137]={tags=_[231],text="5"}
_[136]={tags=_[230],text="before recursion "}
_[135]={tags=_[229],text="[1, 2, 3, 4]"}
_[134]={tags=_[228],text="start: "}
_[133]={tags=_[227],text="[1, 2, 3, 4]"}
_[132]={tags=_[226],text=": "}
_[131]={tags=_[225],text="4"}
_[130]={tags=_[224],text="before recursion "}
_[129]={tags=_[223],text="[1, 2, 3]"}
_[128]={tags=_[222],text="start: "}
_[127]={tags=_[221],text="[1, 2, 3]"}
_[126]={tags=_[220],text=": "}
_[125]={tags=_[219],text="3"}
_[124]={tags=_[218],text="before recursion "}
_[123]={tags=_[217],text="[1, 2]"}
_[122]={tags=_[216],text="start: "}
_[121]={tags=_[215],text="[1, 2]"}
_[120]={tags=_[214],text=": "}
_[119]={tags=_[213],text="2"}
_[118]={tags=_[212],text="before recursion "}
_[117]={tags=_[211],text="[1]"}
_[116]={tags=_[210],text="start: "}
_[115]={tags=_[209],text="[1]"}
_[114]={tags=_[208],text=": "}
_[113]={tags=_[207],text="1"}
_[112]={tags=_[206],text="before recursion "}
_[111]={tags=_[205],text="[]"}
_[110]={tags=_[204],text="start: "}
_[109]={tags=_[203],text="pass list:"}
_[108]={tags=_[202],text="[1]"}
_[107]={tags=_[201],text=": "}
_[106]={tags=_[200],text="1"}
_[105]={tags=_[199],text="after recursion "}
_[104]={tags=_[198],text="[2]"}
_[103]={tags=_[197],text=": "}
_[102]={tags=_[196],text="2"}
_[101]={tags=_[195],text="after recursion "}
_[100]={tags=_[194],text="[3]"}
_[99]={tags=_[193],text=": "}
_[98]={tags=_[192],text="3"}
_[97]={tags=_[191],text="after recursion "}
_[96]={tags=_[190],text="[4]"}
_[95]={tags=_[189],text=": "}
_[94]={tags=_[188],text="4"}
_[93]={tags=_[187],text="after recursion "}
_[92]={tags=_[186],text="[5]"}
_[91]={tags=_[185],text=": "}
_[90]={tags=_[184],text="5"}
_[89]={tags=_[183],text="before recursion "}
_[88]={tags=_[182],text="[]"}
_[87]={tags=_[181],text="start: "}
_[86]={tags=_[180],text="[4]"}
_[85]={tags=_[179],text=": "}
_[84]={tags=_[178],text="4"}
_[83]={tags=_[177],text="before recursion "}
_[82]={tags=_[176],text="[]"}
_[81]={tags=_[175],text="start: "}
_[80]={tags=_[174],text="[3]"}
_[79]={tags=_[173],text=": "}
_[78]={tags=_[172],text="3"}
_[77]={tags=_[171],text="before recursion "}
_[76]={tags=_[170],text="[]"}
_[75]={tags=_[169],text="start: "}
_[74]={tags=_[168],text="[2]"}
_[73]={tags=_[167],text=": "}
_[72]={tags=_[166],text="2"}
_[71]={tags=_[165],text="before recursion "}
_[70]={tags=_[164],text="[]"}
_[69]={tags=_[163],text="start: "}
_[68]={tags=_[162],text="[1]"}
_[67]={tags=_[161],text=": "}
_[66]={tags=_[160],text="1"}
_[65]={tags=_[159],text="before recursion "}
_[64]={tags=_[158],text="[]"}
_[63]={tags=_[157],text="start: "}
_[62]={tags=_[156],text="new list each time:"}
_[61]={_[152],_[153],_[154],_[155]}
_[60]={_[148],_[149],_[150],_[151]}
_[59]={_[144],_[145],_[146],_[147]}
_[58]={_[140],_[141],_[142],_[143]}
_[57]={_[136],_[137],_[138],_[139]}
_[56]={_[134],_[135]}
_[55]={_[130],_[131],_[132],_[133]}
_[54]={_[128],_[129]}
_[53]={_[124],_[125],_[126],_[127]}
_[52]={_[122],_[123]}
_[51]={_[118],_[119],_[120],_[121]}
_[50]={_[116],_[117]}
_[49]={_[112],_[113],_[114],_[115]}
_[48]={_[110],_[111]}
_[47]={_[109]}
_[46]={_[105],_[106],_[107],_[108]}
_[45]={_[101],_[102],_[103],_[104]}
_[44]={_[97],_[98],_[99],_[100]}
_[43]={_[93],_[94],_[95],_[96]}
_[42]={_[89],_[90],_[91],_[92]}
_[41]={_[87],_[88]}
_[40]={_[83],_[84],_[85],_[86]}
_[39]={_[81],_[82]}
_[38]={_[77],_[78],_[79],_[80]}
_[37]={_[75],_[76]}
_[36]={_[71],_[72],_[73],_[74]}
_[35]={_[69],_[70]}
_[34]={_[65],_[66],_[67],_[68]}
_[33]={_[63],_[64]}
_[32]={_[62]}
_[31]={"return"}
_[30]={"text",_[61]}
_[29]={"text",_[60]}
_[28]={"text",_[59]}
_[27]={"text",_[58]}
_[26]={"text",_[57]}
_[25]={"text",_[56]}
_[24]={"text",_[55]}
_[23]={"text",_[54]}
_[22]={"text",_[53]}
_[21]={"text",_[52]}
_[20]={"text",_[51]}
_[19]={"text",_[50]}
_[18]={"text",_[49]}
_[17]={"text",_[48]}
_[16]={"text",_[47]}
_[15]={"text",_[46]}
_[14]={"text",_[45]}
_[13]={"text",_[44]}
_[12]={"text",_[43]}
_[11]={"text",_[42]}
_[10]={"text",_[41]}
_[9]={"text",_[40]}
_[8]={"text",_[39]}
_[7]={"text",_[38]}
_[6]={"text",_[37]}
_[5]={"text",_[36]}
_[4]={"text",_[35]}
_[3]={"text",_[34]}
_[2]={"text",_[33]}
_[1]={"text",_[32]}
return {_[1],_[2],_[3],_[4],_[5],_[6],_[7],_[8],_[9],_[10],_[11],_[12],_[13],_[14],_[15],_[16],_[17],_[18],_[19],_[20],_[21],_[22],_[23],_[24],_[25],_[26],_[27],_[28],_[29],_[30],_[31]}
--[[
{ "text", { {
tags = {},
text = "new list each time:"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "1"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "2"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[2]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "3"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[3]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "4"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[4]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "5"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[5]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "4"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[4]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "3"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[3]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "2"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[2]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "1"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1]"
} } }
{ "text", { {
tags = {},
text = "pass list:"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "1"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[1]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "2"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[1, 2]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "3"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2, 3]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[1, 2, 3]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "4"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2, 3, 4]"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "[1, 2, 3, 4]"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "5"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2, 3, 4, 5]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "4"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2, 3, 4, 5]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "3"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2, 3, 4, 5]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "2"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2, 3, 4, 5]"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "1"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "[1, 2, 3, 4, 5]"
} } }
{ "return" }
]]--

View file

@ -0,0 +1,19 @@
:n = 0
$ f(c=1)
:a = 1
start: {a}
~ a := a + 1
~ n += 1
before recursion {c}: {a}
~ n < 5
~ f(c+1)
after recursion {c}: {a}
~ f

View file

@ -0,0 +1,278 @@
local _={}
_[121]={}
_[120]={}
_[119]={}
_[118]={}
_[117]={}
_[116]={}
_[115]={}
_[114]={}
_[113]={}
_[112]={}
_[111]={}
_[110]={}
_[109]={}
_[108]={}
_[107]={}
_[106]={}
_[105]={}
_[104]={}
_[103]={}
_[102]={}
_[101]={}
_[100]={}
_[99]={}
_[98]={}
_[97]={}
_[96]={}
_[95]={}
_[94]={}
_[93]={}
_[92]={}
_[91]={}
_[90]={}
_[89]={}
_[88]={}
_[87]={}
_[86]={}
_[85]={}
_[84]={}
_[83]={}
_[82]={}
_[81]={}
_[80]={}
_[79]={}
_[78]={}
_[77]={}
_[76]={}
_[75]={tags=_[121],text="2"}
_[74]={tags=_[120],text=": "}
_[73]={tags=_[119],text="1"}
_[72]={tags=_[118],text="after recursion "}
_[71]={tags=_[117],text="2"}
_[70]={tags=_[116],text=": "}
_[69]={tags=_[115],text="2"}
_[68]={tags=_[114],text="after recursion "}
_[67]={tags=_[113],text="2"}
_[66]={tags=_[112],text=": "}
_[65]={tags=_[111],text="3"}
_[64]={tags=_[110],text="after recursion "}
_[63]={tags=_[109],text="2"}
_[62]={tags=_[108],text=": "}
_[61]={tags=_[107],text="4"}
_[60]={tags=_[106],text="after recursion "}
_[59]={tags=_[105],text="2"}
_[58]={tags=_[104],text=": "}
_[57]={tags=_[103],text="5"}
_[56]={tags=_[102],text="before recursion "}
_[55]={tags=_[101],text="1"}
_[54]={tags=_[100],text="start: "}
_[53]={tags=_[99],text="2"}
_[52]={tags=_[98],text=": "}
_[51]={tags=_[97],text="4"}
_[50]={tags=_[96],text="before recursion "}
_[49]={tags=_[95],text="1"}
_[48]={tags=_[94],text="start: "}
_[47]={tags=_[93],text="2"}
_[46]={tags=_[92],text=": "}
_[45]={tags=_[91],text="3"}
_[44]={tags=_[90],text="before recursion "}
_[43]={tags=_[89],text="1"}
_[42]={tags=_[88],text="start: "}
_[41]={tags=_[87],text="2"}
_[40]={tags=_[86],text=": "}
_[39]={tags=_[85],text="2"}
_[38]={tags=_[84],text="before recursion "}
_[37]={tags=_[83],text="1"}
_[36]={tags=_[82],text="start: "}
_[35]={tags=_[81],text="2"}
_[34]={tags=_[80],text=": "}
_[33]={tags=_[79],text="1"}
_[32]={tags=_[78],text="before recursion "}
_[31]={tags=_[77],text="1"}
_[30]={tags=_[76],text="start: "}
_[29]={_[72],_[73],_[74],_[75]}
_[28]={_[68],_[69],_[70],_[71]}
_[27]={_[64],_[65],_[66],_[67]}
_[26]={_[60],_[61],_[62],_[63]}
_[25]={_[56],_[57],_[58],_[59]}
_[24]={_[54],_[55]}
_[23]={_[50],_[51],_[52],_[53]}
_[22]={_[48],_[49]}
_[21]={_[44],_[45],_[46],_[47]}
_[20]={_[42],_[43]}
_[19]={_[38],_[39],_[40],_[41]}
_[18]={_[36],_[37]}
_[17]={_[32],_[33],_[34],_[35]}
_[16]={_[30],_[31]}
_[15]={"return"}
_[14]={"text",_[29]}
_[13]={"text",_[28]}
_[12]={"text",_[27]}
_[11]={"text",_[26]}
_[10]={"text",_[25]}
_[9]={"text",_[24]}
_[8]={"text",_[23]}
_[7]={"text",_[22]}
_[6]={"text",_[21]}
_[5]={"text",_[20]}
_[4]={"text",_[19]}
_[3]={"text",_[18]}
_[2]={"text",_[17]}
_[1]={"text",_[16]}
return {_[1],_[2],_[3],_[4],_[5],_[6],_[7],_[8],_[9],_[10],_[11],_[12],_[13],_[14],_[15]}
--[[
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "1"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "2"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "3"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "4"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "start: "
}, {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "before recursion "
}, {
tags = {},
text = "5"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "4"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "3"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "2"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "after recursion "
}, {
tags = {},
text = "1"
}, {
tags = {},
text = ": "
}, {
tags = {},
text = "2"
} } }
{ "return" }
]]--

View file

@ -0,0 +1,32 @@
(FIXME compare with fe/janet types
$ f()
:a = 1
{a}
~ a := a + 1
$ g
:a = 1
{a}
~ a := a + 1
scoped:
~ f
~ f
~ f
unscoped:
~ g
~ g
~ g

View file

@ -0,0 +1,70 @@
local _={}
_[33]={}
_[32]={}
_[31]={}
_[30]={}
_[29]={}
_[28]={}
_[27]={}
_[26]={}
_[25]={text="3",tags=_[33]}
_[24]={text="2",tags=_[32]}
_[23]={text="1",tags=_[31]}
_[22]={text="unscoped:",tags=_[30]}
_[21]={text="1",tags=_[29]}
_[20]={text="1",tags=_[28]}
_[19]={text="1",tags=_[27]}
_[18]={text="scoped:",tags=_[26]}
_[17]={_[25]}
_[16]={_[24]}
_[15]={_[23]}
_[14]={_[22]}
_[13]={_[21]}
_[12]={_[20]}
_[11]={_[19]}
_[10]={_[18]}
_[9]={"return"}
_[8]={"text",_[17]}
_[7]={"text",_[16]}
_[6]={"text",_[15]}
_[5]={"text",_[14]}
_[4]={"text",_[13]}
_[3]={"text",_[12]}
_[2]={"text",_[11]}
_[1]={"text",_[10]}
return {_[1],_[2],_[3],_[4],_[5],_[6],_[7],_[8],_[9]}
--[[
{ "text", { {
tags = {},
text = "scoped:"
} } }
{ "text", { {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "unscoped:"
} } }
{ "text", { {
tags = {},
text = "1"
} } }
{ "text", { {
tags = {},
text = "2"
} } }
{ "text", { {
tags = {},
text = "3"
} } }
{ "return" }
]]--