Pascal Molin on Thu, 28 Jan 2016 17:36:34 +0100


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

Re: Boolean operations on closures


It seems necessary that

if(f,1,0)

and

if(!f,1,0)

do not return the same, which would be the case since defined closure evaluate to true.

By the way, I do not know why #f returns 5 for any function f.


Pascal

2016-01-28 17:21 GMT+01:00 Charles Greathouse <charles.greathouse@case.edu>:
Now that functions are first-class (or at least emancipated) in GP, I've come to use commands like

select(f, [1..1000])

fairly often. Unsurprisingly some times I want to negate or combine these, which usually means making a quick anonymous closure. But I've been thinking about the PARI philosophy:

> The basic principles which govern PARI is that operations and functions should, firstly, give as exact a result as possible, and secondly, be permitted if they make any kind of sense.

and I think it would make sense to apply operators ! && || to closures. In particular they would be syntactic sugar for

!f <==> v -> !call(f, v)
f && g <==> v -> call(f, v) && call(g, v)
f || g <==> v -> call(f, v) || call(g, v)

following the usual precedence rules. Would anyone else find this useful?

Charles Greathouse
Analyst/Programmer
Case Western Reserve University