This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1 +1 @@
(apply str (interpose "." (seq (.split #"," "Hello,How,Are,You,Today"))))
(apply str (interpose "." (.split #"," "Hello,How,Are,You,Today")))

View file

@ -0,0 +1,22 @@
:- object(spliting).
:- public(convert/2).
:- mode(convert(+atom, -atom), one).
convert(StringIn, StringOut) :-
atom_chars(StringIn, CharactersIn),
phrase(split(',', Tokens), CharactersIn),
phrase(split('.', Tokens), CharactersOut),
atom_chars(StringOut, CharactersOut).
split(Separator, [t([Character| Characters])| Tokens]) -->
[Character], {Character \== Separator}, split(Separator, [t(Characters)| Tokens]).
split(Separator, [t([])| Tokens]) -->
[Separator], split(Separator, Tokens).
split(_, [t([])]) -->
[].
% the look-ahead in the next rule prevents adding a spurious separator at the end
split(_, []), [Character] -->
[Character].
:- end_object.

View file

@ -0,0 +1,3 @@
| ?- spliting::convert('Hello,How,Are,You,Today', Converted).
Converted = 'Hello.How.Are.You.Today'
yes

View file

@ -0,0 +1,2 @@
l: split("Hello,How,Are,You,Today", ",")$
printf(true, "~{~a~^.~}~%", l)$

View file

@ -0,0 +1 @@
'Hello,How,Are,You,Today'.split(',').join('.').say;

View file

@ -0,0 +1 @@
say join '.', split ',', 'Hello,How,Are,You,Today';

View file

@ -1,5 +1,3 @@
#lang racket
(for ([s (regexp-split #rx"," "Hello,How,Are,You,Today")])
(printf "~a." s))
(newline)
(string-join (string-split "Hello,How,Are,You,Today" ",") ".")
;; -> "Hello.How.Are.You.Today"