From 2a845008dab149d97edf734e97275ba9327f245f Mon Sep 17 00:00:00 2001 From: anemofilia Date: Sat, 26 Aug 2023 16:47:22 -0300 Subject: [PATCH] fix: correct combinators for supporting more use-cases and be more readable --- files/lf/.lfrc.swp | Bin 16384 -> 0 bytes modules/radix/combinators.scm | 44 ++++++++++++++++------------------ 2 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 files/lf/.lfrc.swp diff --git a/files/lf/.lfrc.swp b/files/lf/.lfrc.swp deleted file mode 100644 index c59a563656d7238b3cdf64ddcf20828e7c3142a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3U5q4E6~~LOT~R;+KKPm3?dhG_9=E$^b`uw8VIaV4ShAbNWq~M5u)6A2ckNVH z)z(K(&+IHd;Dg4*#1|t8CMLc}LhxH-0xx9Ih(e+*WpdDkn-`%%Q;omXGp zR+ox_ih+uOih+uOih+uOih+uOih+uOih+uOih=(@25i@|u0^kBB;e=$|0w?d$A>NJ zP4E(U4x9tu2FJja;3wD77JLHS0NzH(Ti_XxfEn=8HJ0@>_&#_Fq@V+Aa1Xc@EP!jl zUp{16FM}7rZ^19Xli*R{f<v52S0QjH>9sq670v`ugf-AtASED~T2c85T z(BKZR6YK!L`G94uf>YoN;O(8v1-t=X2G4^Zf^UIG!3OvoxDK4#!97?3uU}<4WcRUI%{w=fID_H^C4*2#$lBzz*hR#i?+LjijxnGaD{3!hNVxxin+s^93QO2shGa16n ze~OBUQg$2%zGKTQ+Og|36o0bSscBQE7MnVBYxTvNit;SZvrC?;-?zJ32<4YG1D()u zw8pAgu%+PfvkUWMDjSVSo2h-^*r}$eaH5*czTel)Y(3VKwyN1V(olYA*3^pAuRlm(6LWLx{VsA;@cvuGMC-C`S3 zVj0Uxb+%>)L2So5QM;YkY;N_)_-A@j*^0xiJQF-Ch_jw9*W} zzo~{8H1thIG&Y=yNVldK@V+>RZ1+67S6QSGqU_LB>vp)R{A?~&v7PlyQQ(KGg>F*W z?BD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b^W~Z-m-~YdcN!GaF=P#>eZ)GS~b#aM6=|omJ*Y2DRY#371y{fQ_^}7>U6Hh#S4=?fQgt^XPM%Hy88tNY zY$=>kCc7zm5(yVe>$;|GQuHu?LsU6VmT;6$DU%ebXecqdNx?|s=(Jioo%@;D-C8Y4 z?ypGanT@ht;&7a^<5gmr0G0fqv9%&KNa?slBGsm6#Fu+TNy2&b(uK{~OgvRzG~Mw% z%Gr?H7GGQ4jZp>Z=VoHE1!c=(pz>yF49uMPHigNlLB{EH{E(V&9oT570~>0Hys5V_ z^R2{A8iej#F09+|W2xhEelJmUxUo6k%7)0584T~{UFCVQi|I(K?x@wq_N_Wb7D784 u`=otw&rK=()O5EZKPZmg@Ha&SIYr5qY~|sCH(WdggcEr&WxmLbVe8)q;+V() diff --git a/modules/radix/combinators.scm b/modules/radix/combinators.scm index d903e48..4332d17 100644 --- a/modules/radix/combinators.scm +++ b/modules/radix/combinators.scm @@ -1,41 +1,39 @@ (define-module (radix combinators) #:use-module (srfi srfi-26) + #:use-module (ice-9 curried-definitions) #:use-module (ice-9 match) - #:export (all? - any? + #:export (all-of + any-of conjoin disjoin inclusive-disjoin)) -(define (all? pred lst) +(define ((all-of pred) lst) (null? (filter (negate pred) lst))) -(define (any? pred lst) +(define ((any-of pred) lst) (cond ((null? lst) #f) ((pred (car lst)) #t) (else (any? pred (cdr lst))))) #| (conjoin (list (conjoin '()) predicates)) = (conjoin predicates) |# -(define (conjoin . predicates) - (lambda args - (if (null? predicates) #t - (match-let loop (((head-pred . tail-preds) predicates)) - (cond ((null? tail-preds) (apply head-pred args)) - ((apply head-pred args) (loop tail-preds)) - (else #f)))))) +(define ((conjoin . predicates) . args) + (if (null? predicates) #t + (match-let loop (((head-pred . tail-preds) predicates)) + (cond ((null? tail-preds) (apply head-pred args)) + ((apply head-pred args) (loop tail-preds)) + (else #f))))) #| (disjoin (list (disjoin '()) predicates)) = (disjoin predicates) |# -(define (disjoin . predicates) - (lambda args - (if (null? predicates) #f - (null? (cdr (filter (cut apply <> args) - predicates)))))) +(define ((disjoin . predicates) . args) + (if (null? predicates) #f + (= 1 (length (filter (cut apply <> args) + predicates))))) -(define (inclusive-disjoin . predicates) - (lambda args - (if (null? predicates) #f - (match-let loop (((head-pred . tail-preds) predicates)) - (cond ((null? tail-preds) (apply head-pred args)) - ((not (apply head-pred args)) (loop tail-preds)) - (else #f)))))) +(define ((inclusive-disjoin . predicates) . args) + (if (null? predicates) #f + (match-let loop (((head-pred . tail-preds) predicates)) + (cond ((null? tail-preds) (apply head-pred args)) + ((not (apply head-pred args)) (loop tail-preds)) + (else #f)))))