Suggestion for implementation of infix 'map' and 'apply'
Subject: Suggestion for implementation of infix 'map' and 'apply'
From: Žiga Lenarčič
Date: Mon, 19 Jan 2009 20:01:42 +0100
Yes, Mathematica's notation is not that beautiful in this area. My
suggestion would be
./ for apply (since it takes it "whole")
.// for map (since it iterates/ slices through)
// for function evaluation on the left side
Another function with possible nice infix notation is append. Consider
[1,2,3] ./. [4,5,6] => [1,2,3,4,5,6]
or something along those lines.
Well I think something like
draw2d ./ makelist( explicit(x^i, x, -5,5) , i, 1, 3) ;
looks nice and clean. Or "(a + b)^3 // expand // ratsimp" looks like
youre sending (a + b)^3 through expand and ratsimp. It may take some
getting used to it. The important part is, that it would not break
any current functionality and that the user can choose if/when he/she
uses infix notation or the usual one.
Ziga
On 19. Jan, 2009, at 7:44 PM, Raymond Toy wrote:
>>>>>> "ziga" == ziga lenarcic <iga> writes:
>
> ziga> Hi!
> ziga> I have another suggestion regarding infix versions of map
> an apply.
> ziga> Infix notation is in many cases easier for humans to read
> than
> ziga> prefix. Consider
> ziga> plus(a,b,c) vs a + b + c.
> ziga> Maxima functions 'map' and 'apply' are very common in
> maxima code and
> ziga> infix versions would help improve readability and reduce
> the number
> ziga> of () in the code. Consider
> ziga> map( lambda([x], x+1), [1,2,3,4]) vs
> ziga> lambda([x],x+1) /@ [1,2,3,4].
>
> I agree that the later is slightly easier to read.
>
> [snip]
>
> ziga> The other day I was thinking of making lambda expressions
> shorter,
> ziga> something like this:
> ziga> (_ + 1)& -> lambda([x], x + 1) and (_1 + _2 + 1)& ->
> lambda([x,y], x
> ziga> + y + 1)
>
> [snip]
>
> ziga> benefit maxima code. For instance - to square every list
> entry and
> ziga> make it a matrix and transpose would in such notation be:
> ziga> ( 'matrix @@ (_^2)& /@ [1,2,3,4] ) // transpose vs
> ziga> transpose(apply('matrix,map(lambda([x],x^2),[1,2,3,4])))
>
> I have to say that these later examples are extremely hard for me to
> read.
>
> But maybe that's because I have not been polluted by Mathematica but I
> am polluted by Lisp.
>
> Ray