At the top of arc.arc: ; don't like names of conswhen and consif
I've been writing them a different way in wart: (consif a b) => (maybe cons a :to b)
(conswhen f a b) => (maybe cons (check a f) :to b)
Here's maybe: def maybe(f a b/to)
if a
(f a b)
b
(Uses param aliases: http://arclanguage.org/item?id=15254)While I'm at it, I'm also unhappy with the name only. Ah, maybe can replace it in the common case of unary functions (17 out of 20 uses in arc 3.1). (only f a) => (maybe f a)
This works because wart is flexible about how many arguments a function can take. Extra args are silently dropped, and missing args are nil by default. maybe exploits both scenarios.And for non-unary functions? I'd replace: (only f a b c)
with (and a (f a b c))
Especially since it's already a common pattern in the arc codebase. (See app.arc)--- consif makes a call to cons if its first arg is not nil. conswhen generalizes the nil check to be parameterizable. I want to make this generalization elsewhere as well. iflet binds and executes body if the binding is not nil, but I sometimes am stuck generalizing it: (let x (...)
(when (f x)
..))
I'm not sure what to do about this case for now. Maybe something like: (let var val :provided check . body)
But that seems like a control abstraction (http://arclanguage.org/item?id=13664). |