<myrkraverk>
What is a good way to trim punctuation from words? I have a simple word counter, which reads lines and splits them on spaces, but then I have punctuation in my words.
<myrkraverk>
I used String.split_on_char to split the lines.
waleee has quit [Ping timeout: 264 seconds]
troydm has joined #ocaml
<discocaml>
<deepspacejohn> The simplest would probably be to use String.iter and write the characters to a buffer, and skip the punctuation characters you don’t want to keep. (That’s assuming that you only want to remove ASCII punctuation.)
<myrkraverk>
For my exercise, I'm limiting the input to ASCII, so that works.
<myrkraverk>
As an exercise, I tried the following in the REPL, but it seems to return the function, not execute the last stage.
<myrkraverk>
let f ( c ) = let l = Char.lowercase_ascii c in let k = Char.code l in Char.code 'a' >= k && Char.code 'z' <= k in Seq.filter f ( String.to_seq ".aoeu//" ) ;;
<myrkraverk>
Is there a way to fix that?
<myrkraverk>
While I'm sure there are better ways to do this; I just wanted to exercise with hand written code first.
<myrkraverk>
Ah, I was just missing the String.of_seq in the final stage.
<myrkraverk>
let f ( c ) = let l = Char.lowercase_ascii c in let k = Char.code l in Char.code 'a' <= k && Char.code 'z' >= k in String.of_seq( Seq.filter f ( String.to_seq ".aoeu//" ) ) ;;
<myrkraverk>
works fine.
<discocaml>
<darrenldl> reads like you're building a pipeline, in which case you might enjoy the pipeline operator: String.to_seq ".aoeu//" |> Seq.filter f |> String.of_seq
<discocaml>
<darrenldl> let f c = ... is also more common than let f ( c )
<myrkraverk>
I'll keep that in mind.
YuGiOhJCJ has quit [Remote host closed the connection]
YuGiOhJCJ has joined #ocaml
chiselfuse has quit [Remote host closed the connection]
chiselfuse has joined #ocaml
<discocaml>
<froyo> for the filtering function`let f c = ...`, you could have just `function 'a'..'z' | 'A'..'Z' -> true | _ -> false`
<discocaml>
<_4ad> I can obliterate `.opam` and reinstall, but these sort of problems happen for me every couple of months. it's just macOS with homebrew and opam installed from homebrew. I do nothing more advanced than `opam update && opam upgrade`.
toastal has quit [Ping timeout: 264 seconds]
YuGiOhJCJ has quit [Quit: YuGiOhJCJ]
toastal has joined #ocaml
<discocaml>
<_4ad> ok, with help from `#opam` I fixed it. the `patch(1)` has to be GNU patch, so if you have homebrew after the system utilities, it won't work.
<discocaml>
<_4ad> if you want to keep homebrew after the system utilities, this works: `ln -s /opt/homebrew/bin/patch $HOME/bin/gpatch` then `rm -rf $HOME/.opam/repo/default{,.tar.gz} && opam update default`, assuming `$HOME/bin` is in your `PATH`.
toastal has left #ocaml [Error from remote client]
toastal has joined #ocaml
mbuf has joined #ocaml
troydm has quit [Ping timeout: 264 seconds]
leah2 has quit [Ping timeout: 264 seconds]
torretto has quit [Remote host closed the connection]
chiselfuse has quit [Read error: Connection reset by peer]
chiselfuse has joined #ocaml
torretto has joined #ocaml
leah2 has joined #ocaml
toastal has left #ocaml [Disconnected: Hibernating too long]
toastal has joined #ocaml
waleee has joined #ocaml
waleee has quit [Ping timeout: 264 seconds]
chiselfuse has quit [Remote host closed the connection]
chiselfuse has joined #ocaml
mbuf has quit [Quit: Leaving]
Inline has quit [Quit: Konversation terminated!]
Inline has joined #ocaml
Anarchos has joined #ocaml
bibi_ has joined #ocaml
leah2 has quit [Ping timeout: 264 seconds]
sailorCa- has quit [Ping timeout: 268 seconds]
leah2 has joined #ocaml
waleee has joined #ocaml
sailorCat has joined #ocaml
waleee has quit [Ping timeout: 255 seconds]
Anarchos has quit [Quit: Vision[]: i've been blurred!]
Serpent7776 has joined #ocaml
<discocaml>
<froyo> why is `Uchar.hash` just its int value? Shouldn't it be actually hashed like `Int.hash` and `Char.hash`?
<discocaml>
<yawaramin> which library? Jane Street?
<discocaml>
<froyo> stdlib.
<companion_cube>
Sadly the stdlib is really lacking when it comes to hashing
<discocaml>
<yawaramin> can someone explain why it matters that it's just the integer value of the uchar? if it's 1:1 mapping, it doesn't matter, does it?
<discocaml>
<froyo> why not extend that argument to `Bool.hash` which does actual hashing then
<companion_cube>
It matters because it's not a good random distribution