How about Gets←{⍎⍺,'←⍵'} called as 'ns.hello'Gets'world'?
@xpqz Right, that's why I'm working on a better way, my current proposal being ns ⎕NS⊂'mystring' 42 (the enclose is so you can set multiple values at once).
@Adám any reason you couldn't just allow not needing the ⊂ and deciding on whether element 1 is a string? seems like an awfully stupid thing to need it for the most often case
@dzaima Two reasons: 1) There's the option of using the current namespace's value rather than supplying a new value; ns ⎕NS 'key1' 'key2' is thus equivalent to ns ⎕NS('key1' key1)('key2' key2) and 2) Backwards compatibility as ns ⎕NS 'key1' 'key2' already has the latter meaning from the first point.
@dzaima My proposal also allows ns ⎕NS ['key1' ⋄ 'key2'] (val1 ⋄ val2)
@dzaima Names cannot have spaces, namespace members must have valid APL names. It is traditional to use matrices to list APL names, e.g. this is the normal result from ⎕NL 2 and also valid argument to ⎕EX, ⎕CY, ⎕NS etc.
@dzaima The utility of your first proposal can be achieved very cheaply in my using ns⎕NS↓⍉↑keys values or ns⎕NS(↑keys)values. I really don't like the lack of structure in your second one. Your third one would be a possible consistent extension, but doing ns⎕NS↓⍉matrix isn't bad either.
My bet is that null chars weren't invented (or that space was the null char) when this became practice. It gives interesting issues in sorting APL charmats too.
@dzaima (the backwards-compatibility problem remains an unsolvable issue though. i'd prefer adding a separate better quad than a worse, more overloaded one, but meh)
@dzaima Yes, that is a possibility, but I though that since we already have one to copy name-values from one namespace to another, why not just use that to set name-values from one namespace to another too?
Especially since the existing one is called simply "NameSpace", not "NameSpaceCopy".
Also, ⎕NS (re- or co-interpreted as "Name(space) Set") is such a great parallel to ⎕WS which does the same for OO objects. And then since ⎕WG is the value getter, it becomes natural to add ⎕NG for "Name Get" or "Name(space) Get".
@rak1507 ah, i was waiting to see this :) it was relatively easy in k because of its well-designed dicts, but i ran out of patience trying to solve it in apl
@rak1507 Ah, so all the Dyalog-specific features of the transformation pattern? I'm not sure how they'd fit into the format. They are well-documented in the ⎕R documentation, though that page could do with a TOC.
@rak1507 I don't have a working APL solution for this yet -- I did this in python first today. Will give it a go now, although having peeked at yours it feels a bit cheaty.
One thing I wished Dyalog's ⎕S would do is to just return any (capture)(groups) as a vector, like python does for re.findall(r'(\d+)(\w+)', string). I find myself having to do:
@xpqz @rak1507 Yes, this should obviously be 1↓⍵.Matches. The problem is the overhead of constructing that every time. I do have a solution that I've proposed to Richard Smith (who handles ⎕R/⎕S) that avoids the overhead until needed, but nobody seems to have complained about this. If you (two) do, then maybe he'll take me up on it.
@Snapdragon-X I have a keyboard layout installed, but that in-browser language bar I linked to will make it easy to type them too.
Now take TMN's ∏ and ∑ notations. They are simply reductions using × and + respectively. APL generalises these into / which allows you to "insert" any two-argument ("dyadic") function between elements of a list ("vector"):
No, these are Unicode symbols. Just go here and drag the "APL" link to your bookmarks bar. Then come back to this page and click the bookmark (it won't navigate away).
@Snapdragon-X Feel free to post ideas and findings here. Maybe others will be inspired or have constructive feedback. You may want to check out the APL Wiki learning resources.
@Adám Thanks. Mike Powell papers are more than great ! He is preparing a CNN paper too.
@Adám Šinkarovs, A., Bernecky, R., & Scholz, S-B. (2019). Convolutional neural networks in APL. In J. Gibbons (Ed.), Proceedings of the 6th ACM SIGPLAN International Workshop on Libraries, Languages and Compilers for Array Programming (pp. 69-79). Association for Computing Machinery. doi.org/10.1145/3315454.3329960
Some positive integers can be shown to have a property called Chain divisibility. For a number to be chain-divisible by n, it must fulfil three requirements:
Each digit divides the number formed by the n digits that follow it.
For example, the number 7143 is chain-divisible by 2 because 7...
@voidhawk {0⋄1} returning 0; ⍺← not respecting the semantics of ←; not having a proper if (or cond), only guards; :: captures the scope at its own location and ignores later variable bindings, etc
@voidhawk … ⊢{a←1 ⋄ }0 giving a value error; can't trace into a one-liner dfn; →0 in the session quits instead of resuming execution; plus←+ ⋄ a plus← and plus←+ ⋄ 1 plus a←2 overwriting plus; :: failing to catch ⎕SIGNAL etc.
Ill have to keep variables in the process dictionary along with a unique reference to it. do I also have to keep environments anywhere besides the current stack? (do i need to refer to environments when theyre not being executed?)
figured out how to simulate mutable, pass by reference in erlang
this is my current schema
-record(h,{h}). % env heap
-record(e,{t,f,p}). % env. tag-frame-parent
-record(x,{x}). % variable heap
-record(y,{t,i,v}). % variable, tag, indices (list of integer pairs [a,i] that index into environment), value
where 'h' and 'x' are stored in the process dictionary
i could be naming them wrong. in this schema 'f' will be a list of variable references.
that will point to a unique variable reference in the process
the process i was going to keep which indices its been inserted at in the environment, so I dont need to map over every variable in every environment (altho that might not be that expensive)
the reasoning is when I update a variable, I need to create a new variable, give it a unique reference, then go thru every reference in every environment that points to the old reference and update it
<zakkor12> I'm having a hard time trying to figure out the proper way to iterate through each "box" in this matrix. I can only get the first row or last row, but not each element in it: i.postimg.cc/bv0WTDV6/image.png
zakkor12: If you mean you want to reduce over all the elements ("iterate" is a little ambiguous), you should turn it into a vector first with Ravel (,).
@cannadayr The way I'd describe it, the runtime doesn't really have a concept of a "variable". There's an instruction to get the value from a certain slot, and an instruction to store the value, and one to make a reference to a slot to store something there later.
what i was thinking was to use the slots to store either undefined (when the env is initialized) or a variable reference. the variables would be stored separately (either in the same environment or at the top-level of the process dictionary)
it might be possible to store a tuple of {reference, value} in each slot instead
might duplicate a little but likely wont be that bad
the reason i need a reference and some entity to connect it to is to enable pass-by-reference semantics
@cannadayr The same value can be referenced multiple times, but that's why you would store a value reference instead of just a value. It's the environment that should be passed by reference to allow it to be mutated.
@cannadayr Values are immutable, so I don't think that's necessary. Of course a block function or modifier will have a reference to its environment, but that reference never changes.
Hey folks, I am very new to APL, and still have tons of tutorials etc. open. I've managed to do Advent of Code 2015-01 in Dyalog, but have TODO notes on what I feel is probably possible but am missing the operators / idioms for. Help for any of these would be greatly appreciated!
y2015d01p1←{+/('('=⍵)-(')'=⍵)} ⍝ TODO: somehow use '()' and - instead of two separate strings?
y2015d01p2←{(+\('('=⍵)-(')'=⍵))⍳¯1} ⍝ TODO: can I flip the ⍳ so that I don't need to parenthetize and the ¯1 can go to the left?
(These are working correctly, I'm just wondering about more idiomatic way to write them)
@cannadayr If I'm understanding the way you're using references here, you can just store the value in the environment directly (and the implementation will use pointers if the same value gets stored in multiple places).
im not sure that will translate to erlang. it doesn't have pointers, and you can't update a variable after definition (except in the process dictionary).
so if i declare a variable a ← 1‿2‿3
then update it later a ↩ 4‿5‿6
i have to do either:
1. create a new value 4‿5‿6 with a new reference. and update all references pointing to 1‿2‿3 to this new reference or 2. update the value at the reference to 1‿2‿3, in which case it is no longer immutable
its very prolog-y
references dont have any data associated w/ them, theyre kindve a unique value that you can compare for equality.
@cannadayr The variable is a slot in the environment, so you should change it by modifying the environment, not anything else. The actual value 4‿5‿6 is completely distinct from 1‿2‿3 in BQN as in Erlang.
You don't want to change all references to 1‿2‿3, just the specific reference a.
@dzaima a∘.='()' is implemented as ⍉'()'∘.=a as of 18.0.
From my Outer Product talk commentary, "while version 17.1 uses the same strategy for comparison as the other operations, 18.0 swaps sides and reverses the comparison to compute a transposed result."
@cannadayr LOCM should store a reference to the environment, and the slot number. That's the way I do it in JS. It avoids having to put any extra structure into the environment.
[a,i] = id would become {r,i} where r is the reference. 'set' will change a variable in the slot 'get' will return the environment tag and slot index. 'ge' will return {r,i}