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 % ( |
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 |
|||
multiplier =: 2 : 'm * n * ]'</lang> |
|||
Example use: |
Example use: |
||
<lang> |
<lang> fwd multiplier rev 0.5 |
||
⚫ | |||
1 1 1 |
|||
(A multiplier 1) 2 |
|||
4 8 12 |
|||
(3 multiplier B) 4 |
|||
⚫ | |||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |