~bouncepaw/agidel-stdlib

872e24ff9f70ac699d7c36d5296d56a095dd4691 — Timur Ismagilov 5 years ago 7ba501a
Fix comparison-operator in Agidel/C
1 files changed, 13 insertions(+), 11 deletions(-)

M c.scm
M c.scm => c.scm +13 -11
@@ 201,18 201,20 @@
                           (-list '|| (defvar name decl* ...))))))))))

 (define (comparison-operator operator)
   (define (form-one-pair pair)
     (format "(~A~A~A)" (-car pair) operator (-cdr pair)))
   (define (groups-of-two operands)
     (-let loop ((acc '())
                 (src operands))
           (-if (-eq? 2 (-length src))
                (-append acc (-list (-cons (-car src) (-cadr src))))
                (loop
                 (-append acc (-list (-cons (-car src) (-cadr src))))
                 (-cdr src)))))
   (lambda operands
     (-apply
      and
      (-map (lambda (lst)
              (format "(~A~A~A)" (-car lst) operator (-cdr lst)))
            (-let groups-of-two ((acc '())
                                 (src operands))
                  (-if (-eq? 2 (-length src))
                       (-append acc `(,(-cons (-car src) (-cadr src))))
                       (groups-of-two
                        (-append acc `(,(-cons (-car src) (-cadr src))))
                        (-cdr src))))))))
     (-if (-eq? 2 (-length operands))
          (form-one-pair (-cons (-car operands) (-cadr operands)))
          (-apply and (-map form-one-pair (groups-of-two operands))))))

 (define eq?  (comparison-operator " == "))
 (define neq? (comparison-operator " != "))