/dpt/ - Daily Python Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

strawpoll.me/12925856
hackage.haskell.org/package/harpy
twitter.com/SFWRedditImages

reimplementing Algol68 in rust

>2017
>C

You have been asked to print the sum of two numbers.

Normal people:
void print_sum(T)(T x, T y)
{
writeln(x + y);
}

Mentally ill C tards:
void print_sum_ints(int x, int y)
{
printf("%i", x + y);
}

void print_sum_floats(float x, float y)
{
printf("%f", x + y);
}

void print_sum_float_int(float x, int y)
{
printf("%f", x + y);
}

void print_sum_int_float(int x, float y)
{
printf("%f", x + y);
}

Shitty language, why would you have to write down T?

>silent coercion if you use an int and a float
The C version is safer tbqh

Because any good language will have lambdas which can take types as arguments.

You mean (T) or the T in T x,
T y)?

I applaud your discerning taste. A woman after my own heart.

In Python

def printSum (a, b):
print(a + b)

Both

Seems cancerous.

That's generics not lambdas you cretin

So youve never written a template then.

I did in the past, however as I kept learning about CS I discovered how shitty they are. Seriously, why on earth would anybody use this kind of crap?

print_sum :: (Semigroup a, Show a) => a -> a -> IO ()
print_sum x y = putStrLn $ show $ x y

>I discovered how shitty they are
t. brainlet
Theres a reason why templates are called meta-programming.

see

wat do

>t. brainlet
I would suggest you to read about type systems. Seriously, templates should not be allowed.

>Theres a reason why templates are called meta-programming.
Because they happen before the compile time?

>see
What does this prove?

#define PRINT_SUM(name, t1, t2, f)\
void print_sum_ ## name(t1 x, t2 y)\
{\
printf("%" # f, x + y);\
}

PRINT_SUM(ints, int, int, i)
PRINT_SUM(floats, float, float, f)
PRINT_SUM(float_int, float, int, f)
PRINT_SUM(int_float, int, float, f)

>Seems cancerous.
Why is that?

>generics
I don't recognize this as a valid word.
>not lambdas
So?

>macros
times_macros_saved_Cs_ass++

>I would suggest you to read about type systems.
I use dependent types though, but we dont live in a world, where i can forego imperative typelet languages yet.

>Why is that?
Because you should be able to do print_sum(x, y)
{
writeln (x + y);
}
instead.

What if you need more than one different type?
In this case minimalism will do more harm than good.

In what way does this explain how functions accepting types as arguments is "cancerous"?
>your code
Type inference is for sub 80-IQ people. An addition operator on all number types is even worse.

That doesn't make use of generics. In fact, it's enabling implicit type inference universally, which is not safe for languages that encourages side effects

>What if you need more than one different type?
It will work exactly the same way. This should be a valid function call as long as the + operator can be applied to both x and y with each other.

>In this case minimalism will do more harm than good.
How so?

encourage*

>generics
What is this? Please translate it into non-Java/subhuman talk.

Learn how to use google, dumb mongoloid.

The type is already known as the values that you pass to the function have one.

>That doesn't make use of generics
What do you mean by that?

>which is not safe for languages that encourages side effects
I am interested to know why.
That being said, I prefer languages that avoid them.

>I am interested to know why.
If you are encouraging side effects, you should really keep track of your types. Many functional languages don't have the risk since the type would not change across the project.

So? How does this explain that functions taking types as arguments is "cancerous"?

I tried to, but there was no explanation in non-retard speak. Could you translate it? You seem to know their language.

>If you are encouraging side effects, you should really keep track of your types
Why though?

>since the type would not change across the project.
What do you mean by that?

Because it doesn't make any sense. You already have the type in the parameter, why would you pass it again?

Well in that case you should take English classes, preferably from non-mongoloid "teachers".

How do people usually handle shared model information (i.e. user credentials and cached data, configs, etc.) in MVVM?
My go-to would be something like a Model Locator, like in MVVMLight

Because you have no information about x,y and this really only works for simple two var functions.

When you got more complicated and need something like
do_something_more(x,y,a,b,c)
{
//twenty lines of stuff
}


Youre stuck looking through the definition for information about how the types work. When you could do something like

do_something_more(T x,T y, N a,N b, R c)
{
//twenty lines of stuff
}

If your int turns into a float in some point and you don't know about it you will get incorrect results

Rate my Rust:
mod mylib {

pub trait Argument : Sized
where F : Fn(Self) -> O
{
fn apply(self, foo : F) -> O;
}

impl Argument for T
where F : Fn(Self) -> O
{
fn apply(self, foo : F) -> O {
foo(self)
}
}
}


#[cfg(test)]
mod tests {
use mylib::Argument;

fn triplicate(x : i64) -> i64 {3*x}

#[test]
fn it_works() {
assert!(6 == 2.apply(triplicate));
}
}


My pipelines with dot notation will never be interupted again.

noice

not idiomatic enough / 10

>Because you have no information about x,y
You do, you know that + should work with both x and y, thus limiting the sets that x and y may belong to.

>Youre stuck looking through the definition for information about how the types work
Read the documentation maybe? Or use an editor that can tell you the type?
In any case, if someone wants to type down the types explicitly this is fine, however what is not fine is forcing everyone to do it.

>Make parameters float.
>Cast integers to float when giving arguments.
>??????????
>Prophet

I would say that if your ints turn into IEEE floats randomly and the reverse that there is something wrong with this language.
I can't see how writing down the types would help you.

>pub trait Argument : Sized where F : Fn(Self) -> O
>impl Argument for T where F : Fn(Self) -> O
eww

>converting integers to float
sign of a bad programmer

How else would you compute interest on that gigantic pile of money that your clients have entrusted you with, user?

There is a reason, dumbass.
It's only to fix C's handicaps regarding polymorphism.
In good languages like CL, this shit is unheard of.

>It's only to fix C's handicaps regarding polymorphism.
Oh, makes sense then, hahaha

Can I call you Rusty?

Oh god damn it.

Guess what Rust's notation for accessing say the zeroth or the second element of a tuple (0,1,2,3) is.

It's (0,1,2,3).0 or (0,1,2,3).2 , respectively.

Theres a reason rust is named after fungus.

Can you do (0,1,2,3).N where N is a variable?

whats wrong with that?

Rust sounds cool to be honset.

>Does Rust do tail-call optimization?

>Not generally, no. Tail-call optimization may be done in limited circumstances, but is not guaranteed. As the feature has always been desired, Rust has a keyword (become) reserved, though it is not clear yet whether it is technically possible, nor whether it will be implemented. There was a proposed extension that would allow tail-call elimination in certain contexts, but it is currently postponed.

>How do I do O(1) character access in a String?

>You cannot.

>How can I define a struct that contains a reference to one of its own fields?

>It’s possible, but useless to do so. The struct becomes permanently borrowed by itself and therefore can’t be moved.

>What are higher-kinded types, why would I want them, and why doesn't Rust have them?

>The lack of support for higher-kinded types makes it difficult to write certain kinds of generic code. It’s particularly problematic for abstracting over concepts like iterators, since iterators are often parameterized over a lifetime at least. That in turn has prevented the creation of traits abstracting over Rust’s collections. ... [T]here’s no inherent reason for the current lack of support.

Why would anyone use this language, again?

Go ahead

No. They are field names/compiler magic.

>The power of American education

>>How do I do O(1) character access in a String?
>>You cannot.
sjw's picked a shitty language to latch onto

More usable than haskell

What about Krusty?

It's because strings are UTF-8 encoded, and since UTF-8 is a variable width encoding, you cannot get O(1) lookups.

I'm learning Lua for my first language and I like it!

Not really though, Haskell has HKTs.

Haskell doesn't have inline ASM

not an argument.

You mean: the Unicode UTF-8 standard is shit.

That's retarded

then don't apologize for rust making it the basis for their strings

I'm not here to defend Rust, but UTF-8 is by far the most sane text encoding.
Using anything else would be fucking retarded.

>>Does Rust do tail-call optimization?
W-What? Pretty sure that eliminating the tail call is trivial in any case. Or do they talk about changing a non-tail call into a tail-call?

>>You cannot.
Blame unicode.

>>and therefore can’t be moved.
Moved?

Arguing with an illiterate is like arguing with a monkey

It shouldn't be the standard string though. UTF-8 is fine.

Why would anyone use that instead of let's say functions or arrays?

True for any unicode encoding.

B T F O
T
F
O

UTF-8 is the standard string format nowadays. The website you are posting on uses it.

Inline ASM is not portable, so it's useless.

wall.org/~lewis/2013/10/15/asm-monad.html

you just gave a bunch of reasons utf-8 is shit compared to ascii, and then say utf-8 is better than ascii. you have to give more reasons for it being better than you gave for it being worse

>Inline ASM is useless
This what a brainlet would say.

All the Unicode standard is retarded.

>Using anything else would be fucking retarded.
Why? It's not even ASCII compatible.
The best would be a UTF21 without retarded shit like emojies or other characters that are made up of multiple codepoints.

>It shouldn't be the standard string though.
What on earth are you proposing?
UTF-16, which is infinitely more retarded than UTF-8 and still doesn't have O(1) lookups?
UTF-32, which takes 4 times as much space to encode english text?
ASCII, which makes you have to deal with garbage like code pages or locales if you want to go beyond it?

>Inline ASM is not useless
This is what a codelet would say.

That's not inline assembly, that's using Haskell to generate assembly.

The first 128 chars of ASCII, nothing else. The extra bit in each byte can be used for parity checking.

>Why? It's not even ASCII compatible.
UTF-8 is ASCII compatible, fuckface.
>UTF21
>Non-power of 2 encoding
Wow, that would be so much better.

>What on Earth are you proposing
A string being an array of characters, like most languages. You can also have a utf-8 package if you want to use it.

>The first 128 chars of ASCII
That's literally all there is to ASCII. ASCII is a 7-bit encoding.
>The extra bit in each byte can be used for parity checking.
It's been decades since anybody has used it for that. It's not like we're using it over a lossy medium.

>A string being an array of characters
Are you fucking retarded? That doesn't answer the question at all.
How the fuck would those characters be encoded?

>UTF-8 is ASCII compatible, fuckface.
No, it isn't. ASCII is 7 bit. UTF-8 is 8 bit. You can't read ASCII files with a UTF-8 decoder nor you can read UTF-8 files with an ASCII decoder. Please learn more about a topic before you hurry to insult someone.

>Non-power of 2 encoding
I see no reason on why it should be one.

It doesn't matter, as long as they have constant size for constant access time.

jit :: [Word8] -> IO ()

Entry# 0905.60283641
>I claim Haskell dosn't have inline ASM
>Hasklet responds inline ASM is "useless"
>I infer it has not made any substantial projects yet. Probably spends all day in Sup Forums gate keeping /dpt/
>I call him a brainlet for needing portability
>It responds and calls me "codelet"
>Brainlet is not even making any sense anymore
>I realise it lost its arguments and I call it a victory
>I will post this entry and see it reacts
>It will be fun
end

strawpoll.me/12925856

>No, it isn't. ASCII is 7 bit. UTF-8 is 8 bit. You can't read ASCII files with a UTF-8 decoder nor you can read UTF-8 files with an ASCII decoder. Please learn more about a topic before you hurry to insult someone.
This is so retarded, you don't even deserve a proper response. (You).

Basically what you're proposing is UTF-32, which is incredibly wasteful. The downsides of UTF-32 outweigh the downsides of UTF-32.

hackage.haskell.org/package/harpy

He is actually pretty smart actually as this seems like the most sane solution. This or storing the positions of the start of each character separately in the string struct inside an array.

It does not matter how the characters would be encoded, any encoding would work fine, as long as one full character was stored. Sadly this is not possible if you consider a character to be one unicode codepoint.

Then ASCII it is

I'm saying that it is a poor programmer who believes inline ASM is useful.

I realize that, being a poor programmer, you may lack the cognitive capacity to understand this.