/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

asciitable.com/
boats.gitlab.io/blog/post/2017-11-16-announcing-failure/
twitter.com/NSFWRedditVideo

c...cute >

never watched anime

t. c++ programmer

>bjarne stroustrup
>agner fog
Tell me about danes, why do they write the C++?

Reposting here because:
Okay, so I have a list like this:
[0, 60, 2, 30, 4, ..., 50, 5]
0 is my starting point and 5 is my destination.
Every odd element in the list is the distance between two points. In this list, for example, 60 is the distance between point 0 and point 2.

Let's say that I want to go from point 0 to point 5 and that I have a starting fuel of "100". My fuel diminishes through each passage between points, but in *some* points I can refuel to 100 again.
The problem is: how can I know which points I can avoid refueling and still go from 0 to 5?

If the list is long this can be tricky to do, and I still haven't formulated a solution for this.

Yes, I'm allowed to see the contents of the list beforehad.

Just some Fortran

! Determine the nature of a cubic equation by
! returning an integer value of:
! 1: three distinct real roots
! 2: multiple root and all roots are real
! 3: 1 real root, 2 non-real complex conjugate roots
INTEGER FUNCTION CubicEq_get_type(a, b, c, d)
IMPLICIT NONE
INTEGER, INTENT(IN) :: a, b, c, d
INTEGER :: discriminant
INTEGER :: eq_type

discriminant = 18 * a * b * c * d &
- 4 * b**3 * d &
+ b**2 * c**2 &
- 4 * a * c**3 &
- 27 * a**2 * d**2

IF (discriminant > 0) THEN
eq_type = 1
ELSE IF (discriminant < 0) THEN
eq_type = 3
ELSE
eq_type = 2
END IF

CubicEq_get_type = eq_type

END FUNCTION CubicEq_get_type

that's the only permissible way to express toxic masculinity

anime website

Sure it helped, thanks. I guess my brain is kinda fried right now because this is literally the final part of a problem I needed to solve, so I spent the whole day in front of my computer.

Autonomous drone for exterminating traps.

Are you retarded? C++ is not JIT compiled.

>Thing is that GC and MMM are only conflicting when you manage memory yourself. MMM relies on you as the programmer being able to determine where memory is. If everything is immutable, you have been promised a GC from the compiler and the code is pure then unless I'm missing something the compiler is given next to complete freedom in organizing data. So it can do a good job.
GC has a runtime cost. That is the core of the problem.
>When you said GHC is a great compiler and haskell is crap for optimizing.
Wasn't me.

>C++ is not JIT compiled.
Just like Java.

Here's a minimal heap allocated Box implementation.
struct Box(T: Type) { ^T }

impl[T] Box(T) {
fn new(x: T) -> Self {
unsafe {
let p = heap::alloc();
*p = x;
struct p
}
}

fn unbox(self) -> T {
let struct p = self;
unsafe {
let x = *p;
heap::free(p);
x
}
}

fn deref[P, Q](P^self) -> Q^T | self: P^Box(Q!T) {
unsafe {
&*self.0
}
}
}

impl[T: Drop] Box(T) {
fn drop(self) {
self.unbox();
}
}

The signature of deref might look a little magical, so I'll try to demystify it.
fn deref[P, Q](P^self) -> Q^T | self: P^Box(Q!T)

A coarser version of this signature that is closer to what Rust requires could look like this.
fn deref[P](P^self) -> P^T

The extra region Q is what allows you to borrow the contents of the box without borrowing the entire box. To allow this, the refinement self: P^Box(Q!T) declares that the contents of the box are borrowed in Q, changing the type of the box inside Q. P and Q themselves are unrelated, so you can unborrow the box itself while its contents are borrowed, but due to the borrowed type Q!T you still cannot drop the box until unborrowing its contents.

You will also notice that the Drop implementation reqiures T: Drop. However, the rest of the implementation doesn't ever try to drop a T, so it's not needed there.

>exterminating traps
are you saying you're not a real programmer?

programmer != trap
kys

I still can't believe someone made a show about internalized sexual harassment and labeled it a comedy.

What's the easiest way (if there's one) to make a fake google review bot?
I want to fuck up a company review throughout my country for their shit service and customer support, it's at almost 5 stars right now because the only people rating are it's own employees, whenever customers are rating, it's a guarantee 1 star and comments shitting on them.
What made me choose them in the first place were the ratings at first glance.

I'm a decent programmer, just wanted to know the best way to go about this. I think creating fake google accounts would be the biggest issue.

Rust's Deref trait can also be refined to allow this more fine grained borrowing.
trait Deref {
type Target;
type Borrowed(Region);

fn deref[P, Q](P^self) -> Q^Target | self: P^Borrowed(Q);
}

impl[T] Deref for Box(T) {
type Target = T;
type Borrowed(P) = Box(P!T);

fn deref(_^self) -> _ {
unsafe {
&*self.0
}
}
}

Because I'm allowing parameter/return types to be omitted when implementing a trait, the complicated borrow machinery is abstracted away.

>brogrammer != trap
ftfy

>I'm a decent programmer, just wanted to know the best way to go about this.

Then you'd know that most of those review farms are using phished accounts

>all this monkeying around with worthless shit
do you ever get anything done, brainlets?

I just came across this horribly unidiomatic piece of Julia code.

Scheme users, please explain this code to me. You understand continuations better than I do.

#Call current continuation implementation. May or may not leak tasks.
function callcc(f)
ct = current_task()
cc = ((x)->yieldto(ct,x))
t = Task(()->yieldto(ct,f(cc)))
yieldto(t)
end

function f(ret)
ret(2)
3
end

# f(identity) returns 3
# callcc(f) returns 2

function genind(lst)
function controlstate(ret)
foreach(lst) do element
ret = callcc() do resumehere
controlstate = resumehere
ret(element)
end
end
ret("fin")
end

mygenerator() = callcc(controlstate)

mygenerator
end
[\code]

Do you use dependency injection Sup Forums?

>dependency injection
>not implicit arguments

Write var=0 /n if fuel

>GC has a runtime cost
MMM does too. A compiler could make portions of the applications used memory be static and not included in the GC collection. It could put in allocs and frees wherever it feels.
There's no reason a compiler can't do the work of a human. Sometimes there's domain knowledge that does go into it and provide massive gains. And I do prefer languages that let you specify that knowledge. But when you consider a broad spectrum of languages I don't see haskell and GHC being in a bad spot. Assuming what you mentioned is the only potential problems (ignoring lazy eval, I haven't read about it yet). Which is probably not the case.
>wasn't me
Well excuse my confusion.

>implicit dependencies
t. brainlet

The dependencies are explicit. Satisfying the dependencies is not.

Also loop it with while var > list(len)

It's creating a spigot function which returns each element of a list every time you call it. So if you pass in (1 2 3) it's returning a function say, retarded. And when you call retarded, it returns 1. Then when you call retarded again, it returns 2. And then 3. And finally, "fin". At least that's what I think it's doing. That syntax is fucking awful. t. someone who has become one with the ))))

>doubles are a subset of integers
the absolute state of Sup Forums

should 3 sigma bounds be symmetric about the mean?

What's the original post this spicy meme came from?

trap == faggot == (You)

You can't just create a bunch of accounts and shit on a company. Spam filtering systems easily detect when a bunch of new accounts have zero activity except for a single negative review of a business.

So working on a little animation where i have a sequence of integers(a one dimen table) ,+ve or -ve,when +ve that number of images have to move from the left to the middle of the screen and dissapear when there then after dissapearing continue like that until the sequence is ended also there are cases of simulteneous mv't ( in and out at the same time)
most of this is finished but but idk why i have this feeling that i could write a better algorithm even though i don't have any precise one in mind (using java in btw)

Integers are a subset of doubles.
t. JavaScript

Anything is anything if i want it to be
t. Javascript

FORTRAN 77 > modern gay Fortran

1+undefined = undefined
'1' + 1 = '11'
t. javascript

That's at least understandable. What's really stupid is [1, 2, 10].sort() // => [1, 10, 2]

>download repo from github
>make some nice changes to it
>have no idea how to build it
>tried literally every guide available
>most of them are outdated from 2013
HOW DO I COMPILE KDE PLASMA GOD FUCKING DAMNIT

I haven't programmed in like 9 months. What kind of program should I work on to ease my back into it?

dude weak typing lmao

>change thing before she got a build going
Hah. Better luck next time user.
Welcome to open source.

What is the twisted logic behind this?

1

It converts them to strings and does a lexicographic sort.

sort is for strings.
1 comes before 2.

>1 comes before 2
Source?

>It converts them to strings
>sort is for strings.
Fucking WHY?

because javascript and weak typing

auto arr = ["3", "1" ,"2"];
arr.sort.writeln; // -> ["1","2","3"]

asciitable.com/

But why even bother converting all of them? Surely the sort function can just use < or whatever internally and have type mismatches resolved on the fly.

For

>Surely the sort function can just use < or whatever internally
Nope, that's up to you
var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a - b});

What a worthless choice of default behaviour.

JS was designed in 10 days.

that's what happens when you use a dynamic trash.

monads solved error checking

somebody explain to me how this could ever crash? it's literally impossible

ptr is uninitialized, not zero.

Now we just need to solve monads.

doesn't it take more effort to make a language with weak typing than it does strong typing?
why the fuck is weak typing even a thing?

no dependent types did.

So uni's can fulfill their secret contracts and churn out brainlet """""""""""programmers""""""""""".

I think you're confusing weak/strong with dynamic/static

either way, weak typing a shit

Weak (and dynamic) typing is easier on the programmer. It facilitates lazy devs, which is most of them.

What's even worse is even if it's null, you can still do ops on it.

>easier on the dev
90% of the bugs i encounter in my JS code are caused by weak typing, and what is worse, these are not bugs that stop the code and raise an exception. these are bugs that run just fine but give me some bullshit answer and nothing to help me debug without inserting a bunch of console.log()s everywhere.

Where were when a rust-dev announcend failure for rust? boats.gitlab.io/blog/post/2017-11-16-announcing-failure/

Give a real list example.

>needing a library for error handling
Rust is 1 step forward and 37 steps back.

It doesn't, this in particular is for coalescing errors of multiple types in a better way than Box.

>Box
what absolute trash.
If only Rust had actually good templates/generics.

Let me explain. In a strongly statically typed language the typical development process is:
>write some code
>fix logic errors
>ship a relatively solid product

With dynamic languages it's:
>write some code
>shit is broken
>try things until it "seems" to work
>ship a barely-working clusterfuck with tons of edge cases
>receive paycheck
>leave the maintenance to some other poor soul

If you don't care about quality, dynamic typing is faster.

Box is literally just Rusts unique_ptr

It does. How else do you expect to store a value of arbitrary (existential) type?

Any license that requires upstream patches?

what should my last program be before i an hero

FizzBuzz, naturally

Optimal noose knot

A program that takes a program as input and determines whether it will terminate.

what language will make me more confident by compensating for my lack of discipline?

lol is this from the other thread?
if x is NULL *x will dereference an invalid pointer, and in the best case it will segfault
worst case itll just fail silently, and things wont work but you wont know why/what is happening

Unironically, Rust

>How else do you expect to store a value of arbitrary (existential) type?
What's even a usecase for Box over a generic function?

why do you think thats worse? if x is NULL, and you have another valid pointer, lets call it ptr, you could do x += ptr which is a valid operation

Because in my opinion it should be a compiler error/ type mismatch.

He's testing whether it's null. The crash is from the pointer being uninitialized and thus electric static.

Efficiency purposes, I guess. Theoretically you should be able to do something like Box T> but Rust doesn't have higher rank type polymorphism (only higher rank lifetime polymorphism).

anything with a GC and strong static typing.

>by compensating for my lack of discipline?
literally any decent pure functional language will tell you to fuck off if you get lazy. And some will even help you with type annotations if you're a brainlet.

I have 3 unit vectors and 3 transformed vectors, how do i get the transformation matrix back? I know i have to take the dot product of a vector and a transformation matrix to get the transformed vector but how do i do it in reverse?

Returning a closure for example, though with impl Trait that will not be necessary:
#![feature(conservative_impl_trait)]

fn foo() -> Box char> {
Box::new(|x| 'a')
}

//Nightly only currently
fn bar() -> impl Fn(i64) -> char {
|x| 'a'
}

oh youre right! i didnt look at the code above, my bad!

returning a generic closure?
Also what's the |x| syntax mean?

What language?

I can whip up an answer in haskell if thats acceptable?

so youre saying pointer arithmetic is bad? what would you do without it?

It was both in C and Java, but I've already solved it, thanks.