<DutchGh0st>
oh, I just had a little thought about it andrewrk. the current std.meta hasField function could take a const boolean, to specify if it should search recursively, or just to search the struct you gave it
<andrewrk>
DutchGh0st, I think recursive search is application specific logic
<DutchGh0st>
yeahh, probablyy
<tgschultz>
yeah, I'm having difficulty seeing how it would be generally useful. I imagine this is for some kind of assistence with flattening composed structs? How would I access the field, given that I don't know where in the structure it is? What if there are two matches? etc.
<DutchGh0st>
huh, 2 matches, have not though of that one..oopsy
<DutchGh0st>
well it just returns true on the first one it finds
<tgschultz>
Sure, but how is that information useful?
<DutchGh0st>
maybe fieldnames aren't that usefull recusively, fieldtypes however could be
tleguern has quit [Ping timeout: 256 seconds]
<DutchGh0st>
in a way that you can have a dummy struct that specifies `phantom` behaviour,
<DutchGh0st>
kind of like marker traits in Rust, but in this case it would be marker fields
<tgschultz>
I'm not following. I'm not familiar with marker traits in Rust (or Rust in general). What are they used for?
<DutchGh0st>
For example there's been quite some changes in the way they want to kind of ensure safety with regards to generators that have references across yield points
<DutchGh0st>
in other words, if you resume the generator, then you'd move, all the references become invalid. To solve this, they have a marker trait called Unpin. In this specific case, Unpin specifies that a type is `safe` to move
<DutchGh0st>
generators are !Unpin (not Unpin)
<DutchGh0st>
but because we don't have traits, but you can simulate this marker behaviour with just an empty struct,
<tgschultz>
DutchGh0st: I think instead of a field for that you want a definition. `struct { const unpin = void{}; };` vs `struct { unpin: void, };`. it won't make any difference to the compiler, but you also won't have to initialize the void field. The change in the metafunction would be to iterate over all definitions then recursively through each field.
<tgschultz>
actually the iteration over definitions could just be replaced by 'hasDef()'
<DutchGh0st>
mhhh
<DutchGh0st>
but then I steal a possible fieldname away?
<DutchGh0st>
I guess hasDef i'm going to write then haha
<develonepi3>
andrewrk, I just updated my documentation of openjpeg for Ultibo. This is found https://github.com/develone/openjpeg/blob/ultibo/openjpeg.odt. A 2048 x 2048 takes 16 sec which is better than my FPGA of the DWT. Would zig improve on this?
<develonepi3>
andrewrk, This work also demonstrates what can be done with bare metal on the RPi. Since this provides an EBCOT bit stream not just the lifting step.
very-mediocre has joined #zig
<AlexMax>
Zig is one of those languages that I put a pin in because the back-of-the-box pitch looked pretty neat
<AlexMax>
However, in conversation about this language, someone else pointed out that the "Why Zig?" wiki page claimed that Zig has no metaprogramming.
<AlexMax>
While at the same time providing generics through comptime
<AlexMax>
What is the disinction...or I suppose the difference in practice - between C++ templates and Zig's comptime T?
<AlexMax>
The same wiki page also claims that allocators are explicit, but I think most C++ types that allocate memory allow you to pass a custom alloactor to them.
<AlexMax>
basically, `fn max(comptime T: type, a: T, b: T) T` vs `<typename T> T max(T a, T b)`
<tgschultz>
Zig has no default allocator. If something doesn't take an allocator as a parameter in idiomatic Zig, it doesn't allocate.
dewf has joined #zig
<tgschultz>
In C/Cpp there are no such guarantees.
<AlexMax>
Yeah, and some functions don't even take alternative allocators in a trivial way (asprintf, strdup)
<AlexMax>
I see. What about C++ templates vs zig generics?
<AlexMax>
What make's Zig's approach better? Is it faster? Does it produce more comprehensible error messages?
<tgschultz>
I'm not sure. If I had to guess, I'd say that the difference is Zig doesn't have a separate language for meta programming. Type is a type of type `type`. It definitely produces better error messages than Cpp templates, but to be frank that's a really low bar.
<andrewrk>
AlexMax, c++ templates vs zig comptime parameters are almost equivalent. some differences are: * zig has no overloading/inference, which makes compile errors much simpler * it's much faster in zig because we have a module system instead of a preprocessor. with C++ the compiler does the work N times and the linker has to deduplicate the work
<andrewrk>
* in zig when you have a comptime parameter, that parameter can participate in comptime expressions ("static if"). I don't believe that works in C++
<andrewrk>
if it is guaranteed to work on template parameters, then that last bullet point is equivalent
<AlexMax>
I see. Still, perhaps the "Why Zig" wiki page could be updated to be worded differently.
<andrewrk>
what is your proposed change?
<AlexMax>
I'm not sure what to change it to, but the point that tripped up my friend is the part about "no metaprogramming"
darithorn has joined #zig
<AlexMax>
Since it seemed to him that comptime + types implementation seemed to him to be broadly equivalent to C++ templates.
<AlexMax>
I did a google search and somebody on the D language forum brought up the same point on the same wiki article.
gunnarahlberg has joined #zig
<gunnarahlberg>
Hi again!
<andrewrk>
I should probably move that wiki page to my personal blog as it was not really a community created page anyway. I'll do that and then update the content. I can make this case much more clearly now (2 years later)
<andrewrk>
sure thing, any contribution would be welcome
<andrewrk>
I think someone may have started this effort, I'd have to search the IRC logs for --test-name-prefix to remind myself
<gunnarahlberg>
I'll search logs
DutchGh0st has joined #zig
<DutchGh0st>
I tried to do an `if(comptime expr) {}` in a struct declaration, and it didn't work, why actually doesn't that work?
<andrewrk>
DutchGh0st, that's never been a feature - if statements are only valid in block scope
<DutchGh0st>
well, guess I can just get around it
<andrewrk>
sorry not block scope. but they're not valid top level declarations
<DutchGh0st>
`var s = undefined; if (expr) { s = struct { whatever } } else { s = struct { otherstuff } }`
<andrewrk>
struct fields are declarative
<DutchGh0st>
*var s: type = undefined
<DutchGh0st>
which seems to work actually
<andrewrk>
why not: const s = if (expr) struct {whatever } else struct { otherstuff };
<gamester>
you can do "struct_field: if(comptime expr) A else B", that's all I know
<andrewrk>
gamester, that's correct, and the `comptime` is redundant in that example
<gamester>
yes
<DutchGh0st>
huh, mh, I guess, but depending on the if, I have a struct with 1 field, else 2
<andrewrk>
it's still declarative. never at any point does a struct exist which only has some of its fields and then more are added later
<gamester>
DutchGh0st: field: if(expr) T else void
<andrewrk>
it's important for structs to be declarative because they can reference themselves
<DutchGh0st>
I was actually looking at andre alexandrescu's bits of his checkedInt implementation, where he does use if's and else's to include fields in structs
<DutchGh0st>
so I figured I'd try it out in Zig
<gamester>
the zig way is "else void"
<andrewrk>
AlexMax, ^ example of zig not having metaprogramming
<DutchGh0st>
ehh, I shouldn't do this anyway I think:
<DutchGh0st>
const s = if (@sizeOf(Hook) > 0) struct { int: I, hook: Hook } else { struct { int: I } };
<DutchGh0st>
'cuz a 0 sized type is nothing after compilation anyway
<andrewrk>
with llvm 8.0.0rc3 tagged yesterday, I am happy to announce all zig tests passing in llvm8 branch
<andrewrk>
when this branch is merged into master, web assembly goes from tier 4 to tier 3
<scientes>
sweet
<scientes>
that is a place where zig could really have an edge too
<DutchGh0st>
how should std.meta's hasFn be used?
<DutchGh0st>
does it only look at a function's name?
shawn_ has joined #zig
darithorn has quit [Remote host closed the connection]
scientes has quit [Ping timeout: 258 seconds]
<DutchGh0st>
oh, my function I was checking for was not pub ._.
shawn_ is now known as scientes
<tgschultz>
yeah, it looks for functions by name that are pub. Reasoning was that non-pub functions probably couldn't be called by whatever was inspecting anyway.
<DutchGh0st>
huh, its kind of interesting how this is working out
<WilhelmVonWeiner>
...what is a group of Zig programmers called?
<andrewrk>
off topic
<WilhelmVonWeiner>
my momma would whoop my ass if I called a group of anyone "ziggers"...
<WilhelmVonWeiner>
Also while it's being ported to OpenBSD I spun up an Ubuntu box to try the language out
<WilhelmVonWeiner>
I work with an ISP doing VoIP (SIP) stuff and Python scripts are great and all but a robust compiled language would be better
<WilhelmVonWeiner>
Are there any plans to implement associative arrays as a language feature?
<andrewrk>
WilhelmVonWeiner, it's planned to never do that
<WilhelmVonWeiner>
Lol.
<andrewrk>
associative arrays are firmly in userland territory
<WilhelmVonWeiner>
that's cool
<hg>
mmmmmmmmmmmmmmmmmmmmassociativearrays
<hg>
WilhelmVonWeiner: ziggies!
<tgschultz>
this is a bit off topic, but is anyone aware of a comprehensive list of actively maintained llvm targets?
<andrewrk>
tgschultz, is that different than the list of default targets that llvm builds?
<andrewrk>
btw as of ade10387a5, `zig targets` will only show architectures that are compiled into LLVM
<tgschultz>
I think so? I've found a few scattered github projects for architectures that aren't part of normal llvm's target list. Like dcpu-16 and z80.
<andrewrk>
live coding stream starting in 5 minutes - implementing GeneralPurposeDebugAllocator, part 2: https://www.twitch.tv/andrewrok
<andrewrk>
tgschultz, I see, so that would include third party projects that are not in llvm mainline
<andrewrk>
I think the successful, well maintained ones usually end up getting merged upstream into llvm
<andrewrk>
I'll be back after the stream
<tgschultz>
that makes sense. too bad though. What I'm really looking for is a simple VM target. A non-physical architecture. Like, I dunno, CHIP8 only not so simple.