/dpt/ daily programming thread - Rust edition

What are you working on /g?

Old thread:

Attached: Kinsey-Male.jpg (256x388, 18K)

Other urls found in this thread:

lmgtfy.com/?q=scanf("%[^\n]"
willowtreeapps.com/ideas/a-look-into-kotlin-native
automatetheboringstuff.com/chapter0/
twitter.com/AnonBabble

>edition
>making a new thread before the old one hits page 10

>> Not using the Catalog.

I love and hate C++ in equal measures.

waiting for a trivial coding challenge where I can post some shitty code as a form of escapism from the consequences of the suboptimal (understatement of the year) handling of my life
thus perpetuating the cycle, of course
folks, teach your kids the skill of discipline

>kinsey quackery
does that have anything on traps and programming socks?

In 1948, 37% of males had had at least one homosexual experience. Today the number is closer to 3%.

I blame traps for making gay sex not gay.

>In 1948, 37% of males had had at least one homosexual experience
[citation needed]

Why does a pthread return a void*?

Why can't you just return a value through the void* parameter?

The book in the OP.

>falling for the gay agenda
ayy shiggy

>In 1948, 37% of males had had at least one homosexual experience
I don't buy it. WW2 didn't have that many sailors.

Sooo... Rust edition?

Attached: rust-logo-512x512.png (512x512, 84K)

In C++...

Reading from a text file with ifstream. I'm reading an entire line at a time. Every time I read an entire line, I want to return the position of the beginning of the next line so I can later output to that position using seekp(). How do I get this position?

int *arr = new int[10];
delete arr;

People actually use this language without a hint of irony.

Attached: dr.jpg (1400x933, 258K)

>flooding the catalog with garbage

array/pointer """equivalency""" was a mistake

Array pointer equivalency is just fact. No amount of construction you do will be able to mask this point.

> VOID WHERE PROHIBITED. The Contest is void in Crimea, North Korea, Syria, Quebec, and where prohibited by law.

Why the fuck is google codejam voided in Quebec?

>> No amount of construction
KYS for making that pun.

Attached: 3 billion devices.png (827x510, 177K)

Pointers and arrays are distinct and trying to confuse the two concepts has done far more harm than good.

..on the doorstep of the amazign Dennis Ritchie programming adventure...

Attached: Screenshot_2018-04-07_23-59-57.png (3840x1080, 314K)

>3 billion devices
>only 40000 jobs
how do they do it???

Attached: 1522330986513.jpg (400x379, 41K)

>not teaching you about gates and _start
a shit.

HQ poo is cloned after production.
Of course, HQ is relative in this context.

I want to roleplay as Dennis Ritchie with my boyfriend roleplaying as Brian Kernighan while I'm developing a toy language.

and I mean an extended sexual roleplay, just to be clear (trying to and succeeding in fucking me while I'm programming on the bed)

that's like 75000 programs per pajeet

barking up the wrong tree in this day and age.
Applications in the wild written here and now are written in languages where pointers don't exist as a feature of the language.

It's a pity.

That is like 75000 poor devices suffering from poo from one pajeet.

C# has pointers and unsafe.

C# totally has refs out the ass, but you can't tell me that people actually use the unsafe context that frequently

Fuck you racist fucks. I know all Indians are not good programmers , but what do you expect, we do the dirty work, enterprise software etc.. where real programming is not always a requirement, where some of us have to wade through legacy applications to find data that some large corporation needs, instead of fizzbuzzing.
And there are programmers here though, a lot of them, Bangalore has a lot of startups , and a lot of people who are interested in programming beyond just a job.

t - NEET pajeet lisp weenie.

>ceos of major it companies are indians
>hurr durr pajeets

Wouldn't it be easier to FFI to a language where that shit comes naturally like C?

Oh shit a brown wave is coming
Bring out the walls

Attached: i4oYqFy.jpg (600x446, 104K)

poo in loo

You too m8.

>C++ was a mistake
Agreed.

Trying to duct tape features onto a language posthoc rarely works. C++ would have been better if it never had the pretense of backward compatibility, but then it also would never have caught on.

ref doesn't require unsafe and soon so will many stack related allocations and interop.
The .NET team is working on bringing the perf gain of such features without the unsafe context.
Span is a stack only collection and Memory is on the heap but is a Stack factory meaning we can interop more easily with languages that support pointers without any extra shit and flags.
We already have Intptr type (for handles) which also doesn't require unsafe conext

You can return a value. That's the point. The void* lets you return whatever you like.

I don't see why I wouldn't just use the thread's void* parameter to do that.

open 2 ifstreams of the file, make 1 be 1 line ahead of the other

It would be annoying having to keep that argument around because the thread creation and thread joining is probably not gonna be in the same scope/function.
Having a return value is cheap and simple, why not have it?
Though, intptr_t would probably have been a better return type because you mostly just care about some integer return code.

>Trying to duct tape features onto a language posthoc rarely works
>C++ was an awful idea
Agreed.

Do you really need a book about a male's sexual behavior

>show tits, ass, or both
>dick goes up

There. Saved you 300+ pages of reading.

You can. The "intent" is to use the parameter as initial data and the return value as returning data. Although modern style dictates that returning pointers is in bad taste for ownership or something reasons. Perhaps an alternate
"modern" design would be to have two void parameter inputs and an int return for error codes.

>tits
yuck

>women
yikes

I guess you can just just cast the void* back to an intptr_t like said.

fags

>dick
yum

Does anybody know the syntax for getting all displays in monogame?

Google is not giving me the results i'm looking for.

because your conditionals are assignments

also
>for j

Oh right
It says the very first line is an error though.

no it doesn't

This is valid:
(for-each . ((lambda . ((e . ()) . ((display . ((cond . (((= . (0 . ((modulo . (e . (15 . ()))) . ()))) . ("FizzBuzz" . ())) . (((= . (0 . ((modulo . (e . (3 . ()))) . ()))) . ("Fizz" . ())) . (((= . (0 . ((modulo . (e . (5 . ()))) . ()))) . ("Buzz" . ())) . (( else . (e . ())) . ()))))) . ())) . ((newline . ()) . ())))) . ((iota . (100 . (1 . ()))) . ())))

works on my machine
paste a complete example - the two lines you enter, and it complaining about the second one (alladd=0) being an error

you forgot your last conditional

I'm trying to work on a program which emulates the Taylor method of calculating exponential functions and I am completely fucking stuck.
Essentially, we are supposed to do this.
1 + ((1 / 1!) * x^1) + ((1 / 2!) * x^2) + ...
And in the program, we are supposed to let it run like this in a loop until the number that is calculated falls in a tolerance that the user sets, such as 0.0001 or 0.001.
I can't fucking figure it out and it pisses me off. Can anyone help me?

Post the code you have made as a try. We're not here to do your homework, just to explain things and point out your bad choice of programming language.

>def function (top):
alladd=0
j=0
while j i%3==0 || i%5==0}

Also,
- you can factor your j++ out of the if/else tree, as you do it in all branches
- you can collapse the remainder to an if (divisible by 3 or divisible by 5)

>if j=top:
oh, and that's
- incorrect (an assignment)
- redundant, as j will always be equal to top at that point of execution

Understood. Here is what I have so far.
import java.util.Scanner;
public class DoTheExponential {

public static void main(String[] args) {
Scanner scnr = new Scanner (System.in);
int i;
int n;
int timesLooped = 0;
double expCal = 0;
double userInput;
double userTolerance;
userInput = scnr.nextDouble();
userTolerance = scnr.nextDouble();
double trueAnswer = Math.exp(userInput);
double Answer = 0;
i = 0;
n = 0;
double x = userInput;
while (Math.abs(Answer - trueAnswer) > userTolerance) {
n++;
i++;
double tempFact = i;
while (i > 0) {
i--;
tempFact *= i;
System.out.print(tempFact + " ");
}
Answer = tempFact;

}
System.out.println(Answer + " " + trueAnswer);


}

}

lads. I need some help. I want to create a chromatic aberration effect. I am using the Pillow library for Python and you are easily able to get specific RGB bands. What would be the best way to do this? For example, shift the red bands to the left and then combine all the bands back together

Why can't javalets be normal..

Ba-weem ba-weh ba-weem ba-weh, ba-weem ba-weh ba-weem ba-weh, ba-weem ba-weh ba-weem ba-weh, ba-weem ba-weh ba-weem ba-weh

I am three months into learning this. I'm sorry.

Now I'm not familiar with the Taylor method, but I do see you got some stuff missing from the formula you gave in the code. But first, fix that mess of code. Make it simple, as if you're writing a story or explaining the method to someone.

Genuinely delete this

user have you covered functions yet? Honest question. You should have factorial be its own function. Actually, you should have an nthterm function too.

No, we haven't. I haven't learned much, seeing that the way I am learning is through Zybooks and using an online course. I hate this, user.

>You should have factorial be its own function. Actually, you should have an nthterm function too.
Not sure if I agree.
Regardless, some shit code that fails to handle too small tolerances:
def taylor(x: Double, tolerance: Double) = {
val trueAnswer = math.exp(x)
var estimate = 1.0
def goodEnough = math.abs(trueAnswer - estimate) < tolerance

var fact = 1.0
var factLast = 1
var pow = 1.0

def improve = {
fact *= factLast
factLast += 1
pow *= x
estimate += (1/fact)*pow
}

while (!goodEnough) improve
estimate
}

> for(p

Ok. Then I'll help you out a little bit:

import java.util.Scanner;
public class DoTheExponential {
//n!
public int fact(int n) {
int ret = 1;
//write code here
return ret;
}
//x^n
public int expt(int x, int n) {
int ret = 1;
//do code here
return ret;
}
//(x^n)/(n!)
public int term(int x, int n) {
int ret = 1;
//do code here
return ret;
}
public static void main(String[] args) {
Scanner scnr = new Scanner (System.in);
int n = 0;
double userInput;
double userTolerance;
userInput = scnr.nextDouble();
userTolerance = scnr.nextDouble();
double trueAnswer = Math.exp(userInput);
double Answer = 0;
while (Math.abs(Answer - trueAnswer) > userTolerance) {
//do code here
n++;
}
}
}

It makes things way way easier to write when you divide the code into functions like this, especially since you can test individual pieces.

>ashamed of anonymously posted code
shiggy

>makes things way way easier to write when you divide the code into functions like this, especially since you can test individual pieces.
with the important caveat that you'll be going from O(n) to O(n^2) (n=number of estimation refinement rounds) if you don't compensate with e.g. memoization.

what language is this

Attached: CAQi-bOUwAAUPQ3.jpg (768x1024, 92K)

the heck is [^\n]
scanf("%[^\n]", input_string);
It reads input stores it in an array, then adds a new line after everything? what's the '^'?

literally the first result
lmgtfy.com/?q=scanf("%[^\n]"
hint for the audience: regaxx

Anyone tried out kotlin native?
willowtreeapps.com/ideas/a-look-into-kotlin-native

[...] means the set of characters in the square brackets, e.g. [xy] means x's or y'z, [a-z] means lowercaes letters, [ 0-9] means numbers or spaces.

^ means compliment, so it gets everything that isn't a newline character

Well of course, taylor series can have slow convergence. But more sinisterly, it's possible to define a tolerance tighter than what's possible due to floats having finer granularity near zero.

>Not sure if I agree
You've already thrown performance away with python. besides it's trivial to memoize.

>more sinisterly, it's possible to define a tolerance tighter than what's possible due to floats having finer granularity near zero.
Yup, that's the one I was thinking about when I mentioned the newton method stuff.
Likewise, the same issue can happen at very large values due.
There was a trivial solution, but I can't be arsed to think about it atm.
>python
?
>it's trivial to memoize.
obviously. However, your post might mislead our clueless friend to think that there's no trade-offs to switching to the (obviously easier to write and more readable) function-oriented approach.

How do I make a text editor

apt-get source ed

You build a nice GUI and make the buttons execute some code. Depends on the language what the exact implementation looks like.

Any language can look ugly if you try hard enough

main(i, u) int i; char const const const const const* u[-~-+1]; {
for (i = 1; !!!!(i - 101); i = + - (- + 1 + - + - + - i)) {
if (i%3&&i%5&&(printf("%d\n", i), -5));
else if (i%5) {{{{{{;;puts("fizz");;;}}}}}}
else if (i%3) (*&*&*&puts)("buzz");
else fwrite("fizzbuzz\n", -~0, 0x8320 - 0101427, stdout);
}
}

Don't forget to take 100% of one core to blink the cursor. Or was it 60%?

Why do you want to make a text editor?

#.(loop for i from 1 to 100 do
(format t "~:[~:[~a~;Buzz~]~;Fizz~:[~;Buzz~]~]~%~@*" (= 0 (mod i 3)) (= 0 (mod i 5)) i))

Because I suck at coding or as I like to call it 'gramming

I wanna learn to 'gram

...

>wanna learn to 'gram
automatetheboringstuff.com/chapter0/
get crackin'

Don't be picking on the beginner

What language do you want to use?

A language to make an editor in! I want it to be as good as emacs

>web apps are the future guise

Attached: Screenshot_2018-04-08-01-48-01-350_com.android.chrome.png (1080x1920, 388K)