| Yet another reason why strings should be a special case of lists in Arc and in any programming language (ignoring how they are implemented) is that the empty string would naturally and logically map to the empty list, and vice versa. So, (string '()) ; --> ""
(is '() "") ; --> t
(is nil "") ; --> t
I can't run Arc at work, so I can't test if this is the case already. If not, it should be. Also, last time I tried it was not possible to take the car or cdr of a string, but it was possible to use scar and scdr. This is illogical.If we had non-deterministic choose and fail as defined in On Lisp, we would have a very nice partial implementation of regular expressions: (def m (str pat)
(rfn match (str pat result)
(if (no str) result
(no cdr.str) (if (and (matches str pat) (no cdr.pat) result (fail))
(choose
(if (matches car.str pat) (match car.str advance.pat (cons car.str result)) (fail))
(match cdr.str pat '()))
(fail))
(reverse (match str pat '())))
(def advance (pat)
; advance the pattern in some way (taking into account
; repetition etc.)
)
(def matches (elt pat)
; test if the element matches the beginning of the pattern
; (for example, elt == "a" and pat == ".?" --> t
)
(m "hi there" '(h .?)) ; succeeds (twice even)
The above is probably inefficient and more importantly incorrect, but there's no reason why it couldn't be applied to any list next, given that we have a way to define the pattern to search for: (m '(a b c) '(.? b c)) ; succeeds
(m '(a b c) '(a .*)) ; succeeds
(m '(a (b c) d) '(a .*)) ; succeeds
(m '(a (b c) d) '(a b)) ; fails
(m '(a (b c) d) '(a (b .*)) ; succeeds
(End of random thought of the day.) |