Unlike other concatenative languages, the order of operation is right to left, and it supports infix operators. This gives the language a very conventional array language feel, while also giving you the power and flexibility of the stack.
As far as I'm aware, there's really nothing like it. Would love if someone gave it a try!
Here's an example, the factorial function:
xs> fac:(prod 1+til);
xs> fac 4
0: 24
You can also define new infix operators: xs> add:{+.};
xs> 3 add 2
0: 5
Here's an example of generating a sequence of values, where n_t=n_{t-1}/2: xs> (x:;x%2) fixes 12
0: [12 6 3 1 0]
Note how when we reach the fixpoint of zero, the recursion stops. These kinds of implicitly recursive combinators are very powerful. Also, equality on floats is not strict, so we can also do this with floats, without having to worry about small differences in precision. This is useful when working with equation optimizers and root finding methods.for boosting popularity:
1- would be nice to use in tryit online or repl.it
2- would be nice to have a link to the implementation repo in the docs
3- have you tried winning some golfscript contests on stack overflow?
4- main improvements over K, with small code samples?
I hadn't heard of golfscript, but those would make some really great examples. I do have a couple Advent of Code 2019 solutions though.
Thanks!
off topic, is it just me? Or a thing informed by silly memes to see this letter and immediately think oh man, Rest in Peace?!
The name of this site is "nsl" for No Stinking Loops.
Here is an array programming challenge for the K programmers reading this thread.
There are two large files A and B.
File A
AAAbjhOJxxxWXrCHt
AAAsofxxxLqKbYOAwLMHG
AAACgxxxOea
AAAwfHjDtoJc
AAAiCfYnbVXWhuvtEx
AAAkzzQwvf
AAAdjLalKFapoYAcGE
AAAthGazmnfK
etc.
File B
AAAwfHjDtoJc
AAAbjhOJxxxWXrCHt
AAAiCfYnbVXWhuvtEx
AAACgxxxOea
AAAkzzQwvf
etc.
The task is:What are the lines in B that are not in A?
Something like
grep -vf B A
But without the stinking loops!EDIT: File A,B formatting
echo@> (2{ARGV) -.&([: <;._1 LF, 1!:1) (3{ARGV)
NB. 2nd arg 3rd arg
NB. g&f execute f for each, then g on both
NB. 1!:1 read file
NB. LF, prepend newline
NB. [: <;._1 split based on first char
NB. -. remove right elements from left array
NB. echo@> echo each line
exit 0
On two ~1.6MB files with ~15k lines (both the same except 3) I had lying around: $ time j9 -c ./pseudo_grep.ijs test_b test_a
…
real 0m0.064s
user 0m0.032s
sys 0m0.017s
$ time grep -vf test_b test_a
…
real 0m5.815s
user 0m5.234s
sys 0m0.576s
Note that most of the script is for loading each file into an array of lines. Most work is done by -. on the two arrays, which is exactly what you asked for, e.g. 0 1 2 3 4 -. 2 4 is 0 1 3. https://code.jsoftware.com/wiki/Vocabulary/minusdot#dyadic set(open('file_b')) - set(open('file_a'))
Slower than J by a factor of 2-3, but still 10x faster than grep: real 0m0.128s
user 0m0.078s
sys 0m0.063s
This would make a good Rosetta Code prompt.In my simple test, that resulting in grep running in 44% of the prior amount of time it required (still more than python though).
A←⊃⎕nget 'C:\test\a.txt' 1
B←⊃⎕nget 'C:\test\b.txt' 1
A~B
┌─────────────────────┬──────────────────┬────────────┐
│AAAsofxxxLqKbYOAwLMHG│AAAdjLalKFapoYAcGE│AAAthGazmnfK│
└─────────────────────┴──────────────────┴────────────┘
Read each file as a nested vector of lines. A without B, like set operations.What about someone who thinks "if" is a big source of software complexity? https://www.youtube.com/watch?v=z43bmaMwagI - talk is "If considered harmful: How to eradicate 95% of all your bugs in one simple step - Jules May".
[1] in interpreted languages, anything you can push down for the runtime to do instead of writing that same code in the interpreted language, tends to execute faster. e.g. my_string.count('c') in Python compared to a `for` loop over the characters written in Python.
For that sort of comparison I usually use
diff -y A B comm -13 A BCan someone ELI5 what this is about, why it's interesting, and why someone would want to learn or use this language?
(I'm coming from the perspective of someone who builds user-facing web & mobile applications in Ruby, Crystal, Python, JavaScript, Swift, etc.)
BTW - I'm asking not because I doubt there are good answers to any of those questions - but because I truly don't understand and wish to.
I read the opening paragraph and without spending an hour looking up the definition of each term, I'm more confused than when I started :)
Thank you in advance!
You're working in a very different space (business oriented, needs networking protocols, probably no major number crunching, your collection of languages do fine for your job etc.)
Some languages are just explorations of the language space, disjoint from your language-using space therefore irrelevant to you directly, and may be (currently) only of academic interest. I'd learn this if I had time, to understand different paradigms, and for fun. Sometimes this is useful. Sometimes not.
(via comments from 2015)
Yet it prints stuff to the terminal.
> Expecting a wide use of neural network algorithms in the near future, our objective is to get a complete software development environment for programming and testing new applications. We intend to produce a high level language for neural network specification, as a part of such an environment.
> The language we propose is characterized by a high degree of modularity, based on parameterizable data structures, with functionalities in the form of update methods attached to them. Composition rules of structures and methods enable to build, step by step, more complex structures from smaller ones previously defined. Objects are viewed as autonomous modules which are linked through plugs for communications. We particularly cared for the parallelization of methods running concurrently on different objects of the network. The syntax is largely related to those of the C and C++ languages.
https://link.springer.com/chapter/10.1007/978-3-642-76153-9_...
M omits the language also known as MUMPS, and also there was a second .Net based language informally called M#, apparently developed by Microsoft Research as part of Midori project, and called "C# for Systems Programming" in public communications from the developers.