Leonidas changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.1.1 released: https://ocaml.org/releases/5.1.1 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
<discocaml> <barconstruction> ```c
<discocaml> <barconstruction> assert (fpclassify(x) == FP_NORMAL);;
<discocaml> <barconstruction> assert (x == x);
<discocaml> <barconstruction> assert (!(isnan(x)));
<discocaml> <barconstruction> assert (isnormal(x));
<discocaml> <barconstruction>
<discocaml> <barconstruction> uint64_t abc = *((long long*)&x) ;
<discocaml> <barconstruction> printf("%" PRIx64 "\n", abc);
<discocaml> <barconstruction> /* Prints fff8000000000000 */
<discocaml> <barconstruction> printf("%f",x);
<discocaml> <barconstruction> /* Prints -nan */
<discocaml> <barconstruction> uint64_t x4 = 0xfff8000000000000;
<discocaml> <barconstruction> assert (x4 == abc);
<discocaml> <barconstruction> ```
<discocaml> <barconstruction> Ok here's I am after fixing the bitwise negation -> boolean negation typos.
<discocaml> <barconstruction> Does anyone have a suggestion on how to debug this
<companion_cube> What's to debug at this point?
<dh`> well
<dh`> it seems like assert(!isnan(x)) ought to fire if x actually contains 0xfff8000000000000
<dh`> are you sure you aren't building the C with assertions disabled?
<companion_cube> :D
<dh`> also have you done anything else that would lead the compiler to conclude the whole thing is UB?
<companion_cube> Good point, I'd run the whole thing in Godbolt
gzar has quit [Quit: WeeChat 4.2.2]
nickiminjaj has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jabuxas has joined #ocaml
<anadon> Why would `List.hd (List.rev char_list)` be giving me the error "Warning 8: this pattern-matching is not exhaustive. Here is an example of a case that is not matched: _::_::_"?
<dh`> that's not a pattern-matching
<anadon> The input of one function is passed to another with correct typing information, so that doesn't explain the issue to me.
<discocaml> <darrenldl> are you sure thats where the error comes from?
jabuxas has quit [Ping timeout: 268 seconds]
<anadon> Using the Ocaml online playground with the following fulltext: https://pastebin.com/ex6vy605
<discocaml> <yawaramin> getting a syntax error in this snippet. you are also using a couple of incorrect operators, instead of `and`, use `&&`. instead of `==`, use `=`
<anadon> Still only *just* learning the language
<dh`> yeah, and after fixing that it doesn't typecheck :-(
<discocaml> <yawaramin> tip: you can use a quoted string literal to avoid having to backslash-escape: `let path = {|/bin:/usr/bin:/home/user/horrible\:path|}`
<dh`> the calls to List.nth aren't passing the list (just n) and the lambda syntax in the folds is wrog
<discocaml> <yawaramin> this: `String.fold_left ( char_list, c = if s`
<discocaml> <yawaramin> should be: `String.fold_left (fun char_list c -> if s`
<discocaml> <yawaramin> or just define it as a named function immediately above
<dh`> preferably the latter
<dh`> also consider using shorter lines :-|
<discocaml> <yawaramin> also instead of `String.append` you should almost certainly use a `Buffer.t`. and instead of `List.append` you should almost certainly prepend with the cons operator `::` and then reverse the list at the end
<anadon> OK. I'll work those in as I can figure out how to.
<anadon> But I'm going to bed. It is almost 1AM here.
<discocaml> <yawaramin> `print_newline paths` should be something like `let () = List.iter print_endline paths`
<dh`> also it looks to me like the use of strings vs. lists isn't consistent
<dh`> I don't immediately see how the online playground got far enough to start complaining about incomplete matches
<dh`> but you might want to consider match List.rev char_list with | [] -> false | '\\' :: _ -> true and so forth instead of mucking with hd and nth
<dh`> easier to read
jabuxas has joined #ocaml
trillion_exabyte has quit [Ping timeout: 268 seconds]
trillion_exabyte has joined #ocaml
Serpent7776 has joined #ocaml
jabuxas has quit [Quit: oops :p]
bartholin has joined #ocaml
waleee has joined #ocaml
wingsorc has quit [Quit: Leaving]
waleee has quit [Ping timeout: 264 seconds]
waleee has joined #ocaml
<discocaml> <contextfreebeer> you aren't allowed to do casts like this, they violate the strict aliasing rule. if you want to do type punning like this (in C) you are supposed to use a union
<discocaml> <barconstruction> Thanks. In this case I suspect it happens to be correct, as if I eliminate that cast and return the float to the OCaml program and use Int64.bits_of_float then I get the same value of 0xFFF800000000. However I understand that the compiler is not at all guaranteed to do that.
<discocaml> <barconstruction>
<discocaml> <barconstruction> In any case I learned last night that the owl library compiled by default with the -ffast-math flag which performs a number of unsafe optimizations and in particular assumes away isnan calls because you're telling the compiler that there are no nan's. So I assume if I change the build configuration to eliminate -Ofast and related flags I will get the correct answer.
mbuf has joined #ocaml
<discocaml> <contextfreebeer> Ah, quite possibly
trillion_exabyte has quit [Ping timeout: 240 seconds]
trillion_exabyte has joined #ocaml
gzar has joined #ocaml
<anadon> Improved my escaped path splitting codes, but I'm having what looks like one last issue before I really need nit-picking to improve what I've written. https://pastebin.com/F5i1A83T
<anadon> I guess this comes down to, how do I return a stack when I push to it?
<octachron> You can just return the stack that you pushed too with "...;c".
<octachron> Note however that Stacks are a horrible fit to your issue, and your code is accidentally quadratic.
<anadon> When I tried using semicolons earlier they did not work, and they don't seem to be working now.
<octachron> The issue is not the semi-colon.
<anadon> 'You can just return the stack that you pushed too with "...;c".' -- ?
<octachron> Yes, and the issue in your updated code has nothing to do with the new `;`.
<anadon> Which is?
<octachron> How are your interpreting the compiler error message?
<octachron> Or worded in a different way, why is there a type error on "let proto_paths = String.fold_left a Stack.create() path" ?
<anadon> @page { size: 8.27in 11.69in; margin: 0.79in } p { line-height: 115%; margin-bottom: 0.1in; background: transparent } “This expression has type string Stack.t -> char -> string Stack.t but an expression was expected of type ('a -> 'b) -> char -> 'a -> 'b Type string Stack.t = string Stdlib__Stack.t is not compatible with type 'a -> 'b”
<anadon> where ‘a → ‘b is really a ‘c of String Stack, meaning the compiler is looking for a pattern match of a function for ‘c → char ‘c and the type “string Stack.t” is that and is also a name for “ string Stdlib__Stack.t” but the resolved names are just not clean. So I have no idea why it is complaining. It looks correct and like it has sufficient information.
<anadon> GDI libreOffice
<octachron> anadon, as a beginner, you should consider that the typechecker is always right.
<octachron> The error message is pointing out the fact that in "String.fold_left a Stack.create () path" the `fold_left` function is expecting to return a value of the same type as `Stack.create`.
<anadon> "string Stack.t" and "string Stdlib__Stack.t" are so close that I fall back to C++ instincts of type coercion.
<octachron> This point is a distraction (and should not happen with a correct setup). `Stack.t` is `Stdlib__Stack.t`.
<anadon> So I was right to disregard the typechecker.
<octachron> Nope.
<octachron> You should never disregard the typechecker in a strongly typed language. Your call to `fold_left` is ill-typed.
<octachron> Hint: Contrarily to C++, functions are first classes in OCaml.
<octachron> Hint 2: How many arguments do you count in the `fold_left` call?
<anadon> If that's the error message it gives me, it is a misdirection. All I can tell is that there is an error. Because it fixated on String Stack = String Stdlib_Stack, it takes away from where any issues really are. I will defend myself on that.
<anadon> I count 3 parameters.
<discocaml> <Kali> you passed 4
<discocaml> <Kali> a
<discocaml> <Kali> Stack.create
<discocaml> <Kali> ()
<discocaml> <Kali> path
<discocaml> <Kali> you need parentheses around (Stack.create ()) for it to be treated as one argument
<anadon> The typechecker wanted () after Stack.create
<anadon> That is a sharp edge. I can't have been those only one to have had that issue.
<discocaml> <Kali> it is a common beginner issue but you quickly grow out of it
<anadon> How do I debug this thing, now? It is wrong somewhere and it is entirely on me for doing this part wrong.
<discocaml> <Kali> well, what is the error now?
<anadon> Exception: Stdlib.Stack.Empty.
pi3ce has quit [Quit: No Ping reply in 180 seconds.]
pi3ce has joined #ocaml
<discocaml> <darrenldl> you start off with an empty stack
Tuplanolla has joined #ocaml
<discocaml> <darrenldl> scratch what i said
<discocaml> <Kali> you switched (Stack.create ()) and proto_paths
<octachron> No? Iterating over the empty stack is not useful? The issue is more the Stack.pop at the start in `b` when the accumulator stack is empty.
<discocaml> <Kali> oh, yes
<discocaml> <Kali> you need to change `Stack.pop string_stack` to `if Stack.length string_stack = 0 then "" else Stack.pop string_stack`, i believe
<discocaml> <Kali> also, the resulting strings are backwards, so you'll need to reverse those
<anadon> Getting it.
<anadon> I know there are issues. I'm flexing muscles I haven't used in years. Working on it.
<anadon> octachron: You're taking issue with my use of stacks overall. Why? What do you see that I do not?
<octachron> You are building strings with "^": this is quadratic in the size of the built strings.
<anadon> What does that have to do with stacks?
<octachron> Using stack to store characters also increases the memory footprint by a factor 16
<octachron> Overall, my impression is that stacks afford you very little, compared to directly splitting the strings with a recursive function.
<anadon> Ignoring that the strings are reversed, because that's really uninteresting, I had asked about a streaming processing method a number of days ago and explicitly told to do this instead. So this is neither optimal or idiomatic. What exactly is expected here?
<discocaml> <limp.biskit> is a simple recursive function adding data into a buffer not the best data thing for this?
<discocaml> <limp.biskit> not purely functional but it would be functioning
<anadon> This uses syntax which I have not yet encountered.
<anadon> I'm going to need some time to parse this.
<anadon> octachron: Your code is giving me the error "This expression has type string but an expression was expected of type char"
<anadon> just " -> ' made it happy, nvm
<anadon> "This function has type char -> char -> int -> int -> string -> string list It is applied to too many arguments; maybe you forgot a `;'." So still not quite working.
<anadon> I'm taking this as an "exercise left for the reader" situation.
<octachron> "let split_path s = split '/' ':' 0 0 s"
<octachron> no, wrong escape character: "let split_path s = split '\\' ':' 0 0 s"
Guest11 has joined #ocaml
Guest53 has joined #ocaml
Guest11 has quit [Ping timeout: 250 seconds]
Guest53 has quit [Quit: Client closed]
bibi__ has quit [Quit: Konversation terminated!]
<discocaml> <leviroth> Broadly speaking I am confused by the desire to handle escaping in PATH. By my reading of the standard, there is no provision for escaping, and you're just encouraged to not use `:` in paths that might become part of PATH.
<discocaml> <leviroth> (And note that attempting to add escaping in the consumer of PATH is not strictly "backwards compatible", as it causes you to misinterpret paths that contain `\`.)
mbuf has quit [Quit: Leaving]
<dh`> it's still a good beginner exercise :-)
troydm has joined #ocaml
<dh`> some other example versions: https://www.netbsd.org/~dholland/tmp/split1.ml (and split2, split3)
<dh`> the relative conciseness of split3 will show why I recommended writing it that way yesterday
<dh`> (also it handles more of the corner cases correctly, and it generalizes readily to more complicated matching)
bibi_ has joined #ocaml
<anadon> leviroth: consider it a way to push my learning a new language.
<octachron> dh`, creating a char list is a biog no in my book.
<dh`> that's up to you but it certainly doesn't matter for strings of the size we're talking about
<dh`> I suppose a fourth way to do it is by creating a list of positions by folding over the string and then extracting substrings one at a time
<dh`> but, the more processing you need to do the less value there is in handling substrings as units
<dh`> you could also do it like you'd write the C code and stuff characters into a Bytes instead of making a list
<octachron> Even in your split3 function, you can directly represents the substring as a character range.
<octachron> There is no need to incur a 16x memory overhead for no reasons.
<dh`> yes, of course you can, but the question is how many substrings you produce vs. how many chars, and that's workload-dependent
<dh`> a list of pairs of ints for ranges is only smaller than a list of chars if the density of distinct substrings is low enough
<dh`> since a list of pairs of ints is going to be 32 bytes per entry
<octachron> No? You only have to keep the current substring range.
<dh`> then you're back to code like split2
ebb has quit [Quit: Somebody set up us the bomb]
<octachron> Neither? You just have to not use the inefficient representation for the current word in split3.ml
ebb has joined #ocaml
ebb has quit [Max SendQ exceeded]
<dh`> no, it becomes a mess
<dh`> try writing it
<dh`> to begin with, String doesn't have a foldi_left
<dh`> so you have to write your own in order to have access to the positions
<anadon> (eagerly listening in CS)
<dh`> then you also need a way to be able to have partial results that are not substrings
ebb has joined #ocaml
ebb has quit [Max SendQ exceeded]
ebb has joined #ocaml
ebb has quit [Max SendQ exceeded]
ebb has joined #ocaml
ebb has quit [Max SendQ exceeded]
ebb has joined #ocaml
<dh`> you clearly didn't compile it :-) ("mdoule")
ebb has quit [Max SendQ exceeded]
<octachron> I did add the submodule at the last minute, I am not sure how this is relevant?
ebb has joined #ocaml
<dh`> it's not
trillion_exabyte has quit [Read error: Connection reset by peer]
trillion_exabyte has joined #ocaml
<dh`> however, _running_ it reveals that it doesn't handle trailing : correctly, and it doesn't reduce \: to just :
ebb has quit [Max SendQ exceeded]
<dh`> it also doesn't reduce \\ to \ and (relatedly) doesn't split if it gets \\:
<dh`> the desired behavior for \\ wasn't specified that I recall but in general if you want to be able to have the escape character appear it has to escape itself
ebb has joined #ocaml
<dh`> and, dealing with these cases is going to add complexity :-)
ebb has quit [Max SendQ exceeded]
<octachron> Agreed, the ESC ESC will need to be split. Not sure what is the right specification for trailing `:` and reducing `\\` to `\` or not.
<octachron> And the reduction will mean switching to a buffer rather than a string range for the current word.
ebb has joined #ocaml
<octachron> Anyway that was mostly me musing on my feelings that most of the time list of chars are a costly detour
ebb has quit [Max SendQ exceeded]
ebb has joined #ocaml
ebb has quit [Max SendQ exceeded]
ebb has joined #ocaml
wingsorc has joined #ocaml
<dh`> trailing : should definitely produce an empty string into the output list (as should ::)
ebb has left #ocaml [WeeChat 4.2.1]
bartholin has quit [Quit: Leaving]
<dh`> anyway, it can be done
<dh`> it's not a horrorshow, just no longer tidy or concise
Serpent7776 has quit [Ping timeout: 264 seconds]
masterbuilder has quit [Ping timeout: 256 seconds]
conjunctive has quit []
masterbuilder has joined #ocaml
Tuplanolla has quit [Quit: Leaving.]