Tacit programming: Difference between revisions

Content deleted Content added
m Python: <code>
m jq: <code>: fix syntaxhighlight error
Line 132:
====jq====
 
[[jq (programming language)|jq]] is a [[JSON]]-oriented programming language in which the {{Code<code>||}}</code> symbol is used to connect filters to form a pipeline in a familiar way. For example:
 
[1,2] | add
Line 138:
evaluates to 3. (Yes, the JSON array is a jq filter that evaluates to an array.)
 
Although similar to Unix pipelines, jq pipelines allow the incoming data to be sent to more than one recipient on the RHS of the '<code>|'</code> as though in parallel. For example, the program `<code>add/length`</code> will compute the average of the numbers in an array, so that:
 
[1,2] | add/length
Line 150:
evaluates to [2,3,1.5]
 
A dot ('<code>.'</code>) can be used to define an attachment point on the RHS, e.g.:
 
1 | [., .]
Line 160:
2 | pow(.; .)
 
evaluates to 4 since <code>pow(x;y)</code> is x to the power y.
 
=====Fibonacci sequence=====
Line 168:
[0,1] | recurse( [last, add] ) | first
 
Here, <code>[0,1]</code> is the initial pair to be taken as the first two items
in the Fibonacci sequence. (The pair <code>[1,1]</code> could likewise be used for
the variant definition.)
 
The alphabetic tokens are built-in filters: `first` and `last`
emit the first and last elements of their input arrays respectively;
and `<code>recurse(f)`</code> applies a filter, f, to its input recursively.
 
jq also allows new filters to be defined in a tacit style, e.g.: