Arc Forumnew | comments | leaders | submitlogin
1 point by raymyers 6122 days ago | link | parent

I like that you added gaurd syntax.

    ;; foo [a,b] | a < b = True
    (p-m:def foo (,((a b) (< a b))) t)
    (foo '(1 2))  =>  t
But is there any way to test across parameters?

    ;; foo a b | a < b = True
    (p-m:def foo (a ,(b (< a b))) t)
    (foo 1 2)  =>  Error


2 points by almkglor 6121 days ago | link

Not yet, although I'm working on it. The main problem is that currently, destructuring splits on the (car ...) and (cdr ...) of each list node in the pattern, something like this:

  ;a is the variable that contains the current list node of the function input
  ;p is the pattern
  `(and (acons ,a)
        ; this creates the test
        (let ,a (car ,a) ,(self a (car p)))
        (let ,a (cdr ,a) ,(self a (cdr p))))
Obviously, I'll need to resequence them - the cdr branch has to be physically located within the car branch, so that I can capture any variables in the created guards.

-----

2 points by almkglor 6121 days ago | link

  ,((a b) (< a b)))
LOL. I didn't even realize this was legal code. But mind you, Arc will be the one destructuring the pattern within the first element of ,(... ...), meaning it won't count the number of elements and all that. Hmm. Note sure if going recursive here is a good idea. Hmm.

-----

1 point by shader 6007 days ago | link

Um, how does that work?

-----