* [Caml-list] [repost] Request for more String functions
@ 2004-02-20 17:28 Richard Jones
2004-02-20 19:34 ` Dustin Sallings
0 siblings, 1 reply; 7+ messages in thread
From: Richard Jones @ 2004-02-20 17:28 UTC (permalink / raw)
To: caml-list
To: caml-list@inria.fr
Subject: Request for more String functions
It's great that the String module in 3.07 has a String.iter function.
What would also be really useful would be:
- String.iteri
- String.map
- String.mapi
- String.fold_left
- String.fold_right
Another difficulty I find is doing search and replace on strings, in
simple cases where the overhead of a regular expression probably isn't
warranted. For example, escaping all '<' characters in a string with
'<'. It would be nice to have a Search.char_replace function to do
this.
Rich.
----- End forwarded message -----
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
Perl4Caml lets you use any Perl library in your type-safe Objective
CAML programs. http://www.merjis.com/developers/perl4caml/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] [repost] Request for more String functions
2004-02-20 17:28 [Caml-list] [repost] Request for more String functions Richard Jones
@ 2004-02-20 19:34 ` Dustin Sallings
2004-02-20 19:44 ` Richard Jones
0 siblings, 1 reply; 7+ messages in thread
From: Dustin Sallings @ 2004-02-20 19:34 UTC (permalink / raw)
To: Richard Jones; +Cc: caml-list
On Feb 20, 2004, at 9:28, Richard Jones wrote:
> Another difficulty I find is doing search and replace on strings, in
> simple cases where the overhead of a regular expression probably isn't
> warranted. For example, escaping all '<' characters in a string with
> '<'. It would be nice to have a Search.char_replace function to do
> this.
I ran into problems with just plain search first. My programs are 4x
faster with plain splits and searches than regex. Here's some of the
stuff I've added:
val split : string -> char -> int -> string list
val split_chars : string -> char list -> int -> string list
val strstr : string -> string -> int -> int
val ends_with : string -> string -> bool
val begins_with : string -> string -> bool
val string_of_chars : char list -> string
--
Dustin Sallings
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] [repost] Request for more String functions
2004-02-20 19:34 ` Dustin Sallings
@ 2004-02-20 19:44 ` Richard Jones
2004-02-20 19:54 ` Shawn Wagner
2004-02-20 20:08 ` William D. Neumann
0 siblings, 2 replies; 7+ messages in thread
From: Richard Jones @ 2004-02-20 19:44 UTC (permalink / raw)
To: Dustin Sallings; +Cc: caml-list
On Fri, Feb 20, 2004 at 11:34:39AM -0800, Dustin Sallings wrote:
> val split : string -> char -> int -> string list
> val split_chars : string -> char list -> int -> string list
> val strstr : string -> string -> int -> int
> val ends_with : string -> string -> bool
> val begins_with : string -> string -> bool
> val string_of_chars : char list -> string
Yes, ends_with and begins_with - I keep copying those functions from
file to file. It'd be great to have them in the std lib.
Along with:
List.truncate - returns the first N elements of a list
String.truncate - truncate a string to a given length
List.group_by - http://groups.yahoo.com/group/ocaml_beginners/message/1556
range : int -> int -> int list - produces a list of numbers from a to b
let (//) = Filename.concat
Rich.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
MOD_CAML lets you run type-safe Objective CAML programs inside the Apache
webserver. http://www.merjis.com/developers/mod_caml/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] [repost] Request for more String functions
2004-02-20 19:44 ` Richard Jones
@ 2004-02-20 19:54 ` Shawn Wagner
2004-02-21 2:07 ` ChoJin
2004-02-20 20:08 ` William D. Neumann
1 sibling, 1 reply; 7+ messages in thread
From: Shawn Wagner @ 2004-02-20 19:54 UTC (permalink / raw)
To: caml-list
On Fri, Feb 20, 2004 at 07:44:49PM +0000, Richard Jones wrote:
> On Fri, Feb 20, 2004 at 11:34:39AM -0800, Dustin Sallings wrote:
> > val split : string -> char -> int -> string list
> > val split_chars : string -> char list -> int -> string list
> > val strstr : string -> string -> int -> int
> > val ends_with : string -> string -> bool
> > val begins_with : string -> string -> bool
> > val string_of_chars : char list -> string
>
> Yes, ends_with and begins_with - I keep copying those functions from
> file to file. It'd be great to have them in the std lib.
<Plug> Many of these (And everything the OP asked for, though I had to add
some of them just now) are in my extlib library
(http://raevnos.pennmush.org/code/extlib/), though under different names.
It's a collection of things that would be useful in the standard libraries
that come with ocaml, but aren't there. I keep adding to it all the time
(Also just added the getpgid/setpgid functions also just requested on the
list).
>
> Along with:
>
> String.truncate - truncate a string to a given length
This one's in it too.
</Plug>
--
Shawn Wagner
shawnw@speakeasy.org
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] [repost] Request for more String functions
2004-02-20 19:54 ` Shawn Wagner
@ 2004-02-21 2:07 ` ChoJin
0 siblings, 0 replies; 7+ messages in thread
From: ChoJin @ 2004-02-21 2:07 UTC (permalink / raw)
To: caml-list
Shawn Wagner <shawnw@speakeasy.org> writes:
> On Fri, Feb 20, 2004 at 07:44:49PM +0000, Richard Jones wrote:
>> On Fri, Feb 20, 2004 at 11:34:39AM -0800, Dustin Sallings wrote:
>> > val split : string -> char -> int -> string list
>> > val split_chars : string -> char list -> int -> string list
>> > val strstr : string -> string -> int -> int
>> > val ends_with : string -> string -> bool
>> > val begins_with : string -> string -> bool
>> > val string_of_chars : char list -> string
>>
>> Yes, ends_with and begins_with - I keep copying those functions from
>> file to file. It'd be great to have them in the std lib.
>
> <Plug> Many of these (And everything the OP asked for, though I had to add
> some of them just now) are in my extlib library
> (http://raevnos.pennmush.org/code/extlib/), though under different names.
> It's a collection of things that would be useful in the standard libraries
> that come with ocaml, but aren't there. I keep adding to it all the time
> (Also just added the getpgid/setpgid functions also just requested on the
> list).
I'm a beginner in ocaml, but from time to time I have to convert a
char to a string. And I was surprised when I couldn't find
"string_of_char".
Is there a better way than String.make 1 my_char ?
--
Best Regards
ChoJin
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] [repost] Request for more String functions
2004-02-20 19:44 ` Richard Jones
2004-02-20 19:54 ` Shawn Wagner
@ 2004-02-20 20:08 ` William D. Neumann
2004-02-21 1:18 ` David Fox
1 sibling, 1 reply; 7+ messages in thread
From: William D. Neumann @ 2004-02-20 20:08 UTC (permalink / raw)
To: caml-list
On Fri, 20 Feb 2004, Richard Jones wrote:
> String.truncate - truncate a string to a given length
I call my version procrustes, because it will also pad a string that is
too short with an optional padding character (defaults to ' '). In any case,
it would be great to see some of these functions added to the standard
library so I wouldn't have to tote around my Wdn module...
William D. Neumann
---
"Well I could be a genius, if I just put my mind to it.
And I...I could do anything, if only I could get 'round to it.
Oh we were brought up on the space-race, now they expect you to clean toilets.
When you've seen how big the world is, how can you make do with this?
If you want me, I'll be sleeping in - sleeping in throughout these glory days."
-- Jarvis Cocker
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-02-21 2:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-20 17:28 [Caml-list] [repost] Request for more String functions Richard Jones
2004-02-20 19:34 ` Dustin Sallings
2004-02-20 19:44 ` Richard Jones
2004-02-20 19:54 ` Shawn Wagner
2004-02-21 2:07 ` ChoJin
2004-02-20 20:08 ` William D. Neumann
2004-02-21 1:18 ` David Fox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox