Arc Forumnew | comments | leaders | submitlogin
1 point by jazzdev 5155 days ago | link | parent

Thanks, that's a great explanation. Makes sense.

The Jarc 'match' actually takes advantage of this lack of hygiene to implement this Perl-like idiom:

  (awhile (readLine in)
    (if (match "^\S") (prn it))
  )
Where match is defined to search 'it' if no 2nd arg is provided.

  (mac match args
    `(match-str ,(car args) ,(if (> (len args) 1) (cadr args) 'it)))
I thought about using the same pattern in the Jarc sql package to dynamically turn tracing of the SQL statements on and off. But it seemed inelegant making all the sql functions into macros just to get the dynamic tracing, so I decided to use thread-local variables instead in that case.


2 points by rocketnia 5155 days ago | link

If you don't mind me suggesting...

  (mac match (regex (o subject 'it))
    `(match-str ,regex ,subject))
(Note that this rejects argument lists of lengths other than 1 or 2, whereas yours doesn't.)

And yeah, that is a good use of it. ^_^ An anaphoric parameter.

-----

1 point by jazzdev 5154 days ago | link

Thanks for the improvement. Much shorter and more readable that way. And error checking as you mentioned.

-----