3 ms·
Most programmers have worked in a largely loopless programming language: SQL. IT lets you easily build the same sort of ‘Boolean state for every item’ as this d
by jameshart 7y ago
Most programmers have worked in a largely loopless programming language: SQL. IT lets you easily build the same sort of ‘Boolean state for every item’ as this discusses, but it requires you to be much more explicit about which items you want to line up next to one another if you’re joining two lists together.
In modern languages we usually just use mapreduce like functional approaches to handle the same sort of thing, so I’m not sure this approach is as unusual as the author seems to think.
- 3xblah 7y agoIs there a difference between loopless and "largely loopless". https://docs.oracle.com/cd/B28359_01/appdev.111/b28370/loop_statement.htm https://docs.oracle.com/cd/B28359_01/appdev.111/b28370/loop_... The wiki author, who also wrote J for C Programmers, never uses the word "unusual". He uses the words "different" and "better". Is it only the parent comment that invokes the word "unusual". The comment also implies J is not a "modern language", whatever that means..
- misterdoubt 7y agoPL/SQL is not SQL.
- kqr 7y agoDo recursive CTEs count as SQL, then? Despite the name, they are practically loops.
- kragen 7y agoI wrote this query for Dercuano the other day; it computes the Collatz sequence starting from each of the first 100 integers, running a second Collatz computation twice as fast in parallel to detect any cycles (and of course there are none): with recursive collatz as (select 1 as x, 1 as n, 1 as m, 0 as p, 0=1 as exit union select case when nextx then x + 1 else x end as x, case when nextx then x + 1 else (case n % 2 when 1 then 3*n + 1 else n / 2 end) end as n, case when nextx then x + 1 else (case newm % 2 when 1 then 3*newm + 1 else newm / 2 end) end as m, case when nextx then 0 else p+1 end as p, case when nextx then 0 = 1 else n = newm end as exit from (select (m = 1 or newm = 1) as nextx, x, n, m, p, newm from (select x, n, m, p, case m % 2 when 1 then 3*m + 1 else m / 2 end as newm from collatz where not exit) a) b where x < 100) select * from collatz; It works in Postgres 9.5.14; I'm interested to hear if it works or doesn't in other SQL implementations. I think this definitely qualifies as a loop.
- 7thaccount 7y agoFrom someone who has experience in mostly SQL, Python, Linux commands, and a smattering of other languages that I've played with (Haskell, Common Lisp, F#, Ada, Prolog, Julia, Forth, Fortran...etc) I can say that J and modern APL systems are completely different in a lot of ways. Yes functional languages have a lot built around map/fold/filter that is very similar to J's tacit programming, but the implementation makes all the difference. With J you just have math basically (assuming you don't use the non idiomatic if-then constructs). I'm not saying J is better than Haskell at all, but keep in mind that when they say "loopless" it's possible that what they're trying to convey is that there are no imperative loops AND the combination of dynamic typing and tacit trains means you have something terse with zero boiler plate.
- jandrese 7y agoIt seems to me like it is terse because this is a DSL for dealing with vectors and arrays of numbers. Sure the equivalent C for loops are a lot more wordy for the problems that this language solves, but you'll drive yourself crazy trying to write a simple event loop for your GUI in J.
- tluyben2 7y agoYou do everything differently in j/k/apl, so the notion of eventloop is not what you want to do there (under the hood that happens ofcourse). People would not typically write GUIs in these languages but you can [0]. They are actual languages, not DSLs. [0] https://www.jsoftware.com/help/primer/gui.htm https://www.jsoftware.com/help/primer/gui.htm
- 7thaccount 7y agoYou're not too far off in my opinion. Yes, you can write beautiful code dealing with arrays, scalars, and matrices, but as you pointed out...it breaks down for other tasks. Opening files in J uses numeric handles that if I recall look something like this (5:!1) which is a little weird, but perhaps not hard once you learn it. It should be noted that Dyalog APL has easier to use primitives for CSV, JSON, SQl, and XML. It also has full interop with .NET on Windows including GUI. J also has GUI capabilities that people use, but it did not appear straightforward.
- bouncycastle 7y agoI believe it's called Declarative Programming. Prolog comes to mind as well. https://en.wikipedia.org/wiki/Declarative_programming https://en.wikipedia.org/wiki/Declarative_programming