<andrewrk>
leeward, nope it was just needing some attention from someone who could merge it. merged!
<andrewrk>
thank you for writing docs
<leeward>
\o/
<leeward>
I have a less obviously good PR in the works. I needed a way to delete arbitrary elements from PriorityQueues.
<plumm>
andrewrk: regarding that pr: im trying to use log10 with a comptime int: what happens with 0?
<andrewrk>
it should either be a compile error or undefined, depending on whether log10 is defined to produce the undefined value, or assert that 0 is not given as a parameter
<plumm>
well it returns an int, but im using it in conjunction with isNegativeInf.. the returnType is still comptime_int
<andrewrk>
if I were to guess the best API right now, I'd define it to return undefined for parameter 0
<plumm>
hmm
<andrewrk>
`@as(comptime_int, undefined)` is valid zig
<andrewrk>
it's only when you *branch* on undefined that it becomes Illegal Behavior
<andrewrk>
so for example: const x: comptime_int = undefined; //ok
<andrewrk>
if (x != 0) { // compile error: branch on undefined value
<andrewrk>
however it is perfectly acceptable for some APIs to say, "calling this asserts that the parameter is not 0"
<andrewrk>
which makes it Illegal Behavior to pass 0 for the parameter, which means if you do it at compile time, it should be a compile error
<plumm>
no worries now, i dont have to use negativeInf if the input argument is comptime since math.log10(0) returns 0
<andrewrk>
I don't know which one log10 is currently, but it should be in the doc comments for the function
<plumm>
but since log10(0) is undefined in math, i think that is an issue
<andrewrk>
defining log10(0) to be 0, when it is undefined in math, is not very ziggy
<plumm>
i think thats because log10(0) right now converts it to a float and then floors it and returns it
<andrewrk>
if it happens to be 0 by accident, but not guaranteed by the API, it would be appropriate for the implementation to do something like `if (want_runtime_safety and param == 0) return undefined;`
<plumm>
wouldn't it make more since to just @compileError at the call site since log10(0) isn't possible? or is there some benefit to letting the variable be undefined
<andrewrk>
making a call with 0 be a compile error is the other thing that I noted would be reasonable to do: it is perfectly acceptable for some APIs to say, "calling this asserts that the parameter is not 0"
<andrewrk>
deciding between one or the other involves subtle considerations
<plumm>
right
<andrewrk>
one benefit of undefined would be that it allows you to calculate something before knowing whether you will need the result or not; and as long as you end up not needing the result when it is undefined, everything works
<plumm>
you said branching on an undefined value is checked behavior, right?
<andrewrk>
it's checked at compile-time, but not yet checked at runtime
<andrewrk>
however that is planned
<plumm>
so my thoughts are: compile error for now, and when runtime undefined detection is in, swap that to undefined. does that sound reasonable?
<andrewrk>
reasonable for what? a pull request to modify log10 in the std lib?
plumm has quit [Read error: Connection reset by peer]
plumm has joined #zig
<plumm>
sorry about that, computer froze
schme245 has joined #zig
<plumm>
yeah, all math undefined functions should be a compile error (e.g sqrt(-x), log(0)) until runtime undefined detection. i just wanted to know if the pr was worth the effort
traviss has joined #zig
<Snektron>
Do you think those are fixable with those arbitrary ranged ints?
schme245 has quit [Ping timeout: 258 seconds]
<andrewrk>
I don't think the implementation should be affected by whether or not we have runtime safety for branching on undefined
<andrewrk>
I think the API should be the best thing, regardless, and the language improvements is a separate concern
<Snektron>
I guess that would make the api very inconvient without some kind of pattern matching though
<fengb>
I need to copy it to 3 more places and it's getting pretty gnarly :/
<andrewrk>
fengb, I was hoping to solve std.fmt.format without an allocator
<fengb>
That's a stack allocator
<fengb>
It'll be pre-allocated on format()
<andrewrk>
I see
<fengb>
I still need to find the actual frame size, but it solves the recursion
<fengb>
Or it should... I suppose it can possibly get into a loop with a custom formatter
<andrewrk>
you know about @frameSize, yeah?
<fengb>
Yeah but these are generic functions
<andrewrk>
yeah good point I don't think it's relevant here
<fengb>
I might have missed something though
<andrewrk>
you're working on the thing that I'm planning on working on next, after I solve some tech debt with regards to variables in ir.cpp, and after I get some more of these PRs merged
<andrewrk>
which is cool
<andrewrk>
but then when I try to help it's putting me in an endless loop
<fengb>
Alright, I can just brute force this last step
<fengb>
And hopefully solve most of the recursion. I'm 90% done... so there's 90% more to go :P
<leeward>
Hooray, the tests run again!
<andrewrk>
ha
<andrewrk>
fengb, if you can uncomment the block of code with EAGAIN in std.os.write, and then run the simple tcp chat server example successfully, you win zig
ur5us has quit [Ping timeout: 260 seconds]
<fengb>
Oof, I may need to refactor format() to generate an AST. I'd like to traverse it twice, once to get the needed stacksize and another to actually run it
Chioque has joined #zig
frmdstryr has quit [Ping timeout: 265 seconds]
dddddd has quit [Remote host closed the connection]
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
marmotini_ has joined #zig
<via>
'0X123' is a valid hex literal, but translate-c will translate as-is, and thats invalid in zig. i have a branch that adds 0X for zero-literals, but not sure if thats the right way to do it
swoogan has quit [Ping timeout: 260 seconds]
marmotini_ has quit [Ping timeout: 268 seconds]
<wilsonk>
via: maybe open an issue and ask there? Andrew and/or some of the others usually answer those and can debate the code/merits better there. You can also post some code examples (or a diff/paste) pretty easily for others to check at their leisure ;)
<fengb>
`@sizeOf(@TypeOf(async formatValue(@as(f128, 1.0), options.fmt, options, &tmp_generator)))` any idea why comptime ends up executing this async function?
schme245 has joined #zig
schme245 has quit [Ping timeout: 265 seconds]
Chioque has quit [Quit: WeeChat 2.6]
mahmudov has quit [Ping timeout: 260 seconds]
_whitelogger has joined #zig
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
dozn_ is now known as dozn
jjido has joined #zig
darithorn has quit [Quit: Leaving]
schme245 has joined #zig
frett27 has joined #zig
schme245 has quit [Remote host closed the connection]
<fengb>
Yeah that should be easy. I’ll make a note
<schme245>
thanks, appreciate it! 🙏
<fengb>
Well this one probably isn’t going to be ready soon so it might be better to convince that one to go in first :P
doublex has quit [Ping timeout: 240 seconds]
PC9801 has joined #zig
<PC9801>
hi there, I was wondering if anyone could point me in the right direction for opening a tcp stream in zig if possible :)
decentpenguin has joined #zig
adamkowalski has joined #zig
<adamkowalski>
andrewrk: i'm trying to add flycheck support for zig so I can get linting in emacs. is there a way to run the compiler on a file, but just do parsing + error reporting?
<via>
is it possible to do packed/extern anonymous struct literals?
dingenskirchen1 has joined #zig
dingenskirchen has quit [Ping timeout: 248 seconds]
dingenskirchen1 is now known as dingenskirchen
<via>
should i be able to address-of something defined as an extern opaquetype? trying to use libopencm3 where the header forward-declares a struct and uses it a lot, but we also address-of an instance of the struct: https://gist.github.com/via/0e27ef8236aa95e6bf8b9b733d7b35c2
<via>
the symbol has an address in the lib at link time
schme245 has quit [Remote host closed the connection]
<pixelherodev>
I would certainly think so
<pixelherodev>
A value defined as extern is available to the module in question
<pixelherodev>
Otherwise, there'd be no point in an extern decl
<pixelherodev>
If you can access the value, by definition, you know its address
<via>
well, i don't have visibility into any of the fields, so i can only deal with addresses of it, not the value
<via>
so i see why zig does not like the fact that i'm declaring a var of that type