Looking for a short way to trim zeros from both sides of a boolean list in J. So far the best I've got is to hack binary conversion by defining g=.]&.#. and then doing g&.|.@g: Try it online!. Any better ideas?
@Sherlock9 I'd probably want to put some comments. On the first line, what it does and how to call it. Then on the Extend←{ line what that does, and on its lines why those steps, and then maybe a comment on the ⊃,/ line about the method.
@Adám Ah comments. I'd nearly forgotten them all XD
I realize there's only so much you can do with functions which grow exponentially, but do you see any parts where the speed of the function could be improved?
I seem to remember a conversation here about ¨ not being very optimizable (something about branch prediction IIRC?), but I'm not sure there's anything that can be done there
@Sherlock9 Just like ¨, but runs each call in true hardware parallel, hence it is read as parallel each. Unfortunately, we've been way slow in making the glyph work, but meanwhile, you can )copy isolate and then use IÏ instead of ∥¨
The following employee matrix of names and email addresses makes it visually clear that bob's email address is bob@example.com.
┌───────┬─────────────────────┐
│alice │alice@example.com │
├───────┼─────────────────────┤
│bob │bob@example.com │
├───────┼─────────────────────┤
│charli...
I have pasted them both into chat. I believe their main base of programming knowledge is Python, however
> Not mistakenly, as far as i know but we did find out by trying to break stuff (we were ordered to play around with the code, so we did) that you can redefine predefined functions
> Me: Also from APLer friend > What would you rather a²+b²+2(a+b) or plus(square(a),plus(square(b),times(2,plus(a,b))) ? In short, the symbols are nice and easy to get used to The array-based part of array-based programming on the other hand that's a little tough
Them: but see, there are perfectly fine conventions for this, using ascii: a^2+b^2+2(a+b)
> Them: yeah, that would require a bunch of for loops i guess but well, that is the tradeoff for other people also understanding my code Me: Again, it's not that hard to get used to the symbols
Presented in honor of APL as an interactive tool turning 50 this year
Background
Ken [Iverson] presented his paper Formalism in Programming Languages in August 1963 at a Working Conference on Mechanical Language Structures, Princeton, N.J. The list of conferees is full of famous and soon-to-...
@Sherlock9 Given a string A, e.g. mississippi and a string B, e.g. ps, give me the indices into A where there is a letter which occurs in B, i.e. [2,3,5,6,8,9]
> Me: It works for any array-based thing (which is darn near everything)
Them: > which is darn near everything Last week I built something that required doubly linked lists and random pointers it was a weird algorithms for graph stuff where we had a number of given assumptions
@Sherlock9 APL has no issue with (infinitely) linked lists, and pointers. Various manipulations of such trees are themselves short one-liners. Search YouTube for "hsu apl graphs"
@Sherlock9 Any of his presentations really. This is his expertise.
@Sherlock9 Speaking of which, given an adjacency matrix M, give me the transitive closure. E.g. [[1,0,0,1,0],[1,1,0,0,1],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,1,0]] → [[1,0,0,1,0],[1,1,0,1,1],[1,1,0,1,1],[0,0,0,0,0],[0,0,0,1,0]]
> Me: *repeats your words about APL, linked lists, pointers, and trees Them: well, then i think you can do anything. Is it proved to be turingcomplete?
XD I hope so
Or I could try to implement a Brainfuck interpreter in APL
@Sherlock9 Heheh, it is A Programming Language :-D A .NET language (if you want), multi-paradigm (functional/imperative, array-oriented/OO, explicit/point-free,…) cross-platform…
Me: Well I can pretty easily write a Brainfuck interpreter in APL, I think, which is itself Turing complete, so yep! This is used in production, which is why I'm willing to go to bat for it
Them: well, then it is just preference
Me: If it were just one of the many esoteric languages I knew, then I'd have called it a day a little earlier :joy:
@Sherlock9 More linked list fun: Sort the numbers in the list L=[4,4,0,[2,[[4]],[0,2]],5,[6,1],[[5]],1] i.e. → [0,0,1,[1,[[2]],[2,4]],4,[4,5],[[5]],6]
Even if they can do it, ask them to do it in-place!
APL: (∊L)←(⍋⊃¨⊂)∊L Extended APL: (∊L)←∧∊L
@Sherlock9 Volvo Penta (makers of trucks, busses, and maritime engines) plans their production in APL. The European commission does its statistics in APL. The Swedish health care system keeps its patient journals in APL… Yeah, I think it is a programming language alright.
@Sherlock9 NP. For next time, this one is fun to show, if people think you can't do serious stuff in APL (running on a single laptop). Thank you for spreading the message!
CS people like being able to control how exactly stuff works, and APL very directly opposes that, hiding all implementation and special-case optimizing only some combinations of builtins
@ngn Just my experience (and that of others too; Aaron Hsu, for instance). Introducing APL to scientists, laymen, children,… very easy. CS people have some kind of block. The more well-versed in traditional programming languages, the harder it is for them to "get it".
@Adám "some kind of block" - or probably the unmet expectations for language mechanisms that evolved in lisp and others after apl was created. for instance, as a sort-of cs person, i find it hard to accept apl's lack of 1st class fns and the bad design of dictionaries in dyalog.
on the other hand, lack of array capabilities elsewhere keeps pushing me towards apl&family.
@dzaima is it because of something in the language itself, or due to external factors like obscurity, absence of good enough f/oss impls, integration with other languages (except C#), lack of jobs?
@ngn mainly because either i often need sets/maps or want to create one custom class that'd be pretty annoying to otherwise use in APL
e.g. currently i'm trying to implement toi efficiently in Java as per this about this and i don't think there'd be a pretty way to do it in APL
my idea would be to have a global list of all possible sets, represented as lists of pointers in that same list, but that's pretty much reimplementing pointer-based memory, just with the added factor of difficulty to use
@BrianBecker You can evaluate a single line of APL by typing it into chat prefixed by ⍞←. Use ⎕← instead for boxed display and multi-line results and use ⋄ instead to silence the first statement. Use ] to call user commands, including ]help ⍣ for help on a glyph etc. Do not use markdown, but fixed-width (4 initial spaces) is fine. Commands: )lb for language bar, )docs for full documentation, )ref for PDF reference card, )idioms for idiom list.
@ngn i don't think that's optimizable without being able to store the data in a completely different format (ignoring the fact that ≢¨ being unique is enough for ∪ to not do anything, as that's just a consequence of how the data was created)
@dzaima good old java's equals and hashCode? :) there's a trade-off between reserving room in the header for a hash code and performance in those cases when it's not needed
there's also the complexity of dealing with in-place updates that invalidate the hash code
@dzaima you don't even have refcounting, java does the memory management for you, and java is great at managing memory (at least sun/oracle's vm), but not for array oriented languages :)
oh i'm using a stored hash of 0 as indication of needing to calculate the hash, so the storing wouldn't help anyway :D (though i should make it never set hash to 0)
computing a hash would take traversing the whole content of an array though
comparing just the lengths (tallies or maybe shapes) should be much cheaper, at least in the case we were considering above where all lengths are different
on the other hand if you have vectors that, for example, are of the same length and differ only in their last element, hashes would surely help
so it's a trade-off, depends on what's expected to be the more common case in practice
@dzaima it depends. in some cases a custom .equals() might help, but "choice fatigue" is also a thing.
for many algorithms you simply can't be bothered with trivial details and you just expect the obvious .equals() from your language
java is bad in that respect, as it doesn't provide default implementations of .hashCode() and .equals() for user classes
i've seen the templated generation of those methods implemented in ide-s (both intellij and eclipse), and as someone put it long ago, "every ide feature is a deficiency of your language" :)
if you find it necessary to highlight types in a different color, maybe the language does a poor job of making it clear what's a type and what's a variable name, or maybe it doesn't need static typing at all
@dzaima ok, i give you that one about the matching bracket :)
apl syntax eliminates the need for only about 50% of bracket pairs (unless you love ⍨), compared to lisp, so there's still a need to highlight matching brackets
@ngn so yeah, i agree that javas default hashcode & equals are horrible (imo they should just not exist without implementing some interface), but offloading language things to the IDE imo can be a good idea sometimes