/dpt/ - Daily Python Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

dlang.org/d-array-article.html
dlang.org/phobos/std_range.html
stackoverflow.com/a/4597164
twitter.com/NSFWRedditImage

I just realized that i didn't actually need the angle brackets
fn is_symmetric(it: I) -> bool
where
I: IntoIterator,
I::Item: PartialEq,
I::IntoIter: DoubleEndedIterator,
{
let mut it = it.into_iter();
while let (Some(l), Some(r)) = (it.next(), it.next_back()) {
if l != r {
return false;
}
}
true
}

Kotlin sucks

Making mad bank autoblogging with affiliate link. Python and Selenium is the meat and potatoes. WordPress on the back end.

Weren't you shilling kotlin? What happened?

/dpt/-chan, daisuki~

Ask your much beloved programming literate anything (IAMA)

Why?

Please use an anime image next time.

Sorry user, I love Rust but D is just so much more comfy!
auto is_symmetric(T)(T[] arr)
{
for (auto a = 0, z = arr.length-1; a < z; a++, z--)
{
if (arr[a] != arr[z]) return false;
}

return true;
}

>, in for loops
disgusting

This isn't an equivalent code tho.

...

So what is your is_symmetric() doing?

Rewritten in a decent language.
let is_symmetric eq len nth arr =
let rec loop i z =
i >= z
|| nth arr i = nth arr z && loop (succ i) (pred z) in
loop 0 (pred (len arr))
;;

let string_is_symmetric = is_symmetric ( = ) String.length String.get;;

That is straight up puke inducing

How can CL compete with Scheme when it doesn't even have continuations?

>String

It's not mine, but it takes an iterator, not a slice. I.e. it can work with any source of data, including vectors, ranges from BTrees, static slices and lazily generated data, without allocating and copying anything.

Also, your code requires T to be comparable to itself, yet D has no way to express it in the function signature, meaning your API is incomplete and you're gonna get some fancy error when you try to use it with incomparable type. While Rust's code is a self-sufficient and type checked as is, your code is just a glorified macros waiting to be instantiated to be actually type checked.

that's a specialisation

It takes a vector, user

lol? Most scheme implementations just don't implement continuations because you can't implement in a efficient way, they are fucking slow. Also nobody uses them anyways.

Even worse then.

It takes slices too

it takes a series of functions, it's essentially what rust is implicitly doing

Are you trying to confuse me?
dlang.org/d-array-article.html
it's a slice, which is just like Rust's slices, a pointer to an array + the length of the array. I guess you can convert a vector to it implicitly basically for free, but it's still far from being a generic over the container like Rust's version is.
>it takes a series of functions, it's essentially what rust is implicitly doing
Rust version does nothing of sorts.

>it's a slice,
It's a rage of T, user. Dig deeper.

What's the latest piece of code you've written? Not projects, code.

threadpool in C also some elisp to build my projects.

No it's not: dlang.org/phobos/std_range.html . With ranges it would be something like
auto is_symmetric(R)(R arr)
if (isBidirectionalRange!R)
{}

And the code would be completely different since you now have to pop() and check for empty().

I just simply didn't add more abstractions, user. I knew about bidirectional iterators

Right, so it's not an equivalent code, this is that I've started with.

I have two strings. How can I check if str1[n] == str2[p] in Rust?

return false; // statistically likely

In C it's easy.
str1[n] == str2[p]

Do you want to compare Unicode codepoints or bytes?

...

strings

Communism and Python is for brainlets.

Python is pretty fast with pypy

If you want to compare string, then it's just str1 == str2, there's not need for indexing.

Not in all use cases.

I thought you guys were meming about Python. But I gotta say, it's horrible. How is it still popular among the scientists?

numpy

>How is it still popular among the scientists?
Why people love untyped and unsafe language? Because they don't like discipline, exactly the same reason why mono repositories are still a thing today. Developers are not ready for discipline and quality work.

it's basically pseudo code

Fuck, I'll need to deliver an assignment 80% complete. Am I fucked? I've never failed before like this.

I do machine learning and ANN with javascript pre ES5

Scientists spend all of their time developing science shit and statistics, not writing code. They all use python because it is quick to pick up and implement their algorithms.
That being said FUCK SCIENTISTS.They have no idea how shitty their code is and just assume that their algorithms take a long time to run when really basic programming concepts would speed their code up drastically.

Where is this from

No scientist is falling for the speed meme about prog langs, they calculate their algo speed in a different way, as well as python is psuedo code in action, once is deployed its mostly C++ and C stuff anyway.

imexperience you need to have more discipline about types because you have to be careful about what the fuck can happen to your variables. In typesafe languages you know it wont change so you dont have to stress about it.

I dont know how someone can implement complex math heavy algorithms without proper debugging (e.g. stepping into lines). C# is also a very easy language and you can build shit quickly with it.

why not parameterize over modules?

I tried, but which type do you use?
Because you can have a generic type (like for array), but for string the item type is char mandatory.

how do non blocking timers work under the hood? do they just create an other thread, where elapsed time is constantly compared to a given amount?

ah yeah that's true. you could use some opaque type and perform some GADT magic to treat String.t as Char.t String.t or something like that
like
module String = struct
type _ t = Str of char string
let (=) (Str x) (Str y) = x = y
let length (Str x) = String.length x
...
end

Reminder that C++ is objectively superior to C. It has everything C has, including speed, because if you need C-like speed you can just use the C subset, and if that's still slower with a C++ compiler than with a C compiler, you can just compile it with a C compiler, and you're still technically compiling C++, because you compile C++ whenever you compile C, because all C is C++, but not the other way around. C cannot be faster than C++, because the fastest C program is also a C++ program.

This assumes that C is a subset of C++, which is false. C++ doesn't have a standard restrict attribute, for instance, and that's important for performance.

>C++ doesn't have a standard restrict attribute
C doesn't have this either but the C compiler does
Reminder that the C compiler is actually a C++ compiler, just not a complete one

Reminder that you are still a virgin.

reminder that no i'm not (thanks dad) and it's foR THIS REASON THAT I THink aoubt sjucicde often

>C++ doesn't have a standard restrict attribute
What is this?

What I read in your post.
Reminder that sane person are crazy people without madness.

Asserts non-aliasing of pointer accesses allowing for greater optimization.

that is not an accurate comparison because madness can diminish a person's abilities where as c++ does nothing to c but add new things to be possible in it

ELI7 plz

Implying C++ isn't madness and doesn't diminish possiblity.

pls answer?

oh that's the restrict you meant
i thought it was standard but apparently it isn't
it doesn't if you don't adhere to the standard

muh void* casts
muh vlas

not him but it means if you declare a pointer as restrict and do a thing through it then no memory accesses except through that pointer can overlap with the thing you did

aliasing pointer access means, that you can refer to the same memory segment with differently named pointers
non-aliasing is the opposite

>muh void* casts
posble in c++
>muh vlas
psibble in c++

So it asserts that only one pointer exists to access that memory. Is that a little like volatile then?

void* does not implicitly convert to other pointer types, like in the obvious case of malloc
standards-compliant C++ does not have VLAs. Even C11 doesn't necessarily have it

>muh void* casts
(void*)
you should be using this in plain C anyway
>muh vlas
these are bad practice in C

void swap(int *restrict p, int *restrict q) {
int t = *p;
*p = *q;
*q = t;
}

// illegal
int x = 10;
swap(&x, &x);

// legal
int x = 10;
int y = 20;
swap(&x, &y);

...

It's not like volatile at all.

>Is that a little like volatile then?
no
volatile asserts almost the opposite: that even if nothing in your code changes some data, it's liable to change without warning, e.g. for hardware reasons, so any repeated accesses shouldn't be optimized away

wait so does this mean
int const volatile* restrict
is a valid type?
>no one inside this program can read or write this data except me
>even i can only read it
>but things outside this program are allowed to write to it

dereveotyan eto ti?

It would be wrong for it to be const, but restrict and volatile can be used together.

pali x = let t@(a,b) = bounds x in x == ixmap t (b + a -) x

/me pukes on user

>It would be wrong for it to be const
Why?
Volatile and const can be used together too.
Can const and restrict not be used together?

Why are you so latent? Accept your feelings of arousal.

I link my C++ code with the C compiler because it's faster, and because none of my C files compile under the C++ compiler without adding tons of -fpermissive shit.

Oh, never mind, you can use them together. A volatile const variable is a variable that can change at any time but the code itself can't write to it. "const" is just a bad name for what it really means.

Pretty sure they can be used together. stackoverflow.com/a/4597164

if you use viewpatterns you can probably avoid the let

int const volatile* restrict snek;

#define const
#define volatile
#define restrict
#include

NAP btfo

...

#undef NAP
#define state

I'm working with Python among scientists. It's hell. I hate Python. I hate dynamically typed languages. I hate Guido van Rossum and his "pythonic" cult following.

Python has to die.

Python is one of the least offensive dynamically typed scripting languages you could be working in.

Still sucks for anything longer than about 200loc

Why are most "programmers" aware of the evils of premature optimization (sometimes to the point where all optimization looks evil) but precious few ever consider premature abstraction?

Quit your memeing.

Blame software engineering. People overestimate how useful chunks of their code actually are and end up making horribly maintainable call stacks because of it. Example: OOP

Am I being dumb or does this example not really need non-aliasing guarantees?

/dpt/ in shellnut

restrict isn't a guarantee, it's an optimization hint that could lead to undefined behaviour if you don't ensure you're using it correctly.