companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.2.0 released: https://ocaml.org/releases/5.2.0 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
mal`` has joined #ocaml
Inline has quit [Quit: Konversation terminated!]
Inline has joined #ocaml
YuGiOhJCJ has joined #ocaml
<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> <froyo> i.e. `String.to_seq ".aoeu//" |> Seq.filter (function ...) |> String.of_seq`
<myrkraverk> I turned it into filter_map to downcase at the same time.
<myrkraverk> And now I have a semi-useful word counter I can throw at ASCII text files.
bibi_ has quit [Quit: Konversation terminated!]
bartholin has joined #ocaml
toastal has joined #ocaml
Tuplanolla has joined #ocaml
<discocaml> <_4ad> hi, opam upgrade fails with this: http://okturing.com/src/20078/body. I am on macOS/arm64.
<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
<discocaml> <yawaramin> interesting. the person who suggested it didn't justify why, i guess they weren't thinking about the distribution https://github.com/ocaml/ocaml/pull/80#discussion_r14857426
<companion_cube> It's a bit weird that our only global story for hashing is, really, the polymorphic hash
toastal has left #ocaml [Error from remote client]
<discocaml> <yawaramin> is it? it's the same global story for a lot of generic things
<discocaml> <yawaramin> is it? it's the same global story for a lot of generic things in OCaml
<discocaml> <froyo> companion_cube, you get a seed and you get to control how far it traverses your structure, it's alright tbh :P
waleee has joined #ocaml
chiselfuse has quit [Remote host closed the connection]
chiselfuse has joined #ocaml
chiselfuse has quit [Remote host closed the connection]
<companion_cube> I mean yeah, we lack a good story for typeclasses, nothing new there
<companion_cube> but with equality the stdlib functions are good
<companion_cube> with hashing it's a mixed bag :/
chiselfuse has joined #ocaml
<discocaml> <yawaramin> actually are we locked in to this decision in Uchar? couldn't we just change it to use `Hashtbl.hash`?
<discocaml> <froyo> Hashtbl.hash would introduce a dependency. same with to_int |> Int.hash
<companion_cube> we should honestly have a Hash module
<companion_cube> and a few intrinsics for hashing primitive types
<companion_cube> and combining hashes/carrying a hash context around
waleee has quit [Ping timeout: 255 seconds]
<discocaml> <froyo> hashing combinators huh... name it Hsh!
<discocaml> <froyo> (like Fmt)
<companion_cube> yikes :p
<companion_cube> I call it CCHash but it'd be nice if the runtime provided a few (fast) combinators
<companion_cube> stuff that takes a int64 and some type t (int, string, etc.) and mixes the type into the int64
<discocaml> <froyo> I've seen a `mix` primitive idea thrown here and there in the issue tracker
waleee has joined #ocaml
torretto has quit [Remote host closed the connection]
torretto has joined #ocaml
Serpent7776 has quit [Ping timeout: 268 seconds]
infinity0 has quit [Remote host closed the connection]
infinity0 has joined #ocaml
chiselfuse has quit [Ping timeout: 260 seconds]
chiselfuse has joined #ocaml
bartholin has quit [Quit: Leaving]
torretto has quit [Remote host closed the connection]
torretto has joined #ocaml
jabuxas has joined #ocaml
Opus has quit [Quit: .-.]
Opus has joined #ocaml
jabuxas has quit [Ping timeout: 255 seconds]
waleee has quit [Ping timeout: 264 seconds]
gzar has joined #ocaml