Anyone know why I can't split with an empty string in (chicken irregex)?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Anyone know why I can't split with an empty string in (chicken irregex)?

joshua

I can't seem to figure out how to split a string into individual characters.
I could swear this worked before, in Chicken 4.
I'm now using Chicken 5.0.0 running on Void Linux.

#;1> (import (chicken irregex))
; loading /usr/lib/chicken/9/chicken.irregex.import.so ...
#;2> (irregex-split (irregex ",") "foo,bar,baz")
("foo" "bar" "baz")
#;3> (irregex-split (irregex " ") "foo bar baz")
("foo" "bar" "baz")
#;4> (irregex-split (irregex "") "foobarbaz")
() ; wat
#;5> (irregex-split (irregex "\\s*") "foobarbaz")
()

Any ideas?


Thanks,
joshua


_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users
Reply | Threaded
Open this post in threaded view
|

Re: Anyone know why I can't split with an empty string in (chicken irregex)?

Peter Bex
On Wed, May 01, 2019 at 11:18:31PM -0500, joshua wrote:
> I can't seem to figure out how to split a string into individual characters.

Hi Joshua,

The canonical way to do that would be string->list.

> I could swear this worked before, in Chicken 4.
> I'm now using Chicken 5.0.0 running on Void Linux.
>
> #;1> (import (chicken irregex))
> ; loading /usr/lib/chicken/9/chicken.irregex.import.so ...
> #;2> (irregex-split (irregex ",") "foo,bar,baz")
> ("foo" "bar" "baz")
> #;3> (irregex-split (irregex " ") "foo bar baz")
> ("foo" "bar" "baz")
> #;4> (irregex-split (irregex "") "foobarbaz")
> () ; wat
Hm, that is somewhat surprising.  I checked irregex upstream,
but as far as I can tell, this has never worked.  In extremely
old versions this would raise an internal error and in newer
versions it returns the empty list.

I can take a look but I'm not even sure what the correct behaviour is
supposed to be.

Cheers,
Peter

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Anyone know why I can't split with an empty string in (chicken irregex)?

joshua
On Thu, May 02, 2019 at 02:17:25PM +0200, Peter Bex wrote:
>
> Hm, that is somewhat surprising.  I checked irregex upstream,
> but as far as I can tell, this has never worked.  In extremely
> old versions this would raise an internal error and in newer
> versions it returns the empty list.
>
> I can take a look but I'm not even sure what the correct behaviour is
> supposed to be.
>

I guess I expected something like this (from Ruby):

home> rlwrap irb
irb(main):001:0> "foobar".split(//)
=> ["f", "o", "o", "b", "a", "r"]
irb(main):002:0> "foobar".split(/\s*/)
=> ["f", "o", "o", "b", "a", "r"]

Even if "" didn't work, I would expect "\\s*" to tokenize a string, eliminating whitespace.


joshua


_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users