1 post by this id. on boards like LULZ, /int/, and MISC every IP gets a poster id in each thread so people in the thread know who is who while staying anonymous
when you mouse over the ID it tells you how many posts this ID has in the thread, and often threads like this one, the OP has only made one post (the thread opener)
It would be a decent heuristic for a shit thread, but >newfags think it means "1 post by this IP on the whole board" (i.e. its someone using a VPN to spam threads while ban evading) >people just say it <10 posts into the thread before OP even has a reason to post respond to any of the posters
for is the ultimate based construct. I've recently stopped using while's, as they're simply redundant. Also, it's so awesome when you can solve a whole loop with an empty for body.
While, really, should be considered harmful, as it's hardly more than a goto. A for on the other hand has a philosophical aspect to it: what is a loop? Initiation, evolution, and conclusion. It really is the recursion of imperative programming
interesting take. For most cases I would need a while loop I end up just using an empty for loop and a break statement. I've seen some devs even do this:
Anon, nothing in his post implied making a computer detect infinite loops. The problem lies with using terminology to suggest that the program unconditionally will loop forever, while introducing logic that could make it not loop forever. It is essentially a while loop, written with the syntax of an infinite loop.
Iterators are not loops.
Iterators process items from collection-like types using a variety of high-level declarative functions, among them conditions (ex: filter, take_while), operations (ex: reverse, step_by), transformations (ex: map, flatten) and conversion (ex: collect, sum).
They're much more powerful as a concept, more readable and result in less buggy code.
That's not always true. You can't, for example, "return a loop" from a function so it can be further processed somewhere else. Usually what happens is you end up allocating a new array or whatever and return that. The closest would be to return a closure or have a function that takes a closure with which you do your thing. Iterators also allow you to think in terms of a pipelines, where each step is expressed in a declarative way using high-level concepts instead of manually written code. Example:
arr.iter()
.skip(arr.length() / 2)
.rev()
.step_by(2)
.take_while(|x| x > 64)
.sum();
This skips over half the array, reverses it, processes every second item while the item is > 64 and finally adds them together. It's super explicit in what it does and it's barely even code. Yes, this example you can replace with a 3 lines for loop, but it won't express the intent as clearly. That would have to be derived from how you set up the loop and what the body does, whereas with iterators you get a simple pipeline of conditions (take_while), operations (rev, skip, step_by) and transformations (sum). That's why it's more powerful (in the sense of expressiveness).
3 weeks ago
Anonymous
>You can't, for example, "return a loop" from a function so it can be further processed somewhere else.
But you're not returning a loop. The loop is in the terminal stage (collect, sum, whatever). Everything before that is just about constructing a generator/stream.
3 weeks ago
Anonymous
Remove the sum at the end and that chain of calls will return an iterator. Which can be returned from a function back to the caller, who then might do whatever else on top, including using it in a for loop. That wasn't really the point I wanted to illustrate, but it's as easy as this:
fn test() -> impl Iterator {
let arr = &[0, 2, 4, 8, 16, 32, 64, 128, 256, 512];
return arr.iter()
.skip(arr.len() / 2)
.rev()
.step_by(2)
.take_while(|x| **x > 64)
}
3 weeks ago
Anonymous
>Iterators also allow you to think in terms of a pipelines
Rust iterators don't allow you to separate the pipeline from the source though. It's more like a stream than a pipeline.
On the other hand:
void do_needful(auto needful) {
for (auto x : iota(-5, 5) | needful) {
cout << x << ',';
}
cout << 'n';
}
>Rust iterators don't allow you to separate the pipeline from the source though
What do you mean? That's just different syntax for the same thing. If you return an iterator like in
Remove the sum at the end and that chain of calls will return an iterator. Which can be returned from a function back to the caller, who then might do whatever else on top, including using it in a for loop. That wasn't really the point I wanted to illustrate, but it's as easy as this:
fn test() -> impl Iterator {
let arr = &[0, 2, 4, 8, 16, 32, 64, 128, 256, 512];
return arr.iter()
.skip(arr.len() / 2)
.rev()
.step_by(2)
.take_while(|x| **x > 64)
}
you can do whatever you want on top.
Example:
fn test() -> impl Iterator<Item = u32> {
let arr = &[0, 2, 4, 8, 16, 32, 64, 128, 256, 512];
return arr.iter()
.skip(arr.len() / 2)
.rev()
.step_by(2)
.take_while(|x| **x > 64)
.cloned()
}
fn callit() {
let iter = test();
let squared = square(iter);
let filtered = filter_less_than(squared, 2);
}
I hard-coded the type for brevity, I could have used a generic, but then the type constraints would distract from the gist of it. Rust doesn't really do cross-function type inference.
3 weeks ago
Anonymous
You can pass around an iterator, but you can't pass around a pipeline that only contains operations.
3 weeks ago
Anonymous
You can, but it requires boxing and dynamic dispatch if you want to pass fully generic pipelines (with respect to the iterator, not the type) around:
type Iter = Box<dyn Iterator<Item = u32>>;
fn op(iter: Iter) -> Iter {
Box::new(iter.map(|x| x * x)
.filter(|x| *x < 2))
}
fn usepipe() {
let arr: [u32; 3] = [1, 2, 3];
let pipe = pipe();
pipe(Box::new(arr.iter().cloned(*~~;
}
I'm not sure how it works in C++. do_needful doesn't even return anything which seems weird.
2 weeks ago
Anonymous
>arr.iter() > .skip(arr.length() / 2) > .rev() > .step_by(2) > .take_while(|x| x > 64) > .sum();
not what I was referring to
https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
It's equivalent to an iterator expression like this
for () in iter::repeat(()) {
// something
}
sure, but are rust infinite loop actually implemented that way? probably not.
2 weeks ago
Anonymous
Rust iterators have a repeat method.
[0, 1, 2].iter().repeat().for_each(|x| println!("{}", x);
And "loop" does not use iterators, what's your point? Of course Rust has loops. You can even turn iterators into for loops. Doesn't mern they're theksrme thing.
c is reponsible for all the worlds problems
c programmers (ponytails) and C
all of the worlds problems. all of them, have been caused by C programmers.
That's because the C for loop consists of both the pre and postcondition, and keeps them all in the same spot. If you're doing imperative programmimg this is how your control flow should be done
A for loop is syntactical sugar for a while loop with a counter variable.
You can do everything a for loop can in a while loop (not saying you should).
true but it really comes down to a matter of effort. Do you want to put in the time to manually keep track of a bunch of counters and increments or do you just want to let the compiler do it for you...of course there are cases where speed concerns or size constraints come into play
>doesn't consume namespace with variables declared in it >ensures you don't forget iteration step >functionally the same as while
There is no reason not to like the for loop. Should it be used for everything? No but that doesn't mean it doesn't have it uses.
reminder
if you're post 30 and are browsing LULZ for hints/tips/buzzwords to impress ppl. and are looking again to mebbe start to learn programming cos ur crap sales type job is finished or too hard or you've finally realised you'll never get real money
you'll never be able to do it ever. you are finished. it is too late.
>but I can’t really tell what magic allows it to print to STDOUT
RSI is the address of a print, RDX is the length of the string, RAX or RDI is the print syscall and the other is a format specifier. what syscall is being called is implementation defined
>I can’t really tell what magic allows it to print to STDOUT
It's the write() system call, which is what lies underneath all sorts of print() calls in the standard library. That takes a file descriptor number as its first argument (probably in RDI), and 1 is the standard file descriptor number for stdout.
SYSCALL just calls kernel functions like write in this case. AX contains the number of the function, DI contains the file descriptor (as this calls write, see man 2 write), SI contains the buffer from where it writes to the file descriptor provided, DX contains the count of bytes to write. Linux returns a value in AX which is why it has to be set to 1 (to write again) afterwards. If you are interested you can read about the AMD64 architecture from AMD's or Intel's programmer's manuals, here is a link to AMD's programmer's manuals because Intel's are always a pain in the ass to find. https://developer.amd.com/resources/developer-guides-manuals/
For loops are harder than while loops
You have to think ahead of time how much you want it to loop before you've written the innards. With while you just set an end condition
>inb4 recursion >inb4 list comprehensions or some other language specific construct which is essentially just syntactic sugar for the Nyulund nightmare
[log in to view media]
>makes outlandish claim
>does not elaborate
>1pbtid
based
What does 1pbtid stand for?
[log in to view media]
>1pbtid
You seem new. So, can you and I be fwends? Pweeze?
No way, fag
hey i like that picture can i borrow it?
1 post by this id. on boards like LULZ, /int/, and MISC every IP gets a poster id in each thread so people in the thread know who is who while staying anonymous
when you mouse over the ID it tells you how many posts this ID has in the thread, and often threads like this one, the OP has only made one post (the thread opener)
Thanks.
We need this for LULZ. Have wanted it for years. It's so obvious the rust threads are created by one person who keeps bumping his own posts
If it's obvious then no, you don't need IP trackers, glowie.
should be site wide, /b/ would shit themselves if they saw how much spam was from one ip
The draw of /b/ IS that complete anonymity is enforced.
For EVERY other board on LULZ[nel], I agree with you though.
It would be a decent heuristic for a shit thread, but
>newfags think it means "1 post by this IP on the whole board" (i.e. its someone using a VPN to spam threads while ban evading)
>people just say it <10 posts into the thread before OP even has a reason to post respond to any of the posters
one penis boner thrusted in deep
giwtwm
>outlandish claim
Not at all
Open linux kernel, see for loops, see linked lists, shit on every "competent" dev and move along.
[log in to view media]
For a start, it would compile in GCC.
int a = 10;
loop:
if(a == 0)
goto breakloop;
/* ... */
a --;
goto loop;
breakloop: return;
Enjoy not having any compiler optimization.
for is the ultimate based construct. I've recently stopped using while's, as they're simply redundant. Also, it's so awesome when you can solve a whole loop with an empty for body.
While, really, should be considered harmful, as it's hardly more than a goto. A for on the other hand has a philosophical aspect to it: what is a loop? Initiation, evolution, and conclusion. It really is the recursion of imperative programming
interesting take. For most cases I would need a while loop I end up just using an empty for loop and a break statement. I've seen some devs even do this:
#define forever for(;;)
forever
{
// loops forever
if (breakout_case)
break;
}
>// loops forever
>doesn't actually loop forever
dishonest codemaking
im sorry
// fixes bug 1
#define forever for(;;) for(;;)
he doesnt know about the halting problem
get him!
Anon, nothing in his post implied making a computer detect infinite loops. The problem lies with using terminology to suggest that the program unconditionally will loop forever, while introducing logic that could make it not loop forever. It is essentially a while loop, written with the syntax of an infinite loop.
said anon made a positive statement that has a truth value. Its the halting problem.
just call it loop instead like rust
> needing a keyword for something like this
Iterators are not loops.
Iterators process items from collection-like types using a variety of high-level declarative functions, among them conditions (ex: filter, take_while), operations (ex: reverse, step_by), transformations (ex: map, flatten) and conversion (ex: collect, sum).
They're much more powerful as a concept, more readable and result in less buggy code.
>They're much more powerful as a concept
No. They're just an alternate way of expressing the same thing, with neither more nor less power.
That's not always true. You can't, for example, "return a loop" from a function so it can be further processed somewhere else. Usually what happens is you end up allocating a new array or whatever and return that. The closest would be to return a closure or have a function that takes a closure with which you do your thing. Iterators also allow you to think in terms of a pipelines, where each step is expressed in a declarative way using high-level concepts instead of manually written code. Example:
arr.iter()
.skip(arr.length() / 2)
.rev()
.step_by(2)
.take_while(|x| x > 64)
.sum();
This skips over half the array, reverses it, processes every second item while the item is > 64 and finally adds them together. It's super explicit in what it does and it's barely even code. Yes, this example you can replace with a 3 lines for loop, but it won't express the intent as clearly. That would have to be derived from how you set up the loop and what the body does, whereas with iterators you get a simple pipeline of conditions (take_while), operations (rev, skip, step_by) and transformations (sum). That's why it's more powerful (in the sense of expressiveness).
>You can't, for example, "return a loop" from a function so it can be further processed somewhere else.
But you're not returning a loop. The loop is in the terminal stage (collect, sum, whatever). Everything before that is just about constructing a generator/stream.
Remove the sum at the end and that chain of calls will return an iterator. Which can be returned from a function back to the caller, who then might do whatever else on top, including using it in a for loop. That wasn't really the point I wanted to illustrate, but it's as easy as this:
fn test() -> impl Iterator {
let arr = &[0, 2, 4, 8, 16, 32, 64, 128, 256, 512];
return arr.iter()
.skip(arr.len() / 2)
.rev()
.step_by(2)
.take_while(|x| **x > 64)
}
>Iterators also allow you to think in terms of a pipelines
Rust iterators don't allow you to separate the pipeline from the source though. It's more like a stream than a pipeline.
On the other hand:
void do_needful(auto needful) {
for (auto x : iota(-5, 5) | needful) {
cout << x << ',';
}
cout << 'n';
}
int main() {
do_needful(transform(square) | filter(less_than_2)); // 1,0,1
do_needful(filter(less_than_2) | transform(square)); // 25,16,9,4,1,0,1
}
>Rust iterators don't allow you to separate the pipeline from the source though
What do you mean? That's just different syntax for the same thing. If you return an iterator like in
you can do whatever you want on top.
Example:
fn test() -> impl Iterator<Item = u32> {
let arr = &[0, 2, 4, 8, 16, 32, 64, 128, 256, 512];
return arr.iter()
.skip(arr.len() / 2)
.rev()
.step_by(2)
.take_while(|x| **x > 64)
.cloned()
}
fn square(iter: impl Iterator<Item = u32>) -> impl Iterator<Item = u32> {
iter.map(|x| x*x)
}
fn filter_less_than(iter: impl Iterator<Item = u32>, n: u32) -> impl Iterator {
iter.filter(|x| x < n)
}
fn callit() {
let iter = test();
let squared = square(iter);
let filtered = filter_less_than(squared, 2);
}
I hard-coded the type for brevity, I could have used a generic, but then the type constraints would distract from the gist of it. Rust doesn't really do cross-function type inference.
You can pass around an iterator, but you can't pass around a pipeline that only contains operations.
You can, but it requires boxing and dynamic dispatch if you want to pass fully generic pipelines (with respect to the iterator, not the type) around:
type Iter = Box<dyn Iterator<Item = u32>>;
fn op(iter: Iter) -> Iter {
Box::new(iter.map(|x| x * x)
.filter(|x| *x < 2))
}
fn pipe() -> Box<dyn Fn(Iter) -> Iter> {
Box::new(|iter| op(iter))
}
fn usepipe() {
let arr: [u32; 3] = [1, 2, 3];
let pipe = pipe();
pipe(Box::new(arr.iter().cloned(*~~;
}
I'm not sure how it works in C++. do_needful doesn't even return anything which seems weird.
>arr.iter()
> .skip(arr.length() / 2)
> .rev()
> .step_by(2)
> .take_while(|x| x > 64)
> .sum();
not what I was referring to
https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
It's equivalent to an iterator expression like this
for () in iter::repeat(()) {
// something
}
sure, but are rust infinite loop actually implemented that way? probably not.
Rust iterators have a repeat method.
[0, 1, 2].iter().repeat().for_each(|x| println!("{}", x);
Dhis will run forever.
Rust literally has a "loop" keyword, moron
And "loop" does not use iterators, what's your point? Of course Rust has loops. You can even turn iterators into for loops. Doesn't mern they're theksrme thing.
start:
if (!breakout_case)
goto start;
holy cnile cope
use a real language if you want high-level iteration
you're aware that C++ implements container-based iteration, right?
of course he isn't. his brain has oxidized
That's because it is a while loop, dressed up in a Monty Python Ministry of Silly Walks style.
It should have a mandatory "while" keyword in it:
for (int i=0; while i<10; i++) {
}
and then get rid of the "for" keyword which does nothing and means nothing relevant in English and is some math in-joke wink reference like "let" is.
you should consider crying about it stupid homosexual
c is reponsible for all the worlds problems
c programmers (ponytails) and C
all of the worlds problems. all of them, have been caused by C programmers.
That's because the C for loop consists of both the pre and postcondition, and keeps them all in the same spot. If you're doing imperative programmimg this is how your control flow should be done
i get what you're saying but the rare problem exists where only a for loop can produce your solution
dont ask me to provide an example because i cant think of one
>You're wrong but I can't tell you why
You're wrong.
A for loop is syntactical sugar for a while loop with a counter variable.
You can do everything a for loop can in a while loop (not saying you should).
You literally only need if (not even else) and goto.
If you use any other construct, you're a terrible programmer.
Writing goto in any professional context will get you fired lol.
Complete myth that only nocoders believe.
goto is quite common in large C codebases since it's the most straightforward method to ensure that resources are released.
Real java chads use streams.
Thanks for your attention sirs.
true but it really comes down to a matter of effort. Do you want to put in the time to manually keep track of a bunch of counters and increments or do you just want to let the compiler do it for you...of course there are cases where speed concerns or size constraints come into play
>Only beginners and incompetent devs use this.
Only beginners and incompetent devs use C and languages with C-like syntax? Yes.
Imagine being filtered by syntax.
Yes, competent devs use LOOP.
>doesn't consume namespace with variables declared in it
>ensures you don't forget iteration step
>functionally the same as while
There is no reason not to like the for loop. Should it be used for everything? No but that doesn't mean it doesn't have it uses.
reminder
if you're post 30 and are browsing LULZ for hints/tips/buzzwords to impress ppl. and are looking again to mebbe start to learn programming cos ur crap sales type job is finished or too hard or you've finally realised you'll never get real money
you'll never be able to do it ever. you are finished. it is too late.
>shittiest bait ever to be seen
>30+ replies
Not an argument.
variables now considered harmful.
what's wrong with for loops? i use literally nothing else in my C code. not out of rebellion, but I just don't need other loops as often as for
>what's wrong with for loops?
Some people are filtered by them. Some people have a room temperature IQ.
global _start
section .data
n: db "n-word", 10, 0
i: equ $-n
section .text
_start:
MOV RDI, 1
MOV RSI, n
MOV RDX, i
MOV RAX, 1
n-word:
SYSCALL
MOV RAX, 1
JMP n-word
Did arm64 asm, not familiar with pcasm
Does SYSCALL call whatever’s in RDX? I’m assuming this prints n-word forever, but I can’t really tell what magic allows it to print to STDOUT
>but I can’t really tell what magic allows it to print to STDOUT
RSI is the address of a print, RDX is the length of the string, RAX or RDI is the print syscall and the other is a format specifier. what syscall is being called is implementation defined
>address of a print
address of a string, sorry, my ligma is acting up
>I can’t really tell what magic allows it to print to STDOUT
It's the write() system call, which is what lies underneath all sorts of print() calls in the standard library. That takes a file descriptor number as its first argument (probably in RDI), and 1 is the standard file descriptor number for stdout.
SYSCALL just calls kernel functions like write in this case. AX contains the number of the function, DI contains the file descriptor (as this calls write, see man 2 write), SI contains the buffer from where it writes to the file descriptor provided, DX contains the count of bytes to write. Linux returns a value in AX which is why it has to be set to 1 (to write again) afterwards. If you are interested you can read about the AMD64 architecture from AMD's or Intel's programmer's manuals, here is a link to AMD's programmer's manuals because Intel's are always a pain in the ass to find. https://developer.amd.com/resources/developer-guides-manuals/
Why not use stream sir?
For loops are harder than while loops
You have to think ahead of time how much you want it to loop before you've written the innards. With while you just set an end condition
i HATE curly brackets with a passion.
you need to leave LULZ and go back to mcdonalds.
They are annoying especially when the opening is on its own line. Click auto format and make people seeth.
goto
[log in to view media]
kek
>not using the superior
std::for_each()
>along with the gigachad lambda
[] () { }
that's the most stupid use for for_each
>today on "/g/tarded neet makes retard claim thus explaining why you're all jobless basement-dwellers"...
So whats the competent senior dev alternative?
>inb4 recursion
>inb4 list comprehensions or some other language specific construct which is essentially just syntactic sugar for the Nyulund nightmare
Iterators
This bait worked better than I expected, kudos.
Damn right that's a noop at best
You rarely need a naked loop
I use recursion instead.
[log in to view media]
Even more disgusting. Use while like a normal person.
You think that's for not f-or, don't you. I bet you don't know what the f stands for.