Category:J: Difference between revisions

m
→‎The J language: link to some well thought out reflection on implications
m (grammar)
m (→‎The J language: link to some well thought out reflection on implications)
 
(10 intermediate revisions by 2 users not shown)
Line 19:
== The J language ==
 
A frequent reaction when one first encounters a J program is often something along the lines of "that's cheating". The thought here is that the problem could not possibly be that simple, so -- instead -- the issue must be that J was specifically designed to tackle that problem.
 
The flip side of this issue is that J is a dialect of APL -- a language whose development started in the 1950s and which was implemented in the early 1960s. And, originally, APL was designed as a language to describe computer architecture. The implementation as a programming language was motivated by its original successes in documenting computer hardware and instructions, and the relative simplicity of its concepts.
 
See also https://github.com/cratelyn/j for some reflection on some of the linguistic character of J.
 
== Introduction ==
Line 33 ⟶ 35:
Object-module and imperative techniques are supported, but not required.
 
The J programming language was designed and developed by [http[wp://en.wikipedia.org/wiki/Kenneth_E._Iverson Ken Iverson]] and Roger Hui. It is a closely related successor to [[APL]], also by Iverson which itself was a successor to the notation Ken Iverson used to teach his classes about computers in the 1950s.
<br clear="all"/>
 
Line 49 ⟶ 51:
For example, the phrase <code>(+/ % #)</code> finds the average of a list of numbers.
 
<syntaxhighlight lang="j">
<lang J> (+/ % #) 1 2 3
2</lang>
2
</syntaxhighlight>
 
To understand how this works, you might try working with simpler sentences and their variations.
 
<syntaxhighlight lang="j">
<lang J> +/ 1 2 3
6
+/4 5 6
Line 67 ⟶ 72:
5
(+/ % #) 4 5 6
5
5</lang>
</syntaxhighlight>
 
By themselves, these experiments mean nothing, but if you know that +/ was finding the sum of a list and # was finding the length of a list and that % was dividing the two quantities (and looks almost like one of the old school division symbols) then these experiments might help confirm that you have understood things properly.
 
== Some Perspectiveperspective ==
 
If you wish to use J you will also have to learn a few grammatical rules (J's parser has [http://www.jsoftware.com/help/dictionary/dicte.htm 9 reduction rules] and "shift" and "accept" - the above examples use four of those rules). J verbs have two definitions - a single argument "monadic" definition and a two argument "dyadic" definition.
Line 82 ⟶ 88:
For example, if language did not have an internal stack, a word's definition could not be used during the execution of that word. All current J implementations support recursion, but in some sense this is a convenience, and it's reasonable to imagine J implementations which do not (perhaps in a "compile to silicon" implementation).
 
=== Types ===
Perhaps also worth noting is that when thinking about J programs, it can be convenient to think of an instance of an array as a type. This is somewhat different from the usual treatment of type (where all potential values in a context are treated as a type).
 
Perhaps also worth noting is that when thinking about J programs, it can be convenient to think of an instance of an array as a type. This is somewhatin some ways different from the usual treatment of type (where all potential values in a syntactic context are treated as a type but the types are typically far more constrained than "an array").
 
J's type hierarchy supports arrays of arbitrary size and dimension, and array contents may be numeric, character or boxed. Thus, for example, we might work with an array of boxes, each box containing a one dimensional array of characters -- or, informally: strings.
 
In addition to arrays, J's type hierarchy includes procedural types: verbs, adverbs, and conjunctions. These roughly correspond to functions (J's verbs) and metafunctions (J's adverbs and conjunctions) of other languages.
 
As a simple example: 2 is an array (with zero dimensions), 3 is an array, and < is a verb. The expression (2<3) compares 2 and 3 and returns a truth value indicating that 2 is less than 3. But the expression (<3) returns a box which contains the array 3. While the details here are a bit different, the general concepts should be familiar to users of other programming languages. (For example, in C, 2&3 performs a bitwise and between the two numbers, and &y returns a pointer to the value referred to by y.)
 
J would be considered dynamically typed because of the generality of its arrays. But its type based syntax would lead some to consider it to be statically typed (though the simplicity of its syntax might invite criticism from people who prefer more complexity).
 
== J on RosettaCode ==
 
Discussion of the goals of the J community on RC and general guidelines for presenting J solutions takes place at [[J/HouseStyle|House Style]].
 
 
== Jedi on RosettaCode ==
Line 107 ⟶ 122:
 
Want to try one of those cryptic J lines you see peppered through RC?
Try pasting it into this [httphttps://joebojsoftware.github.io/j-emscriptenplayground/bin/html/emj.html browser-based implementation of J]. Here's a short [https://youtu.be/W_f7wUILcoc video intro], for people who would prefer some guidance.
 
If you want to be a bit more interactive, and get some guidance from J gurus, you can join the actual J IRC channel on Freenode, #jsoftware. Buubot and several other J eval bots run there.
Line 119 ⟶ 134:
 
==Todo==
[[Reports:Tasks_not_implemented_in_J]]
 
See also: [[Find_unimplemented_tasks#J|the "unimplemented tasks" task page]] for a mechanism for finding rosettacode tasks and draft tasks which have not been implemented in J (or any other language, for that matter).
6,951

edits