does anyone know how to typeset APL(Dyalog) code inside Latex? e.g you can use Verbatim to enclose Python code inside Latex, I want to enclose APL code inside Latex,
I know there is Latex package called wasysym to render APL symbol inside Latex, but If I want to enclose APL code literally inside Latex. Package wasysym does not help because it is only render APL symbol. When I copy APL code to Latex and enclose with Verbatim, then APL symbol can not be display properly.
@EliasMårtenson redoing my (dzaima/BQN) pretty-printing formatting. Decided to go with using proper BQN values as the storage format, meaning I can use matrices for the results and even inline BQN code; The elements of the matrix can be characters, or a string of a grapheme cluster, meaning that in the 99.9% case I work with efficient data, and when there are grapheme clusters, it just quietly switches to being quite a bit more inefficient, but still would work properly.
@dzaima (to note is that i'm actually too lazy to actually find grapheme clusters, this is just for working around UTF-16 breaking doublestrucks for now. but adding those should "just work")
@dzaima (if i wanted to add coloring information (i.e. ANSI color escapes), i could squeeze that info into those "extended charaters" without breaking formatting too, though then the format would necessarily always be in the inefficient mode)
@dzaima I just tested, and I can actually compile for JS now. Now that I think about it, I believe at the time the KClass object wasn't even available.
Thank you. I'll need to implement some functions that needs to be made available on each platform which the Kotlin multiplatform libraries don't provide, and then I might be able to create a "try-KAP" site :-)
@ngn Trying to get everything to pass in JS. Right now the status is: 44 failed tests / 467 succeeded.
So for the most part things seems to run. Now the issue is Unicode support. I haven't done any javascript in a very long time. What is the Unicode API I'm supposed to use? I need to do things like split strings into grapheme clusters, and decode UTF-16.
@ngn Do note that the graphical interface (you can call it "IDE"), is only available on the JVM version
(and for the opposite direction, "𝕩".codePointAt(0) (though the 0 is redundant here))
@dzaima (fwiw that works with varargs - String.fromCodePoint(120168,120169) (or, equivalently, String.fromCodePoint(...[120168,120169]) but note that there's some stupid varargs size limit))
@dzaima Perhaps Kotlin uses an older version, because I can see it in my browser (as expected) but when I call it from Kotlin is says that the function is not defined.
@ngn Well, the main reason is that KAP has a function called unicode:toGraphoemes which performs this conversion. It's used by the formatter to make sure that output is aligned properly.
@dzaima It is actually available in Kotlin, but it's called Char.toChars(codepoint)
Hmm, my next problem in getting this thing to run in JS is how to deal with the standard library. The underlying function loads a file off the filesystem, but that doesn't work in the browser.
@EliasMårtenson ah. using the online playground currently because am too lazy to get a local test playground
@EliasMårtenson i don't like some things about kotlin (and can't be bothered to estimate whether the good parts are worth it), so am forced to stick with java, awaiting the day i write my own language specifically for myself
Hmm, grapheme-splitter hasn't been updated in 2 years, meaning that it'll probably have problems on any new characters in the latest versions of Unicode.
@dzaima I agree, there are some truly annoying thing about Kotlin. But the benefits outweigh for me.
@dzaima (particularly, i really don't like it switching away from primitive types. Ideally, it would make primitive types (i.e. ones without identity, pass-by-value) first-class, but that's obviously impossible if wanting to remain compatible)
@ngn The KAP standard library is written in KAP, so I just need to be able to open a file. I guess in the browser case, I'll just download it from the server URL.
I've reached a point where the only ailing test cases are the ones that require the stadnard library.
Oh no. Now this is an interesting, and frustrating, problem. The IO functions in JS are all asynchronous. But of course I want to have synchronous operations.
@EliasMårtenson my solution to that was to implement my own super-simple file system and syscalls that work with it. probably not applicable in your case because java..
I have build a simple file access API. It's needed because Kotlin multiplatform doesn't contain a standard IO API, so you have to do that yourself. So in my case, the JVM implementation calls into the Java libraries and the Native implementation calls into read/write, etc.
However, now I need to implement the JS version, which is tricky because I don't think I can read a file/URL synchronously in JS?
Another way to phrase my issue is that I somehow need to be able to implement a function with the following protoype in JS: String readContentFromSource(String filename)
@EliasMårtenson If you're going to be displaying results in the browser, could you format as HTML, with tables? You'd want a fallback to use for Node from a terminal, but that seems like a more elegant way to display things.
@ngn OK, there seems to be no simple way of embedding data in a JS project with Kotlin multiplatform at the moment. So I will take a hybrid approach: In the init code, I will do async loading of all the library files that will be needed. They will then be stored in a hashmap and served as recommended by you.
@ngn With HTML tables you probably don't have to use grapheme splitting (who would seriously use the Node version over Kotlin?), so I think I'm saving work here. Sure, the browser has to render the tables, but that's what browsers do.
@ngn here i'm not even saying "do more", i'm saying "go ahead, don't do less". And as I've said before, I don't like the mindset of doing less for the singular purpose of doing less
@rak1507 (Dyalog has more resources than dzaima, but Oracle/JVM has more resources than Dyalog). Might be speaking out of turn here, but Dyalog surely has more code paths to handle configurable ⎕IO, migration level ⎕ML, comparison tolerance, debugger hooks, parser that has to be able to cope with namespaces/classes/tradfns, and so on which will add some overhead.
@EliasMårtenson If you'd like to start with BQN's online REPL (mostly in repl.js) you're free to. I can waive the ISC (like MIT) license requirement so you don't have to bother with copying the license as well.
It's adapted/rewritten from the ngn/apl one in case you'd like to reference that.
@ngn i'll agree that "faster than C" rarely means "practically noticeably faster than any C", but just being "faster than c that most sane people would write" isn't that hard
@ngn The program {((⊢⍱≠\)'"'=⍵)/⍵} removes quoted sections from a string. I will be quite impressed if you can demonstrate a well-written C equivalent.
@Marshall any apl expression you can think of - collect the fragments of the interpreter that interpret it, put them in a c file and compile it, it should be no slower than the original
@ngn I will be quite impressed if you can furnish those parts of Dyalog's current source code, but I don't consider that explanation to be a demonstration.
@ngn If you're writing more assembly than a single specialized tight vectorized loop that you've spent quite a while thinking of the best way to do, i would assume the likelihood of c being faster to indeed be quite high.
@ngn The claim isn't that C can't be faster than APL, but that APL can be faster than C. You'd agree that I gave a simple task that any competent programmer could solve?
I just think it's weird to use "well-written" to mean something that most competent programmers couldn't produce.
@ngn No, C is better for performance in general (but programs are slower and more costly to write). Doesn't change the fact that if you have a good fit for array programming then you want APL.
yes, "apl is faster than c" is a bullshit statement. it aims to present apl in a more positive light than it deserves. it distorts the truth by failing to mention the conditions under which apl is faster.
@ngn You dropped a "sometimes" from the original source. I think "APL is sometimes faster than C" is useful and not misleading, and it's usually discussed in the context of explaining when it might be better.
@dzaima if someone knows what s/he's doing in c, there's no way you can beat their program with apl. maybe apl would take less time and fewer characters, maybe it will be easier to write, but ultimately c has more ways to map to machine code, and they are a superset of the array-oriented paradigm, for better or for worse.
And I think the "proof" that APL can't be faster than C is misleading, because it invites the reader to ignore that Dyalog is implemented in non-portable and very sophisticated C.
@ngn If by "knows what s/he's doing in c" you mean "is omniscient". That phrase usually doesn't imply knowledge of original and unpublished algorithms developed at a small British software vendor.
@ngn how about this: "for a certain class of problems, reasonably written APL (i.e. what most APL programmers who know how to write optimized code would write without a specific request for performance) can often be faster than reasonably written C (i.e. what most C programmers who know how to write optimized code would write without a specific request for performance)"
@Marshall so: i know a secret fast algorithm to solve a certain problem. i write it in (say) python. you write your solution in (say) java, without knowing my algorithm. therefore, python is faster than java.
The original is "I am interested in how APL is so efficient at what it does, to the point of sometimes being benchmarked as outperforming C." That's very objective and I'm pretty sure it's true as I've personally made such benchmarks.
@ngn I 100% believe the OP could have seen a benchmark showing exactly that (whether the C side of the benchmark contained the specific inline asm to make it faster than APL is another question), and they even qualified that with "sometimes"!
@Marshall in order to call the results "objective" you shouldn't be the one writing both the c code and the apl code. objective benchmarks should be adversarial.
afaict marshall wasn't saying the benchmarks were objective either (and any "objective" benchmark of runtime performance cannot beat C anyways as it has inline assembly)
@dzaima Because optimisations. But yeah, NaNs are bad. To quote Roger Hui:
> My feelings about NaN ("real hideositynesshood") come from years of dealing with it in J. The bad thing about it starts with the following property, namely NaN=NaN is 0 (false). Whatever benefits obtain from NaN are not worth throwing out the property that x=x is true. Throwing it out will bite in unexpected ways.
@user677578 OK, I'm on it. No need to email again. (I can see your ID only when you're here.)
I'm reading Notation as a Tool of Thought with a bit of background in J, but none in APL. To clarify, does APL use column major order, but print on one line when the array to print has only one column?
Sometimes people will use an "inverted table", which is a vector of column vectors, but there's no support for treating inverted tables as matrices.
Strictly speaking I guess there's nothing stopping an implementation from using column-major order, but it conflicts with ravel order so I've never heard of any implementation doing that.