Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected repl behaviour #6

Closed
andrewnc opened this issue Aug 24, 2020 · 10 comments
Closed

Unexpected repl behaviour #6

andrewnc opened this issue Aug 24, 2020 · 10 comments

Comments

@andrewnc
Copy link
Contributor

andrewnc commented Aug 24, 2020

I have encountered this behaviour a few times when using BQN. I will enter an expression, but instead of an output OR an error, I will see what seems to be a call graph.

For example,
{π•©βŸ0} 3 ->

v0=e[1];if(v0===null)err();
v1=e[5];if(v1===null)err();
v2=e[2];if(v2===null)err();
v0=call(v1,v0,v2);
v1={e:e,p:6};
v0=set(1,v1,v0);

v0=O[21];
v1={e:e,p:7};
v0=set(1,v1,v0);
v1={e:e,p:8};
v0=set(1,v1,v0);

v0=e[6];if(v0===null)err();
v1=O[21];
v2=e.p[66];if(v2===null)err();
v3=D[121](e);
if(v2.m!==2)err();v1=v2(v3,v1);
v0=call(v1,v0);

v0=e[1];if(v0===null)err();
v1={e:e,p:9};
v0=set(1,v1,v0);

v0=D[122](e);
v1={e:e,p:10};
v0=set(1,v1,v0);

v0=e[7];if(v0===null)err();
v1=e[10];if(v1===null)err();
v2=e.p[1];if(v2===null)err();
v3=e[4];if(v3===null)err();
v4=e[2];if(v4===null)err();
v2=((f,g,h)=>(x,w)=>call(g,call(h,x,w),has(f)?call(f,x,w):f))(v4,v3,v2);
if(v1.m!==1)err();v1=v1(v2);
v0=call(v1,v0);
v1={e:e,p:11};
v0=set(1,v1,v0);

v0=e[8];if(v0===null)err();
v1=e.p[55];if(v1===null)err();
v0=call(v1,v0);
v1=e[10];if(v1===null)err();
v2=e.p[1];if(v2===null)err();
v3=e.p[119];if(v3===null)err();
v4=e[4];if(v4===null)err();
if(v3.m!==1)err();v3=v3(v4);
v4=e[2];if(v4===null)err();
v2=((f,g,h)=>(x,w)=>call(g,call(h,x,w),has(f)?call(f,x,w):f))(v4,v3,v2);
if(v1.m!==1)err();v1=v1(v2);
v0=call(v1,v0);
v1={e:e,p:12};
v0=set(1,v1,v0);

v0=e[6];if(v0===null)err();
v1=O[21];
v2=e.p[66];if(v2===null)err();
v3=e.p[3];if(v3===null)err();
v4=e[11];if(v4===null)err();
v5=e[12];if(v5===null)err();
v4=list([v4,v5]);
if(v3.m!==1)err();v3=v3(v4);
v4=e.p[115];if(v4===null)err();
v5=O[21];
v6=e.p[7];if(v6===null)err();
v7=e.p[48];if(v7===null)err();
if(v6.m!==2)err();v5=v6(v7,v5);
v3=((f,g,h)=>(x,w)=>call(g,call(h,x,w),has(f)?call(f,x,w):f))(v5,v4,v3);
v4=e.p[115];if(v4===null)err();
v5=e.p[42];if(v5===null)err();
v3=((f,g,h)=>(x,w)=>call(g,call(h,x,w),has(f)?call(f,x,w):f))(v5,v4,v3);
if(v2.m!==2)err();v1=v2(v3,v1);
v0=call(v1,v0);
return v0;}

and 2β—Ά"abcdef" ->

v0=e[1];if(v0===null)err();
v1=D[120](e);
v2=e[5];if(v2===null)err();
v3=e.p[115];if(v3===null)err();
v4=e[1];if(v4===null)err();
v5=e[4];if(v5===null)err();
v6=e[2];if(v6===null)err();
v4=call(v5,v4,v6);
v2=call(v3,v2,v4);
if(v1.m!==1)err();v1=v1(v2);
v2=e[2];if(v2===null)err();
v0=call(v1,v0,v2);
return v0;}

Am I missing a simple symbol for echoing / printing in these situations? I would love some clarity here.

@dzaima
Copy link

dzaima commented Aug 24, 2020

It's printing the source code of the function. The JS BQN compiler converts your code to JS code to be evaluated, and it seems there's nothing preventing that source code from just being printed. As a simpler example, try just !.

@andrewnc
Copy link
Contributor Author

Ok, fascinating, is this a user error on my end?

@dzaima
Copy link

dzaima commented Aug 24, 2020

There's no reason to not allow printing functions, whatever that ends up as being. It could of course be made to print something nicer, but that's probably of relatively low priority compared to other things about the language.

@andrewnc
Copy link
Contributor Author

Oh! I see, I am trying to call the functions, is there something obvious I'm missing to initiate that call?

@dzaima
Copy link

dzaima commented Aug 24, 2020

{π•©βŸ0} 3 is equivalent to 3⍟0, which is syntactically like 3⍣0 in APL - you aren't calling anything, you end up with a 2-modifier (dyadic operator in APL terms), derived to a function. Similarly for 2β—Ά"abcdef" - it's again just deriving a 2-modifier

@andrewnc
Copy link
Contributor Author

That makes sense, I'm coming from J and am still getting the hang of things.

How do I repeat 3 "0"s and select the 2th item respectively?

@mlochbaum
Copy link
Owner

Those would be 3β₯Š0 and 2βŠ‘"abcdef". See Indices for more discussion on Select (⊏) versus Pick (βŠ‘) though.

@dzaima
Copy link

dzaima commented Aug 24, 2020

As a quick test, anything circled is a 2-modifier (aka conjunction; βŒ½β‰ are exceptions and are functions similar to APL), and superscripts (˜¨˘⁼⌜´`) are 1-modifiers (adverbs); see this

@andrewnc
Copy link
Contributor Author

Ok perfect! I got my simple example working

{𝕩‿𝕩 β₯Š 1∾ 𝕩β₯Š0} 3

Thank you both for the help.

@mlochbaum
Copy link
Owner

mlochbaum commented Aug 24, 2020

The non-array part of formatting was just casting to a string with ""+x (it has to be implemented in Javascript, since there isn't a way to find a scalar's type from BQN yet). I've improved it to detect primitives and infinities, and use Β― for a minus sign. For non-primitive functions and modifiers, it just prints the type, for example *1-modifier*. Since they're anonymous functions, deconstructing them to get better output would be difficult with the current VM. But at least there are no raw function printouts any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants