Arc Forumnew | comments | leaders | submitlogin
posmatch broken?
3 points by kens1 5883 days ago | 6 comments
Posmatch looks broken to me:

  arc> (posmatch "a" "bcd")
  Error: "string-ref: index 3 out of range [0, 2] for string: \"bcd\""
It looks like posmatch goes out of its way to subtract 2 to ensure it goes off the end of the string:

  (for i start (- (len seq) (- (len pat) 2))


3 points by kens1 5879 days ago | link

Headmatch seems broken too:

  arc> (headmatch "abcde" "abc")
  Error: "string-ref: index 3 out of range [0, 2] for string: \"abc\""
But maybe this is deliberate, because begins is a "safe" headmatch, with the arguments reversed:

  arc> (begins "abcde" "abc")
  t
  arc> (begins "abc" "abcde")
  nil
Trying to document this gives me indigestion.

-----

2 points by kens1 5878 days ago | link

A couple more broken things. trim seems to be broken with 'front:

  arc> (trim "abc" 'front)
  Error: "<: expected argument of type <real number>; given nil"
num doesn't work well with negative numbers:

  arc> (num -123456)
  "-,123,456"
I also don't get why there are both findsubseq and posmatch functions, since findsubseq seems to be a less-functional version of posmatch. findsubseq doesn't support a function as pattern, but posmatch does. On the other hand, findsubseq actually works.)

  arc> (findsubseq "an" "banana" 2)
  3
  arc> (posmatch "an" "banana" 2)
  3
  arc> (findsubseq "an" "foo")
  nil
  arc> (posmatch "an" "foo")
  Error: "string-ref: index 3 out of range [0, 2] for string: \"foo\""

-----

2 points by kens1 5871 days ago | link

Another broken thing is rem, which goes into an infinite loop if given a table:

  arc> (rem t (obj a 1))
  user break
As a consequence, keep, trues, and union all hang on a table argument.

-----

3 points by almkglor 5871 days ago | link

The problem here is 'coerce. 'rem attempts to coerce the object to a string, then coerce that string to a list, which it then passes to itself. however, coercing a table always returns a table. ^^

-----

3 points by kens2 5870 days ago | link

split also seems broken (or at least non-optimal) for a position of 0.

  arc> (split '(a b c) 0)
  ((a) (b c))
I'd expect (nil (a b c)).

-----

1 point by kostas 5881 days ago | link

  (pos #\a "bcd")

-----