Charles Boyd on Mon, 11 Mar 2013 15:01:24 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: PARI 2.6 syntax 2: [f(x)|x<-a,b(x)]


Hello Everybody,

I wonder why not simply limit the scope of this '<-" operator to a given function (reasonably named say "map()" or "apply()").

Revisiting BIll's example from the original message:

L = [x^2|x<-[1..100],isprime(x)];

Could be expressed by:

L = map( [1 .. 100],  i<-i^2, isprime(i) );

Where the variable 'i' is implicitly set in the lexical context of this map() function.

A reasonable prototype might be:

map( List, Function, { [ Set of Conditions ], otherwise empty }, { Explicit Local Variable to Use, otherwise 'i' } )

This would solve the problem of ambiguity with '<-' operator, since it would only make sense within the scope of map() function. Maybe this would introduce other problems though, or duplicates an existing piece of Pari/GP functionality that I'm not aware of.

Would using '=>' instead of '->' create the same ambiguity?

On Fri, Mar 8, 2013 at 2:29 AM, Joerg Arndt <arndt@jjj.de> wrote:
Slightly ugly...
When ~ is a dead key, then hitting
  ~ [space]
brings up the plain tilde, no problem here.

PERL programmers might suggest =~  (or was it ~= ?).

I think this would be confusing both for Pari/GP users and doubly so for those who are Perl programmers, since the '=~' operator is used to to match/bind variables to a regular _expression_.

For example:

my $animal = "black cat";
if ( $animal =~ qr/cat/ ) { print "animal is a cat","\n"; }

my $reminder = "time to feed the dog";
$reminder =~ s/dog/cat/;
print "$reminder","\n"; # prints "time to feed the cat"

As a Perl programmer, I wouldn't recommend using this operator for anything. ;)

Best,
Charles

--
2048D/E67424BF (GnuPG)