Arc Forumnew | comments | leaders | submitlogin
2 points by rocketnia 4330 days ago | link | parent

Your 'if example might not be contrived enough. :) Here's a way to do what you're doing in pg-Arc:

  (mac format (open close char s i flag)
    `(when (and (is (,s ,i) ,char)
                (or ,flag
                    (atend ,i ,s)
                    (and (~whitec (,s (+ ,i 1)))
                         (pos ,char ,s (+ ,i 1)))))
       (pr (if ,flag ,close ,open))
       (zap no ,flag)
       t))
  
  (if
    ... ; lots of complicated cases
    (format "<i>" "</i>" #;between #\* #;at s i ital)  nil
    (format "<b>" "</b>" #;between #\+ #;at s i bold)  nil
    ... ; lots more complicated cases
    )
A contrived 'obj example might be better....

  (if debug*
    (mac capture-debug-info ()
      '( debug        't
         dynamic-env  env
         line-num     line-num))
    (mac capture-debug-info ()
      '( debug        nil)))
  
  (obj @(capture-debug-info)
       type 'literal-expression
       val 36)
Here's one pg-Arc alternative, which is somewhat more verbose:

  (def obj+ args
    (w/table result
      (each arg args
        (each (k v) arg
          (= result.k v)))))
  
  (if debug*
    (mac capture-debug-info ()
      '(obj debug        't
            dynamic-env  env
            line-num     line-num))
    (mac capture-debug-info ()
      '(obj debug        nil)))
  
  (obj+ (capture-debug-info)
        (obj type 'literal-expression
             val 36))
Here's another, which is somewhat less flexible:

  (if debug*
    (mac capture-debug-info body
      `(obj debug        't
            dynamic-env  env
            line-num     line-num
            ,@body))
    (mac capture-debug-info body
      `(obj debug        nil
            ,@body)))
  
  (capture-debug-info
    type 'literal-expression
    val 36)


1 point by akkartik 4330 days ago | link

Thanks for the new example! The if.. nil idea is cool; I wouldn't have thought of doing stuff in the conditions in a million years :)

-----