The Array Cast – A podcast about the array programming languages
91–100 of 141 posts
Re: The Array Cast – A podcast about the array programming languages
#92 sep=:10#.^:_1] NB. Separate digits
ea=:&.> NB Perform on each
sep ea 23 7534 322 7 24756
│2 3│7 5 3 4│3 2 2│7│2 4 7 5 6│ #ea n NB. How many?
│2│4│3│1│5│ +/ea n NB. Sum
│5│19│7│7│24│ */ea n NB. Product
│6│420│12│7│1680│ /:~ ea n NB. Sort
│2 3│3 4 5 7│2 2 3│7│2 4 5 6 7│Re: The Array Cast – A podcast about the array programming languages
#93Earlier quoted context omitted.
> I have to look up range/xrange and len and memorise All you're communicating here is that you don't regularly work with Python. The claim that you have to look up len seems disingenuous; I might believe it if you didn't look like a speaker of English. > & means where And that's something any engineer would know, unlike having to look up what len means?
> The claim that you have to look up len seems disingenuous In what way? I have to look up "how do I get the indices of a list" to get range(1,len(x)) -- I think I could have also used enumerate() and a bunch of other things, but this seemed the shortest. > All you're communicating here is that you don't regularly work with Python. I hope I'm communicating more than that because I put a lot of effort into my comment.…
Re: The Array Cast – A podcast about the array programming languages
#94Earlier quoted context omitted.
I am going to tell you something fantastic, but first, I want to explain some things about this: us:{$[#i:&{(y~*K)&"*"~*x}':x;@[x;i;:[;,"_"]];x]} The first is that there's a typo in what bidirectional wrote. The above is correct. The second, is what it is. Once I have explained that, I can tell you the fantastic thing. k syntax is very simple. There's just a few forms you need to be aware of: f x which applies x to f…
TXR Lisp: 1> (defun rewrite (fun list) (build (while* list (let ((nlist [fun list])) (if (eq list nlist) (if list (add (pop list))) (set list nlist)))))) rewrite 2> (defmacro rewrite-case (sym list . cases) ^(rewrite (lambda (,sym) (match-case ,sym ,*cases)) ,list)) rewrite-case 3> (rewrite-case x '(foo bar * select * fox select * bravo) ((select * . @rest) ^(select _ . ,rest)) (@else else)) (foo bar * select _ fox s…
We can stick that data into the pattern matching syntax using the or operator:
3> (rewrite-case x '(foo bar * select * fox where * bravo)
((@(or select distinct partition from where
group having order limit) * . @rest) ^(,(car x) _ . ,rest))
(@else else))
(foo bar * select _ fox where _ bravo)
Or put it into a variable: 4> (defvarl K '(select distinct partition from where group having order limit))
K
5> (rewrite-case x '(foo bar * select * fox where * bravo)
((@(member @sym K) * . @rest) ^(,sym _ . ,rest))
(@else else))
(foo bar * select _ fox where _ bravo)
"If an object sym which is a member of K is followed by * and some remaining material, replace that by sym, underscore and that remaining material."Hash table:
6> (set K (hash-list '(select distinct partition from where group having order limit)))
#H(() (select select) (where where) (limit limit) (order order)
(having having) (distinct distinct) (partition partition) (group group)
(from from))
7> (rewrite-case x '(foo bar * select * fox where * bravo)
((@[K @sym] * . @rest) ^(,sym _ . ,rest))
(@else else))
(foo bar * select _ fox where _ bravo)
This code golfs moderately well: https://news.ycombinator.com/item?id=27227276Re: The Array Cast – A podcast about the array programming languages
#95Earlier quoted context omitted.
If this were me, and I needed a function like us, I would have written this: us:{$[x~(z;y);,"_";y]}[(*K;,"*")]': I would be interested in seeing anything that was shorter[1] and faster than that in any language , and I would be very curious to learn from anyone who could also do that faster than me. But I'm not a fetishist: I didn't learn k because it was cute, and I don't wake up every day looking for ways to rewrit…
> I would be interested in seeing anything that was shorter One way to do that would be to pose that as a problem on the Code Golf Stackexchange. My rewrite-case solution condenses (by removal of all non-essential spaces) to 69 bytes if the symbols are in a hash table K, and the input list is in a variable y, rather than a big literal: (rewrite-case x y((@[K @sym]* . @rest)^(,sym _ . ,rest))(@else else)) A one-letter…
Re: The Array Cast – A podcast about the array programming languages
#96Earlier quoted context omitted.
> I would be interested in seeing anything that was shorter One way to do that would be to pose that as a problem on the Code Golf Stackexchange. My rewrite-case solution condenses (by removal of all non-essential spaces) to 69 bytes if the symbols are in a hash table K, and the input list is in a variable y, rather than a big literal: (rewrite-case x y((@[K @sym]* . @rest)^(,sym _ . ,rest))(@else else)) A one-letter…
you'll never get J/K brevity though. Because in opposition to Lisp where control flow is explicit in the syntax, most of the control flow in array languages is implicit. I love lisp too, but for some (rare) use cases it's not the best.
You can get implicit control flow via macros.
Furthermore, all control flow is implicit is some way.
Take basic old progn: (progn (foo) (bar)) evaluates (foo) and then control implicitly passes to (bar) because that's the next thing.
The only control flow which is not implicit is that of a state machine described by a table or graph, indicating the next state for every input and current state.
(How can you say you can't get implicit control flow in Lisp, when I'm using pattern matching to express if you see this prefix, replace it with that?)
Speaking of macros, you could always resort to a macro like this:
(j"... line noise in character string ...")
The j macro expands the string to code at compile time. The code could be a bona fide J implementation, or something like it. That's still not down to J, because of the (j"") wrapping chewing up five characters. In a Lisp with a programmable read table, that could be reduced to two character framing or something.Re: The Array Cast – A podcast about the array programming languages
#97Earlier quoted context omitted.
Let's do this using the same approach, "find indices and assign over them in a copy of the sequence": This is the TXR Lisp interactive listener of TXR 259. Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet. Do not operate heavy equipment or motor vehicles while using TXR. 1> (defun subst-select-* (list) (let ((indices (where (op starts-with '(select *)) (cons nil (conses list))))) (if indices (let (…
If this were me, and I needed a function like us, I would have written this: us:{$[x~(z;y);,"_";y]}[(*K;,"*")]': I would be interested in seeing anything that was shorter[1] and faster than that in any language , and I would be very curious to learn from anyone who could also do that faster than me. But I'm not a fetishist: I didn't learn k because it was cute, and I don't wake up every day looking for ways to rewrit…
us←{('_'@(1+⍸2{(⍺≡⊃K)∧⍵≡'*'}/⍵))⍵}
is one(1) character shorter.
Re: The Array Cast – A podcast about the array programming languages
#98Earlier quoted context omitted.
I've lost count of the number of times I've heard some theoretical mathematician say that about impenetrable gibberish.
" Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something. " Dismissing what you don't understand because it is unfamiliar is the essence of a shallow dismissal, no? And you did it twice in this thread. The first was a blessing in disguise because of geocar's excellent reply, but now you're just repeating it, with added name-calling. Please don't do that h…
Syntax can be good or bad. I don't believe that it's just a matter of "getting used to it", there are objective metrics of readability, developer error rates, and speed of training that some languages do poorly at.
My point was that most array languages look like line noise. That's flippant, but true.
Ask yourself this question: Is it possible to develop an array-based language and use more "normal" syntax?
Of course it is! That was a rhetorical question.
Similarly, there are other branches of science or mathematics that through an accident of history have developed impenetrable syntax.
This is not dismissing something I don't understand. I understand several such branches of mathematics and still think the syntax is unnecessarily obtuse. Coughcategory theorycough.
PS: Geocar wrote about two pages to explain what is a trivial piece of code, and I still have no idea what it even does or how! I can write code in 10 languages and read about 20-30 without too much difficulty. This includes obscure languages like Mathematica, Haskell, and several flavours of assembly language.
Array based languages are the first time I've seen a high-level language that is less readable than the machine code that they are supposed to be abstracting away! It's also the second time that I've failed to understand a simple piece of code even with a detailed explanation. For reference, the only other case is quantum algorithms.
Okay, I tell a lie. Thinking back on it, I've also seen Perl scripts that are unreadable line noise, but that's about it...
Re: The Array Cast – A podcast about the array programming languages
#99Earlier quoted context omitted.
If this were me, and I needed a function like us, I would have written this: us:{$[x~(z;y);,"_";y]}[(*K;,"*")]': I would be interested in seeing anything that was shorter[1] and faster than that in any language , and I would be very curious to learn from anyone who could also do that faster than me. But I'm not a fetishist: I didn't learn k because it was cute, and I don't wake up every day looking for ways to rewrit…
> I would be interested in seeing anything that was shorter One way to do that would be to pose that as a problem on the Code Golf Stackexchange. My rewrite-case solution condenses (by removal of all non-essential spaces) to 69 bytes if the symbols are in a hash table K, and the input list is in a variable y, rather than a big literal: (rewrite-case x y((@[K @sym]* . @rest)^(,sym _ . ,rest))(@else else)) A one-letter…
1> [window-map 1()(do if(and[K @1](eq'* @2))'_ @2)y]
(foo bar * select _ fox where _ bravo)
2> (mapcar(do if(and[K @1](eq'* @2))'_ @2)(cons()y)y)
(foo bar * select _ fox where _ bravo)
3> (mapcar(lambda(:match)((@[K] *)'_)((@a @b)b))(cons()y)y)
(foo bar * select _ fox where _ bravo)Re: The Array Cast – A podcast about the array programming languages
#100Earlier quoted context omitted.
What the actual f? It's like someone threw up the noise that modems make during initial connection onto an electric typewriter from the 1960s, and then explained their intention using quotes from a Lovecraft novel.
I am going to tell you something fantastic, but first, I want to explain some things about this: us:{$[#i:&{(y~*K)&"*"~*x}':x;@[x;i;:[;,"_"]];x]} The first is that there's a typo in what bidirectional wrote. The above is correct. The second, is what it is. Once I have explained that, I can tell you the fantastic thing. k syntax is very simple. There's just a few forms you need to be aware of: f x which applies x to f…
let mut input = ["select", "*", "from", "potato"];
for i in 1..input.len() {
if ["select","*"] == input[i-1..=i] {
input[i] = "_";
}
}
If I could be bothered to dig up a Haskell compiler, I'm sure it's possible to do a one-liner list comprehension that is both terse and readable.If I was doing this in Rust, it's easy to create an iterator extension that does something like "map_lookback" which explains the intention without requiring comments.
I'm going to be blunt: Unreadable array languages are popular with quants because they work in a highly competitive, cut-throat industry where "write only" languages provide job security. I've come across developers purposefully obfuscating code by using only one-character identifiers and zero comments. One of them literally blackmailed their employer, demanding their salary be doubled on the grounds that there was no chance their code could be maintained by anyone else. He should have gone to jail for that, but he had his managers by the balls, got what he wanted, and bought a house with cash soon after.
Why are we applauding this?