First-class functions/Use numbers analogously: Difference between revisions

Content deleted Content added
Use 'curry', compare to "First class functions"
→‎{{header|J}}: align with established pattern
Line 275: Line 275:


=={{header|J}}==
=={{header|J}}==
{{incorrect|J|Compare and contrast the resultant program with the corresponding entry in First-class functions.}}

This seems to satisfy the new problem statement:
This seems to satisfy the new problem statement:


<lang j> x =: 2.0
<lang j> x =: 2.0
xi =: 0.5
xi =: 0.5
y =: 4.0
y =: 4.0
yi =: 0.25
yi =: 0.25
z =: x + y
z =: x + y
zi =: 1.0 % ( x + y )
zi =: 1.0 % (x + y) NB. / is spelled % in J

A=: x,y,z
B=: %A


fwd =: x ,y ,z
multiplier=: conjunction def '(m*n)*]'
rev =: xi,yi,zi


BA=: A multiplier B</lang>
multiplier =: 2 : 'm * n * ]'</lang>


Example use:
Example use:


<lang> BA 1
<lang> fwd multiplier rev 0.5
0.5 0.5 0.5</lang>
1 1 1
(A multiplier 1) 2
4 8 12
(3 multiplier B) 4
6 3 2</lang>


=={{header|Mathematica}}==
=={{header|Mathematica}}==