Charles Greathouse on Thu, 28 Jan 2016 17:21:56 +0100


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

Boolean operations on closures


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