As I mentioned a few days ago, I tried to use APL to solve the sliding tiles puzzle. @ngn showed me an elegant way to generate the valid moves. I now have something that works, up to a point: gist.github.com/xpqz/550d032db953bc7f0d87bc8fd136ec5f
It finds the solution for a 2x2 puzzle, but for a 3x3 it basically never finishes.
My solution is clearly epically inefficient in APL.
@Adám - I've encountered interpreters for other languages that would do this; does Dyalog?: If the workspace/session is getting full, save it and reload it - that forces a garbage collection, which lets you work some more.
@dzaima - Good to know, although the question was less about how to force gc than about whether doing so, by hook or by crook, would allow one to continue to work after getting WS FULL (following up on @xpqz's comment).
@Adám - What's the (source code) compatibility between Dyalog and NARS2000? Mostly, I'm interested in knowing what to avoid using in either if I want to write code that will run in both.
@JeffZeitlin Obviously, the unique Dyalog functions and operators, as dzaima mentioned, but also things unique to NARS2000 like ⍡⍦‼⌻≈√π.. and the many constant notations. NARS2000 also requires and depends on explicit mention of dfn arguments, so you can't do {⎕←?4}¨⍳3 as that dfn is niladic (!). NARS2000 has some system labels that Dyalog doesn't have, etc. etc.
@Adám - Yes, I was just checking out some of that. For the most part, the project I have in mind is more-or-less vanilla APL - most of it would probably be doable without much difficulty on that IBM5150 emulator, if I do dfns as tradfns - so I just wanted to be sure that there weren't going to be any real GOTCHAs.
@JeffZeitlin I'm not sure what scoping NARS2000 uses, but if you do advanced stuff and try to convert dfns to tradfns or vice versa, you might hit differences there.
@Adám I have a question about what "If X is specified, it is an array whose major cells specify keys for corresponding major cells of Y. The Key operator ⌸ applies the function f to each unique key in X and the major cells of Y having that key." means, in the docs about ⌸
I guess I don't understand what the "major cells" are
@RGS The major cells are simply the subarrays of rank one less than the whole array's rank. I.e. scalars of a vector, vectors of a matrix, matrices (layers) of a 3D array, etc.
@RGS I can't promise everything is defined quite yet, but if you wonder what a term means in APL lingo, try APL Wiki. E.g. Major cell. If you fail to find something, let me know.
@Adám You are getting into really weird formatting things :P I was trying to understand if there was something really short and obvious I was missing; I doubt I need to go into the detail you are going into.
Either way, I'll remember in the future that ⎕FMT exists o/
Yes. It is not so hard to identify tacit APL. If the rightmost (bordering the end of the parenthesis or the statement) token is a function, you've got yourself some tacit code.
You don't actually need the parenthesis for stand-along tacit functions. They are just for clarity. The following is perfectly valid:
Makes sense; evaluation is from right to left and you can't really evaluate a function without arguments so if the rightmost "thing" is a function then the whole thing is a function. Is this reasoning ~accurate?
This is what I used :) I wanted to know what you think about that cheap trick I did there, appending 'ABCDF' to the grades I get and then subtracting 1 when I'm summarizing them
Do you want context / a link to the problem I'm talking about?
@RGS Rather than using conversion to and from string to round, you can use ⌊0.5+number but first multiply by a power of 10 to make the rounding happen at the right magnitude.
@RGS Instead of computing 1-⍨≢⍵ twice, you can give it a name inline. APL's assignments always have a "pass-through value" identical to whatever is on the right of ←, so {⍺,count,⍎1⍕100×len÷⍨count←1-⍨≢⍵} would work.
It is because it stores the code in tokenised form. If you start off with code in text files, it'll use the exact spacing you used. There's also a trick you can use to make it remember your spaces: Use 2⎕FIX to create the function. Once created, you can use the regular editor to modify it and whitespace will be preserved. So, e.g. to create and edit the function Foo, just do ⎕ED 2⎕FIX,⊂'Foo'
^ this space-removing thing is why i never use the in-Dyalog editor when making >10 char functions. I really like my whitespace as it is. Sometimes i just write in a text file and copy-paste to the )ed window :p
@RGS So you have to remember to use my trick. You can even stick it into a function. If you find yourself in the editor having already written a lot of stuff, select everything and copy to clipboard, escape the editor, run that definition expression or function, then paste.
@dzaima You can use my trick too. I was so surprised when I stumbled upon it.
@Adám ah, i first tried using 2⎕fix'test' which told me to make a file. what you were describing was another, even more obscure way to do an even more useful thing :|
@dzaima Firstly, it is a (relatively) new feature, and traditional Dyalog programmers are used to the auto-formatting. Secondly, it requires additional memory to keep it:
There also isn't much support for the feature. E.g. ⎕NR/⎕CR/⎕VR will return the detokenised form, not the actual source, and there's currently no way to get the actual source under program control. We're working on that though; it should probably be ⎕SRC.
@RGS ∘., has to apply , between all combos of elements from left and right argument, creating a new 2-by-2 array. But each application of , gives a 2-element vector, so each scalar element of the result matrix has to itself be a 2-element vector.
@RGS ⊃ "eXtracts" (it is on the X key) the contents of a particular element (or element's element, etc.), while ⌷ just fetches the element (or cell, really).