[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

Due to resource constraints, /g/ and /tg/ will no longer be archived or available. Other archivers continue to archive these boards.Become a Patron!

/g/ - Technology

View post   

[ Toggle deleted replies ]
File: 142 KB, 900x900, amazon-parrots-dani-stites.jpg [View same] [iqdb] [saucenao] [google] [report]
63309860 No.63309860 [Reply] [Original] [archived.moe] [rbt]

What are you mimicking today, /g/?

Previous thread: >>63299849

>> No.63309897

a good programmer who has confidence in himself.

>> No.63309902

What's the ideal language

>> No.63309910

>long int
>long long int
>unsigned char
>unsigned int
>unsigned long int
>unsigned long long int
>void *
>_Bool *
>char *
>int *
>long int *
>long long int *
>unsigned char *
>unsigned int *
>unsigned long int *
>unsigned long long int *
should have been
and uppercase reserved for typedefs

What the fuck were they thinking, especially with _Bool?

>> No.63309911

Idris if it were fast.

>> No.63309912


What is the most precise way of timing shit, is std::chrono::high_resolution_clock() fresh?

>> No.63309918

Common lisp

>> No.63309928


>> No.63309930

Agda surely

>> No.63309933
File: 45 KB, 731x777, 1507169916015.png [View same] [iqdb] [saucenao] [google] [report]

Not ideal, but the best one ever created.

>> No.63309957

>u1 for bool

>> No.63309959

agda does some wonky things and idris is comfy.

>> No.63309975

It is unsigned, and has 1 bit of value. That we don't have a way to force/unforce packing is of course a shame, but not a fault of the type names.

>> No.63309996

>that feel when you fucked up logic of the application, and had to duplicate ~100 lines of code.

Its going right into production anyway.

>> No.63310017

>no strings
>no enums
>no mixins
>no modules
>no ufcs
>no ctfe
>no lambdas
>no closures
>no properties
>no uda's
>no templates
>no ranges
>no slices
>no lazy
>no foreach

Need i go on?
>inb4 "all bloat"

>> No.63310028

What do you guys think

#include <stdio.h>
#include <string.h>

int main()
short s = 0;
char* str = "Hello World!\n";

for(int i = 0; i < strlen(str); ++i){
s = (short)str[i];

printf("%s", &s);

return 0;

>> No.63310042
File: 56 KB, 1200x1200, Rust_programming_language_black_logo.svg.png [View same] [iqdb] [saucenao] [google] [report]

Ideal language, shitty community.

>> No.63310050

It's a Boolean value, not an unsigned 1-bit number. Why would it not be marked with bool

>> No.63310059
File: 36 KB, 600x480, ponylogo.jpg [View same] [iqdb] [saucenao] [google] [report]

Ideal core language, wonky syntax, great but way too small community.

>> No.63310060

>ideal language
Not yet.

>> No.63310067

>POSIX.1 defines seconds since the Epoch using a formula that approximates the number of seconds between a specified time and the Epoch. ... This value is not the same as the actual number of seconds between the time and the Epoch, because of leap seconds ... see POSIX.1-2008 Rationale A.4.15 for further rationale.

So what do we find in POSIX.1-2008 Rationale A.4.15?

>A.4.15 Scheduling Policy
>There is no additional rationale provided for this section.


>A.4.16 Seconds Since the Epoch
>Coordinated Universal Time (UTC) includes leap seconds. However, in POSIX time (seconds since the Epoch), leap seconds are ignored (not applied) to provide an easy and compatible method of computing time differences.

What the fuck? Are they trying to trick me? Is this the power of GNU?

>> No.63310070

So is pony a meme or not? I have difficulty taking it seriously given its name.

>> No.63310084

BC and the syntax is not ideal in any way.
Solid language bogged down by terrible syntax.

>> No.63310097


>> No.63310139

If a new programming language is not free software or at least open source then something is wrong.
Sounds interesting.
Relative to what?

Why couldn't they have called it something like 'Equine' or 'Mare'?

>> No.63310174

C was designed to allow for non 8-bit byte architectures, so naming the standard integer would be inappropriate.
>What the fuck were they thinking, especially with _Bool?
The C standard reserves all identifiers with a leading underscore and capital letter or two leading underscores.
So when they typically add a new keyword, they will use a reserved identifier to not break any existing code, and provide a convenience macro (bool from stdbool.h).

>> No.63310175

Pretty sure they said in a talk they plan to FOSS it Soon™.
>Relative to what?
"It's faster than Java, but still not comparable to C/++"

And i think it's a nice paradigm difference from the usual C-like. They just really need to clean up things.

actor Main
new create(env: Env) =>
env.out.print("Hello, world!")

>> No.63310179

The only thing I'd like to have added to Rust is trait members and maybe function overloading. Lately we got generators/coroutines which was the biggest wish for me I guess.

>> No.63310198

I need to create some kind of pattern to be able to translate objects to different type without changing and knowing its implementation just know that every type have two pointers to same type and one int member.

Imagine someone has following code:

struct SomeonesNode
SomeonesNode* previous;
SomeonesNode* next;
int key;
double weight;

and someone else has code:

class AnotherOne
AnotherOne* prev;
AnotherOne* next;
int key;

And I want to translate/cast these objects to

class Node
Node* prev;
Node* next;
int key;

I want to give them possibility tu run my function (myFunction(Node* node)) on theirs own implementation without need to change code.
How can I achieve this?

I could require to implement theirs own casting fe.

class Node
Node(YourObject& yourobject) {
prev = new Node(yourobject);
next = new Node(yourobject);
key = youobject.getKkey;

And additional I need to prevent looping when objects are linked in circular way.

Is this a good approach? Any better ideas?

>> No.63310219

That's great news.

My biggest complaint right now is the lack of full, real HKTs.

>> No.63310222

also, the whole name is a dumb joke:

>Back in the flight sim days, when I would make my friends groan by telling them yet again about all the things I was going to do when I wrote a programming language, one of the people I would tell was Nathan Mehl. And one time, when I gave him yet another laundry list, he said: “yeah, and I want a pony”.

>> No.63310247

>no strings
Wrong, there is char* which provides any sane man's idea of a string, that is a null terminated string, as used in other languages which "implement" strings such as perl. If you need byte strings the C99 VLA feature together with a struct can easily implement it, as is done in several libraries however this is an edge case which the majority of users have no use or desire for.
>no enums
What the fuck are you talking about?
>An enumeration comprises a set of named integer constant values. Each distinct
>enumeration constitutes a different enumerated type.

>no mixins
Because it's not object-oriented.
>no ufcs
This does seem cool, having functions create file descriptors for write() sure would be something, instead of having to define your own wrapper like netwrite() when writing e.g a web server with dynamic application support.
>no ctfe
Macros, const attribute.
Function pointers.
Arrays of function pointers.
All the others are bloat, yes.

>> No.63310261

#define true 1
#define false 0

Otherwise using it for multiplication would feel unclean and like utter nonsense.

>> No.63310262
File: 22 KB, 485x443, 1509259560452.png [View same] [iqdb] [saucenao] [google] [report]

>Function pointers.
>Arrays of function pointers.

>> No.63310279

>>Ideal language, shitty community.
>Worst language
>node.js community

>> No.63310280
File: 44 KB, 640x480, 1509769670768.jpg [View same] [iqdb] [saucenao] [google] [report]

>Wrong, there is char* which provides any sane man's idea of a string, that is a null terminated string
I'm too scared to read the rest of your post now. Surely nobody's this delusional?

>> No.63310286

the ultimate enlightenment: realizing all monads are continuations

>> No.63310288

the enum was a mistake.

>range / slices

Kill yourself m8

>> No.63310298

Well, dividing them all by 8 would be reasonable then.
_Bool is still ugly as shit, they could have went with boolean and created an alias for that.

>> No.63310340
File: 30 KB, 720x718, 1508895610314.jpg [View same] [iqdb] [saucenao] [google] [report]

All useful monads are either free or better done with linear types.

>> No.63310360

>Well, dividing them all by 8 would be reasonable then.
No. That's stupid.
That would undoubtedly have broke existing code.
>created an alias for that
bool is the fucking alias. If you want to use bool , include stdbool.h. If you don't include it, don't worry about it.

>> No.63310364

Never mind, I misunderstood closures. They are even worse than I thought, and not suitable for C. Lambdas are function pointers with another syntax, yes.

>> No.63310371

They created an alias for _Bool you idiot. stdbool.h. Wew. So hard.

>> No.63310405

>not suitable for C
Because it lacks generics? Languages with generics like C++ or Rust can use closures with zero overhead (because there's no indirection).

>Lambdas are function pointers with another syntax, yes.
Function pointers are one way of representing closures (well, you also need to capture free variables). Lambdas are not function pointers, lambdas are anonymous functions which may or may not be closures (but often are).

>> No.63310409


>> No.63310440

What would
auto thing = [ 20, 1, 11, 300, -2 ].filter!(num => num > 10);

look like in C with a function pointer?

>> No.63310448

For example, it's what perl does. For anything else, there is the mem* family of functions.
And not a single argument.
Defining bool as an alias for boolean in stdbool.h, I mean.
There are still other names to pick for it.
It is not suitable for C as it is an incredible amount of bloat. Longjmp and inline assembly to put the registers somewhere works acceptable, but it's still a horrible idea- pointers will fuck you up
Lambdas are anonymous functions, which are syntactic sugar for function pointers. You can pass them in, return them, etc.
Why don't you explain what the code does first?

>> No.63310474

>I can't fathom how first class functions work without pointers

>> No.63310475

>Why don't you explain what the code does first?
literally just filters the numbers in the array that are greater than 10.
filter! being a template instantiation.

>> No.63310484

Name one.

>> No.63310531

Huh? We can hide them behind typedefs, but that's useless.
You would pass in a function pointer to filter!().

>> No.63310547

Now what about if 10 got changed to 10.9?

>> No.63310549

It's quite rare that you actually need to compile a subroutine that could work for absolutely any function (in which case you use a function pointer) as opposed to inlining the higher order function and the function argument. No indirection needed, and this is expressed directly with monomorphized generics.

>> No.63310569

We would change the function, or have it take 10 as an argument.
Any modern compiler does this for you.

>> No.63310581

If the code itself doesn't concern function pointers but instead uses generics, you can just pass everything by value and it's a lot nicer.

>> No.63310587

could you show me exactly how that'd look?
How would you handle if 11 got changed to 11.1?
I'm not convinced the C version wouldn't be a tedious mess, but you'll call lambda's bloat.

>> No.63310628

Generics for what? Weren't you talking about the lambda?
You would have a function called greater(x, y), which would return 1 if x > y and 0 if x < y. You could also hardcode 11 into the function and change it there.
Changing 11 (int) to 11 (int) is no difference. Changing 11.0 (float) to 11.1 (float) is a 1 character change.
Changing 11 (int) to 11.1 (float) is a 6 character change.

>> No.63310633

>Generics for what? Weren't you talking about the lambda?

>> No.63310649

>You would have a function called greater(x, y)
So how do you do this with just a function pointer?
filter(x => greater(x, 10))

>> No.63310672

>You could also hardcode 11 into the function
ah yes, the sure sign of good code.

>> No.63310703

Is there some function like memcpy which is guaranteed to be optimized and not have UB?
as in
char[] a = "abcdefghi";
memcpy(a+1, a, 8);
// a == "aaaaaaaa";

I don't understand what you're trying to convey here.
Yeah, something like that. We weren't discussing the existence of .filter().
In some cases it, coupled with a #define or just a comment, makes perfect sense, yes.

>> No.63310708

>I don't understand what you're trying to convey here.
You say closures aren't suitable for C, I say that's just because it doesn't have generics.

>> No.63310715


>> No.63310717

Closures need you to copy the stack and dump it somewhere, not suitable, no.

>> No.63310728

Generics were a mistake.
If you don't know which data type you're going to store, you've done your analysis wrong.

>> No.63310734
File: 40 KB, 645x729, 1508970819999.png [View same] [iqdb] [saucenao] [google] [report]


>> No.63310735

Memmove does the opposite of what I want, it would give me "aabcdefgh".

>> No.63310752

>still no simple demonstration of a simple filter """"""""""""""""""lambda"""""""""""""""""""""" in C

>> No.63310766

>Closures need you to copy the stack and dump it somewhere
Are you somehow confusing closures with continuations? You only close over the variables you need to. C doesn't have closures because closures are incoherent outside of garbage collected languages. t. C++ with its weird "closures."

So you want the garbage data of "aaaaaa" or if you did, a+2, a, you would want "abababab"?? You're going to have to dip into assembly for that retarded behavior.

>> No.63310772

What does a function of type forall a b c. (b -> c) -> (a -> b) -> a -> c do?

What does a function of type (String -> Int) -> (Double -> String) -> Double -> Int do?

>> No.63310776
File: 12 KB, 817x182, string ass.png [View same] [iqdb] [saucenao] [google] [report]

Why would this assignment produce this garbage? They are both std::string

>> No.63310782
File: 55 KB, 645x729, 1506554217525.jpg [View same] [iqdb] [saucenao] [google] [report]

>C doesn't have closures because closures are incoherent outside of garbage collected languages. t. C++ with its weird "closures."

>> No.63310788

Gofags everyone

>> No.63310828
File: 82 KB, 978x682, 1494538263363.jpg [View same] [iqdb] [saucenao] [google] [report]

In Py3, assuming the sys module has been imported, why would this:

x = input("State thy name. ")
print("Greetings, " + x + ".")

be preferable to this?:
print("Yo homie, whas'yo name?")
z = sys.stdin.readline()
print("Sup, ", z)

I'm not sure how to punctuate the end of the second example either. My attempts at doing so resulted in a newline being created, and the period ending up there.

>> No.63310829

Could you explain what advantage would it give to Rust?
I can't find anything specific and many of HKT features can be archived in Rust.

>> No.63310841

go away ekmett

>> No.63310868

No, as C does not have filter. If it did, we could just do something like
filter(array, greater, 10);

>Are you somehow confusing closures with continuations?
Entirely possible.
>So you want the garbage data of "aaaaaa" or if you did, a+2, a, you would want "abababab"?
>You're going to have to dip into assembly for that retarded behavior.
Perfectly sane behavior. It copies from src to dest, since dest happens to be located inside src src happens to mutate during the copying, but this is not the function's fault. The function copies from src to dest, and you have the same problem with memcpy if another thread would suddenly start copying into src.
How would assembly help me? I can just write a function
void sanememcpy(void* dest, const void* src, size_t n)
void* stop = (void*) (((intptr_t) src)+n)
for (; src < stop; src++ = dest++};

Which does what I want.

>> No.63310872

In a good FP each arg can be named for even better context.
but why don't you paste the whole thing seeing as you're purposely leaving out the names.

>> No.63310887

But you said it's just a function pointer, so show me how simple it is.

>> No.63310907

Not him, and it's not full HKTs, but generic associated types are extremely useful. For instance:
trait Foo {
type Bar<'a>;
fn baz(&'a self) -> Bar<'a>;

At the moment, you need to work around it with dynamic borrowing. You can also port various type classes from Haskell:
trait Functor<T> {
type F<U>;
fn map<U>(self, f: impl Fn(T) -> U) -> Self::F<U>;

trait Monad<T> {
type M<U>;
fn unit(x: T) -> Self;
fn bind<U>(self, k: impl Fn(T) -> Self::M<U>) -> Self::M<U>;

>> No.63310910

filter(array, greater, 10);

That's how, provided C would have filter().

>> No.63310914

The point is that the generic type of the first function tells you exactly what it does. You don't need to know what the arguments are named (and in any case, argument names can lie).

The second function could do any number of things.

Consider a simpler example. forall a. a -> a and Double -> Double.

>> No.63310915

Are you a rustlet? Because your "closures" are shit too.
>error: closure may outlive the current function, but it borrows `x`, which is owned by the current function [E0373]

>> No.63310928

Please tell me why that shouldn't be an error. If you need it to not be an error, you move the captured variables into the closure.

>> No.63310970

Surely the type parameter of Monad should be M? Something like:

trait Monad<M> : Applicative<M> {
fn return<A>(a: A): M<A>
fn bind<A, B>(fa: M<A>, f: A -> M<B>): M<B>

>> No.63310976

The main advantage and disadvantage of HKT's when you already have Rust's power level is stronger free theorems.

I think introducing some level of dependent types would be much more useful for Rust than HKT's desu. You can express functors/applicative/monads and traversable in Rust without HKT's. But dependent types on the other hand enable things like trait implementations for raw foxed-length arrays of any size, which is much more useful.

If HKT's get in the way of dependent types and type inference, then dump them imho.

>> No.63310999

Completely agree. I suspect HKTs are easier to add to Rust than a solid implementation of dependent types, maybe I'm wrong though.

>> No.63311004

Rust's traits have an implicit type parameter Self which is the type of the implementor. What Rust would need to have HKTs as opposed to just generic associated types would be the ability to specify the arity of Self for a trait and then some kind of type level lambda.

>If HKT's get in the way of dependent types and type inference, then dump them imho.
HKTs don't get in the way of type inference. Dependent types do.

>> No.63311005
File: 39 KB, 657x527, 1476385241148.jpg [View same] [iqdb] [saucenao] [google] [report]

Should i learn Rust or sepples? What are the pros and cons of each?

>> No.63311017

That's not what i asked.
You can't leave the answer half-finished, which proves my point is that C is shit.

>> No.63311028

Oh, I think I understand. So instead of M<...> in the trait body there would be Self<...>?

>> No.63311039


>> No.63311073

>Should i learn Rust or sepples?
>pro's : libraries i guess
>:: too many

>> No.63311074
File: 55 KB, 793x794, 1489867148632.jpg [View same] [iqdb] [saucenao] [google] [report]

>array indexing starts at 0

>> No.63311075

These aren't "arg names" but type-var names, and yes you can name them anything you want, and yes they're usually just abstract symbols akin to foo and bar because they occur in usually "purely symbolic" (not *specific* or specialized) simple data-structure transformation functions

>> No.63311296

Functor and Monad can be implemented easily like this:

trait Functor {
type Item;

fn map<U : Functor>(self, f: impl Fn(Self::Item) -> U::Item) -> U;

trait Monad {
type Item;

fn puref(Self::Item) -> Self;
fn bind<U : Monad>(self,impl Fn(Self::Item) -> U ) -> U

This implementation is actually much better than Haskell's typeclasses, since you can define (mathematical) functors between any pair of types, not just from a given type to a "container" of such types. What you give up is free theorems so that you actually have to prove a few extra laws.

>> No.63311307

The problem is that most of the stuff that HKT's are useful for in Haskell (monadic things like lists, parsers, futures, exceptions as sum types) would not apply as easily in Rust. For instance, in Rust, there are seperate types for each iterator combinator (.map returns Map<Self,F>, .filter returns Filter<Self,P>, etc.). When Haskell folks beg for these features in Rust, it just comes off to me like them wanting their favorite features in every language; there is no real practical need for the kind of Monad representation you want.

However, HTKs would still be nice for abstraction over pointer types and to make functions parametric over mutability. Also, value kinds would be really nice to clean up the messy slice implementation.

This isn't to say that we don't need better monad support. The tokio concurrency library, and the pervasiveness of Result<> shows that we really DO need some sort of monad abstraction. Manually writing .and_then everywhere is very ugly. Perhaps they can look at OCaml, which provides preprocessor extensions that just transform "let%bind x = e in b" into "bind e ~f:(fn x -> b)". However, there are still problems; closures have specific semantics in Rust that are not nearly as free as closures in GC'd languages, which occasionally bites you in the ass when doing closure-heavy stuff -- especially when threading stuff like tokio monads. If the presence of closures were sugared away, then you would have to diagnosing borrow checking problems in closures that are completely implicit. Not something I would like to spend my time on.
It's not an easy problem. I'd love to hear some of these points addressed

>> No.63311332
File: 25 KB, 800x331, flat,800x800,075,f-c,0,75,800,331.u1.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.63311346

Why is the /dpt/ on wizchan so much better than here? Is it really true you need autism to be a good programmer?

>> No.63311376

>go there
>literally the same type of posts as /dpt/ only with more /v/ kiddy questions
alri /r9k/

>> No.63311377

Checked out Go today, it's actually not so bad. I mean, at least it's not Rust or C# I guess

>> No.63311401


>> No.63311408

Go programmers are self-selecting, it seems.

>> No.63311471

>literally the same type of posts as /dpt/
Maybe check again

>> No.63311489

Is this the one?
>how do i get money
>what is best for X to get a job
>help my C++ isn't working

>> No.63311500

>fn map<U : Functor>(self, f: impl Fn(Self::Item) -> U::Item) -> U;
I don't think this works; wouldn't this allow you to e.g. map an Iterator into an Option ?

>you can define (mathematical) functors between any pair of types
Could you elaborate on this? How is it more mathematical? I've just started reading up on the real category theory background on functors

>> No.63311620

Trivial example that "vanilla" monads in Haskell's standard library can't do:

impl Monad for f32 {
type Item = f64;

fn puref(x:f64) -> f32 {
x as f32

fn bind<U : Monad>(self, f: fn(f64) -> U) -> U {
f(self as f64)

This lets me apply f64 operations to f32 numbers.

>> No.63311635

That's not a monad...

>> No.63311636

What are good exercises/things to do if I want a job?

>> No.63311645

>"What's the ideal language"
>one-sentence shitposts filling up half of every thread
>people actually think python is better than bash

>> No.63311664

>X is better than Y
>no it's not

alri m8

>> No.63311668
File: 136 KB, 1600x900, Nico 320.jpg [View same] [iqdb] [saucenao] [google] [report]

i rly like watching cpp con videos
does anyone have any good ones
heres some if anyone else likes these:

post more!

>> No.63311702

A functor F is any function from one category to another so that for a pair of morphisms (let's just take functions) f,g we have F(id) = id and F(f . g) = F(f) . F(g). It does not have to work on every pair of types, it's allowed to only be defined on a specific pair.

You're actually correct that the definition of functor I mentioned doesn't actually work since I can't make it generic over U, I need to specify it as an additional type parameter for the trait.
trait Functor {
type Item;
type Target;
type TargetItem;

fn map<U : Functor>(self, f: fn(Self::Item) -> TargetItem) -> Target;

The monad definition works as-is though.

>> No.63311711

>that Q&A section of mike acton's talk
But I like the ones where the core members are all together and they get visibly flustered when people bring up other langs.

>> No.63311716

are you talking about 'grill the cpp committee' or something

>> No.63311720

Yes it is, by the category theory definition, for the category of all functions to and from f32 and f64.

>> No.63311725

Yeah, those and they have a few others.

>> No.63311848


puref(x).bind(foo) = foo(x)
x.bind(puref) = x
x.bind(foo).bind(bar) = x.bind(x -> foo(x).bind(bar))

are all satisfied, you can check it yourself.

>> No.63311908
File: 642 KB, 476x595, Screenshot 2017-11-10 at 8.22.02 PM.png [View same] [iqdb] [saucenao] [google] [report]

I'm fascinated with old tech/computing. I'm writing an 8080 emulator + Operating system right now. What are some good docs to read on old technology, assembly, processors, etc.?

>> No.63311921

You could read the old programming magazines like Byte.

>> No.63311926

I've actually done that! I made a modem program using their article on the Kansas city standard!

>> No.63311957

This can be generalized. Whenever I have two spacex X and MX, with an injective function f from MX to X, then I can define a monad for any function g that which is a left inverse of f, i.e. satisfies g(f(x)) = x. The monad is defined by defined by pure(x) = g, and bind(x,foo) = foo(f(x)).

>> No.63311958

I can't help you with your answer, but you should wrap your code in code brackets any time you post it. Look at the sticky for more information.

>> No.63311974

* pure(x) = g(x)
for x in X, and pure(x) = x for x in MX

>> No.63311977

>fn map<U : Functor>(self, f: fn(Self::Item) -> TargetItem) -> Target;
This still doesn't work, since we want to be able to e.g.
>Some(3).map(|x| format!("{}", x))

>A functor F is any function from one category to another
Right. So here's my understanding of functors in typed languages:
Let R the category of Rust types, with objects T,U (types) and morphisms f,g: T -> U (functions).
A functor F maps R -> R', where R' is a subset of R specialized to that function, e.g.
F = Vec, F(T) = Vec<T>.
F can be "applied" any function f: T -> U as the map operation such that F(f) : F(T) -> F(U), obeying those laws you stated.

I suppose F doesn't have to just be the specialization of a generic type. You could have a constant F(T) = i32, which would have to necessarily ignore the mapping function.

>It does not have to work on every pair of types
How so?

If you're right, then it's just not a very useful monad.

>> No.63312001


>> No.63312088
File: 344 KB, 667x1000, MBC_CHM_2015-4-25_PORT_WEB-6600.jpg [View same] [iqdb] [saucenao] [google] [report]

spent a couple of days rewriting nanovg
what a heap of horrible horrible code
god bless bjarne

>> No.63312112

>> If you're right, then it's just not a very useful monad.

That's a special case of a forgetful functor, which is an extremely useful construction to have in mathematics. You can also define a similar "monad" that maps the Either monad to the Maybe monad.

Another useful functor (monad) of a similar type would be one that maps functions on iterators to functions on vectors, etc etc.

Limiting functors and monads to cases where you have a specific type constructor is unnecessarily limiting.

Right, the crucial point is that F(T) and F(U) don't need to be of the form Constructor<T> and Constructor<U>, they can be arbitrary types in the functors target subcategory of Rust types, as long as the functor laws are satisfied.

T and U can also be restricted to be part of some specific subcategory of Rust types, instead of having to be generic.

>> No.63312207
File: 106 KB, 1657x819, Code 1.png [View same] [iqdb] [saucenao] [google] [report]

I don't understand

I can print

but trying to do

which should show 0, instead gives me a nil error, so what the hell is happening because I can't see the issue? Like why does one nested table thing work but the other spits out an error?

Code is Lua, don't judge I don't know how to do programming.

This is the last step in getting my current game code pretty much 100% functional

>> No.63312264

>T and U can also be restricted to be part of some specific subcategory of Rust types
Right. But they would still be "generic", unless your subcategory was something boring like "the category U with just the object u32, and the category I with just the object i32."
But then a functor F : U -> I would basically only have a single implementation (F(u32) = i32, (F f)(x) = f(x as u32) as ui32) which kind of defeats the point of it being a trait.

>Limiting functors and monads to cases where you have a specific type constructor is unnecessarily limiting.
I wouldn't say it's unnecessary. At some point we have to come to terms with the halting problem, and if we want good type inference we'd better not put arbitrary functions at the type level. (btw, I think that dependent types are very novel, but require far too much machinery to be applicable to general programming).

>> No.63312346

Shouldnt Playerstattable1 be Playerstattable1 [1] at ln 1848?

>> No.63312396
File: 105 KB, 960x952, 22688317.jpg [View same] [iqdb] [saucenao] [google] [report]

Just solved the birdmin problem.

use std::io;

fn luhn_doubler(x: i32) -> i32
let mut result: i32 = 2 * x;
loop {
result = result % 10 + (result - result % 10) / 10;
if result < 10 {

fn main()
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap_or_default();
input = input.trim().into();

let mut sum = 0;
for (i, n) in input.chars().enumerate() {
sum += if i % 2 != 0 {
n as i32
} else {
luhn_doubler(n as i32)

"This is a{}alid number.",
if sum % 10 == 0 { " v" } else { "n inv" }

>> No.63312412
File: 243 KB, 1000x1500, Yui 205.jpg [View same] [iqdb] [saucenao] [google] [report]

i like that yui pic

>> No.63312486

It doesn't consider spaces I don't think, doesn't on the other one as it's exactly the same

>> No.63312503

I am practicing C on CS50 IDE, instead of using, let's say nano, because I don't want to segfault, and destroy some of my memory/computer files. How much of a pussy am I?

>> No.63312518

no i mean, Playerstattable is a 1 dimensional array whereas you're trying to index it as a multi. Unless Lua just has weird syntax.

>> No.63312527

can you actually destroy you files through a niave memory error?
isn't that the whole point of process encapsulation
can't only processes running at 'ring 0' or something do that?

>> No.63312557

I think it's built wierd yes but looking at the code

battle2playertable1 is a table within a table
Playerstattable1 is a table within a table

But one prints just fine and the other spits out an error...unless I need one more....

>> No.63312572

r8 my rust code
let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut let mut

>> No.63312584

not idiomatic enough / 10

>> No.63312604

rate my C code
int*** (char**)[] (&&*(&void*))********** int*(size_t***)

>> No.63312613

If I change PlayerORDER1 to yamchastats1 it will work fine, but obviously that's not what I need. So I don't know what it is, maybe it's because it's a 0? I have no idea

>> No.63312615

would rust be better with l instead of let and lm instead of let mut?

>> No.63312621

doesn't compile / 10

>> No.63312626

But it's not because it's 0, because I tried to add in numbers just to see....

>> No.63312629
File: 70 KB, 580x779, Azusa 477.jpg [View same] [iqdb] [saucenao] [google] [report]

ive worked with gtk
seems it might be legitamately easier to use SDL to make my next gui instead
am I retarded?
I just want to make a file searcher and browser for my anime pics
if I use sdl i can make it cute

gtk is hell

>> No.63312636


>> No.63312644


>> No.63312645


>> No.63312671

No. let mut is objectively better.

>> No.63312680


>> No.63312684

>not having a safe space in your language
get on our level C luddites

>> No.63312701

Aids you in preserving const correctness.

>> No.63312705

Rust is stuck in the past in more than one way, desu

>> No.63312718

So would lm. The only difference is it's 5 characters shorter.

>> No.63312733

Need I say more?

>> No.63312750

>uses Rust
>Doesn't take modern, functional approach
Are you from 1975 or something?
import std.algorithm, std.range, std.string;

enum luhnTest = (in string n) pure /*nothrow*/ @safe /*@nogc*/ =>
.zip(only(1, 2).cycle)
.map!(p => (p[0] - '0') * p[1])
.map!(d => d / 10 + d % 10)
.sum % 10 == 0;

void main() {
assert("49927398716 49927398717 1234567812345678 1234567812345670"
.split.map!luhnTest.equal([true, false, false, true]));

>> No.63312774

good lad

>> No.63312787


>> No.63312796

I dislike Go builtins can do things user code can't. Generics would help, maybe go 2 will do something about that. I do like is how lightweight goroutines are and the low pauses of the GC.

>> No.63312799

Well, in my defence:
1. I'm very new to Rust
2. My solution actually reads from stdin, parses them and prints if valid or not.

But I see your point. I'll re-do the problem.

That's D. (t. ex D fag)

>> No.63312800

That's D you dummy

>> No.63312816

>(t. ex D fag)
What do you use now?

>> No.63312817

The issue was the order of the code

the nested table needs to go under the other tables.

>> No.63312835

C++ at work, learning Rust. I took a break for the fucking excruciating project I had for the last 4 months.

>> No.63312845

>learning Rust
you poor soul

>> No.63312855

Protip: It's the future.

>> No.63312873

whatever you say m8, maybe the next iteration language with a better BC will be. But Rust will always be largely irrelevant and a stepping stone language, much like Haskell.

>> No.63312887

I see your point :)

>> No.63312931

Haskell's a bloody long stepping stone if you ask me

>> No.63312944

Well done, anon.
Looks a bit expensive but looks nice!

>> No.63312962

Just depends if you want to go deeper down the hole or move to a language with dependent types. Which is why my time with haskell was pretty short before i tried and loved idris.

>> No.63312993

Idris is great and I generally prefer it too. Haskell has a lot more going for it right now though. I worry that the momentum it has accumulated will push out better (but smaller in terms of usage) languages for some time yet.

>> No.63312994

I'm trying Idris now, dependents types are cool but the language itself seems unfinished. What's the best resource for learning?

>> No.63313021

it already has unfortunately. No one wants to make libraries, only use them. So no languages ever get adopted unless someone else does the work for the rest.
His book, probably.
Got it half off because i could not find a torrent or dl anywhere

>> No.63313113
File: 2.90 MB, 1920x1080, convert.webm [View same] [iqdb] [saucenao] [google] [report]

You guys never told me programming for the Commodore 64 would be this much fun.

>> No.63313203

torrent is on bibliotik

>> No.63313222

I can't be fucked with privates which is probably why i didn't find it. But having a physical programming book is pretty comfy.

>> No.63313258

it seems it's on libgen now but it originated from bibliotik


>> No.63313261

Implemented in OCaml for practice
open Batteries
open OUnit2

let luhn s =
let (%) = Int.modulo in
let char_dig c = Char.code c - Char.code '0' in
let dig_sum k = (k / 10) + (k % 10) in
let double i n = if i % 2 = 0 then n else n * 2 in
(String.rev s
|> String.enum
|> Enum.map char_dig
|> Enum.mapi double
|> Enum.map dig_sum
|> Enum.sum)
% 10 = 0

let _ =
@@ test_list
["Luhn" >::
fun _ ->
assert_equal (luhn "49927398716") true;
assert_equal (luhn "49927398717") false;
assert_equal (luhn "1234567812345678") false;
assert_equal (luhn "1234567812345670") true ]

btw jane street pls hire me

>> No.63313282

It's shameful to see a functional language looking more unnatural than an imperative language in functional programming.

>> No.63313317

OCaml looks weird at first but I'm used to it now

Also if we open Enum we can make it nicer
let luhn s =
let open Enum in
let (%) = Int.modulo in
let is_mul n x = x % n = 0 in
let char_dig c = Char.code c - Char.code '0' in
let dig_sum x = (x / 10) + (x % 10) in
let double i x = if is_mul i 2 then x else x * 2 in
String.rev s
|> String.enum
|> map char_dig
|> mapi double
|> map dig_sum
|> sum
|> is_mul 10

>> No.63313542
File: 7 KB, 793x370, ER.png [View same] [iqdb] [saucenao] [google] [report]

I'm writing a program where we have a market place for cars, where people can upload cars to sell.

Is this ER correct?

- a user can upload more than one car, but at least one
- the market place can have lots of cars, but at least one

>> No.63313564

>Is this ER correct?
Who cares?

>> No.63313574

the professor

>> No.63313616

Tell him to stop teaching useless bullshit

>> No.63313632

fn luhn_check(input: &str) -> bool {
let n: i32 = input.chars()
.map(|c| (c as u32 - '0' as u32) as i32)
.map(|(i, n)| if i % 2 == 0 { n } else { n * 2 })
.map(|k| (k / 10) + (k % 10))

n % 10 == 0

fn examples() {

>> No.63313643

This theme is so apt for my current project

>> No.63313739

Depends on what you're after but I'd probably look away from documentation for the specific clocks and see what others use. For instance go look at https://github.com/google/benchmark
Because most docs won't tell you the reality of the situation.
rdtscp (or similar) is the best resolution you can get but they come with caveats like not measuring your process execution time but rather the CPU clock count.
In my experience running benchmarks repeatedly really makes this effect unnoticeable. For more complicated situations or longer running tests (where I doubt you need the resolution frankly) it might be a problem though.

>> No.63313750

Why are you all so focused on code and not your problem domain? Doesn't this show you as either inept programmers (no offense meant) or that there's something wrong with your environment?

>> No.63313755

I made a bookmarklet for a black placeholder page to use with your browser on a current unused monitor: https://gist.github.com/Meyermagic/b09b8785776311f07dec4e1394535b00

>> No.63313771

>and not your problem domain?
Because I want my code to be nice.
And in the current year you don't have to settle for one or the other.

>> No.63313794

No this is a side interest. Of course focusing primarily on programming is dead end. Thanks for posting this though. I hope some newbies read it.

>> No.63313827

>maybe newbies will read it
I hadn't thought of it but you're right. It's something I certainly would have liked to hear.

>> No.63313862

Yes for me too. Now I am industrial programmer but I still like programming for itself.

>> No.63313934

working on a lame retard tier project but i finished it with no help without peeking and it works and is more featureful than the tutorial version and i feel good yay

>> No.63314024

The nonexistent ^C language from a few threads ago

^C-fag, if you're reading this, make that shit happen. It would be like an imperative Idris

>> No.63314030

please don't insult idris like that.

>> No.63314036

But anon, it's slow.

>> No.63314051


>> No.63314060

And C is unsafe, lacks an ocean of features, and has the expressiveness of a chink.

>> No.63314062

>lacks an ocean of features
C is a simple language

it was not made to be a bloat one


>> No.63314069

>union <’a>list of nat {
{n:nat} Cons(n+1) of ’a * <’a>list(n);
(’a){m:nat, n:nat}
revApp(xs:<’a>list(m),ys:<’a>list(n)) {
var: ’a x;;
[m1:nat,n1:nat | m1+n1 = m+n]
(xs:<’a>list(m1), ys:<’a>list(n1))
while (true) {
switch (xs) {
case Nil: return ys;
case Cons(x,xs): ys = Cons(x,ys);
exit; /* can never be reached */
<’a>list(n) reverse (xs: <’a>list(n)) {
return revApp(xs, Nil);
Figure 2. The list reverse function in Xanadu

>i-its all bloat, who needs it!
Every time.

>> No.63314070


>> No.63314071
File: 112 KB, 1200x900, C2ZIMJ0UsAA2039.jpg [View same] [iqdb] [saucenao] [google] [report]

>But anon, it's slow.
>Non-C languages are too slow.
>You're too slow!
>C'mon, step it up!
>Chili dogs!
>Gotta go fast!


>> No.63314073

Yeah but you'd agree there are new certainly things that C is lacking?

>> No.63314081

What's the problem?

>> No.63314082

>And C is unsafe, lacks an ocean of features, and has the expressiveness of a chink.
Yeah, but out of those three problems, ^C would only be unsafe.

Whereas Idris is slow.

>> No.63314104

You'll never convince a cnile C needs anything.
The language is perfect in their eyes, but can be made even *better* by immaculate macros.
the lisp-like syntax mostly.
Idris can only get faster, whereas building a whole language from would take a considerable amount of time. But i do welcome anyone to improve on C's many mistakes.

>> No.63314111

I assumed you were actually talking about C and were just spelling it like a retard.

Please explain what the fuck ^C is and why anyone should give a shit about it.

>> No.63314114

C is very bloated compared to brainfuck. Why do you need C?

>> No.63314116

C now is fine as a target

>> No.63314120

It looks literally nothing like Lisp. Opinion discarded.

>improve on C's many mistakes.
The only changes C is willing to make are relaxing the standards even more for easier compiler optimizations at the expense of people actually trying to use the language.

>> No.63314123

>C's many mistakes.
name one
>inb4 pointing out numerous flaws that you shouldn't actually call mistakes because that would be anachronistic

>> No.63314126

>Why do you need C?
you need C to run an OS

write an OS in brainfuck

i'm waiting.


>> No.63314138

>they don't count if i don't agree with them
desu, i think it actually is more ocaml like than Lisp.

>> No.63314140
File: 149 KB, 750x1000, throwpillow,small,750x1000-bg,f8f8f8.jpg [View same] [iqdb] [saucenao] [google] [report]

>"you need C to run an OS"
>he didn't write his OS in haskell
literally what are you even doing here

>> No.63314141

The context was about type system, why did you shift the topic?

And of course, you don't need to lie that you are writing an OS. Tell me why you need bloated C when there is brainfuck?

>> No.63314149

Discarding C's historic degree of optimization, what makes you say that? I'm assuming you've arrived at a practical perspective (e.g. C will be the only language that fulfills this requirement in the near future). There are some improvements that could be made to the language proper. I'm only talking about front-ends, essentially. Do you write C at your job? I write Nim, compile to C, comment, and submit that.

>> No.63314155

>>they don't count if they're anachronistic

for example C should have had generics and is worse off without them, I fully acknowledge this, but how exactly does that mean not including them was a mistake? calling it that would be anachronistic because it's not so much a matter of choosing to omit them as it is of having not invented them yet at the time

>> No.63314162

Modules then.
Let's start there.
>to omit them as it is of having not invented them yet at the time
You really going to pretend Algol doesn't exist?

>> No.63314168

algol didn't have generics

>> No.63314171

Ops, I don't think the cnile is going to be able to answer that. They are a bit too "simple minded".

>> No.63314177

>desu, i think it actually is more ocaml like than Lisp.
Yes, and OCaml and Lisp really don't look the same

>having not invented them yet at the time
System F was discovered independently by logician Jean-Yves Girard (1972) and computer scientist John C. Reynolds (1974).
First appeared 1972


TBPH, C with ocaml style modules + functors would be really neat. Even without generic types/functions you can get a lot of near-metaprogramming power with functors.

>> No.63314190

see: >>63314168

i haven't heard of system f therefore it is obscure

>> No.63314193

Jesus fucking christ just stop posting

>> No.63314200

>>>63314171 (You)
>see: >>63314168
I didn't as you about generics. I asked you a simple question on the premise that C is more bloated than brainfuck.

>> No.63314201

Well not in thy typical sense no, but it did have generic operators you could define.

>> No.63314204


luhncheck(n) = n |> digits |> enumerate |> collect .|> (x -> (1 + ((x[1] + 1) % 2))*x[2]) .|>
digits .|> sum |> sum |> x-> x % 10 == 0

@assert luhncheck(49927398716) == true
@assert luhncheck(49927398717) == false
@assert luhncheck(1234567812345678) == false
@assert luhncheck(1234567812345670) == true

>> No.63314205

system f was a mathematical theory not a programming language, your argument is invalid

>> No.63314212

>I didn't as you about generics
then you didn't address the example i gave
therefore you really shouldn't have pretended like you did:
>You really going to pretend Algol doesn't exist?

>> No.63314216

You're right, but I'm just disappointed at how type abstraction is a concept as old as C yet Go still doesn't have generics

>> No.63314217

I'm slightly mad that the iterator returned from enumerate doesn't let me do broadcast multiplication, so I have to allocate an intermediate array with collect. Otherwise, Julia would fuse every loop here.

>> No.63314225

>then you didn't address the example i gave
What example answers my question?

>> No.63314227


>> No.63314242

Which of these meme languages are worth learning: GO, Haskell, Rust

>> No.63314250

an unfair comparison: c is a language, not a concept

the corresponding concept -- low level imperative programming -- is a concept MUCH older than type abstraction (see: charles cabbage)

go sucks regardless though

>> No.63314252

Haskell is the only one of worth there.

>> No.63314253

All three. They each take quite different approaches to language design and will contribute to your understanding of programming languages at large.

>> No.63314259

All three.

>> No.63314265

this is exactly why i'm interested in them but theres so much shit flinging about languages that its hard to tell if something is actually bad or not

>> No.63314266

your question is not the issue here

you can't just ask a question after someone has already said something and then act like the thing they said was supposed to be an answer to that same question you hadn't even asked yet at the time

>> No.63314277

hey cnile are you just going to ignore this sick burn? >>63314071

>> No.63314280

That's mostly epic memes.
All three have real downsides but then again so does every other language.

>> No.63314281

No. That's how answering a question is. You just don't have an answer to my question. Plain and simple.

So next time you spew ``mah bloat" joke as an excuse, recall that you don't have a proper basis for that.

>> No.63314284


Can some one help me de-brainlet this?

I am about to figure out how to put this into a gui and then into an executable for my boss tomorrow, but I am pretty sure as soon as he sees this he will fire me.

Pls help an employed python programer.

searchterm = input('what u lookin for? : ')
searchterm = searchterm.upper()
if os.path.isdir(filelocation) == True:
files = os.listdir(filelocation)
for file in files:
if file.endswith('.xlsx'):
for i in files_xls:
wb = openpyxl.load_workbook(i)
sheets_to_search = wb.get_sheet_names()
for sheet in sheets_to_search:
sheet = wb.get_sheet_by_name(sheet)
for cells in sheet['A1':get_column_letter(sheet.max_column)+str(sheet.max_row)]:
for cell in cells:
cell_upper = str(cell.value).upper()

if searchterm in cell_upper:
row = str(cell.row)
for results in sheet['A'+row :get_column_letter(sheet.max_column)+row]:
line = []
for result in results:


>> No.63314286

but anon, hask-lel is not of worth
>inb4 the angry girlmale says "muh moan ads, muh lamb duhs"

>> No.63314288

>Can some one help me de-brainlet this?
Yes by ditching python

>> No.63314299

To be honest, Haskell is of the least worth of those 3

>> No.63314301

it teaches you a lot of new things in FP even if its syntax is wonky. Go has nothing new to offer and Rust can be passed on until v2 comes out.

>> No.63314309


jesus man, try separating that shit out into functions, no one wants to read a decanested for loop

>> No.63314313

>That's how answering a question is
it's not, you literally said:
>>to omit them as it is of having not invented them yet at the time
>You really going to pretend Algol doesn't exist?
the implication being i was wrong because algol had modules
despite the fact that i was actually right because i never said anything about modules and all i said was it doesn't have generics
>inb4 "but *I* said a thing about modules"
that was after the fact and therefore has no bearing on the matter

>> No.63314319

Stop using memesnek for starters.

>> No.63314333

but anon they are not new things and it didn't teach me shit
it's like c++: stealing a lot of good ideas, packing them together in one disgusting looking package deal, and acting like it invented them
the other two languages are also trash as well of course

>> No.63314347

if it's your first FP, as it is with a lot of people, yes.

>> No.63314352

Why the fuck are you bringing these up? Are you replying to the wrong anon? Here is how the conversion is going, in case you are not in the same page:

You claimed that is a simple language and it's not bloated like others.
I asked why do you need C if you don't like bloat because brainfuck is much more simple and less bloated than C.
Then you shifted the topic to OS dev.
Then you shifted the topic to modules, generics, algol etc.

My question remains unanswered.

>> No.63314356

why the fuck would you ever make declarative c++ your first fp

>> No.63314365

>You claimed that is a simple language and it's not bloated like others.
not me
>I asked why do you need C if you don't like bloat because brainfuck is much more simple and less bloated than C.
not me
>Then you shifted the topic to OS dev.
not me
>Then you shifted the topic to modules, generics, algol etc.
this was me

>> No.63314370


Where should I make the functions?

I didnt plan this out at all before hand so I cant even figure out how to make the program pause to display the results.

I need help.

>> No.63314372

He thinks you are me, as i brought them up >>63314162

>> No.63314375

Anon was talking about Haskell.

>> No.63314379
File: 2.73 MB, 4160x2340, IMG_20171110_233134464.jpg [View same] [iqdb] [saucenao] [google] [report]

Being a massive faggot

>> No.63314386

i know, that's what I'm talking about too
see: >>63314333
>it's like c++: stealing a lot of good ideas, packing them together in one disgusting looking package deal, and acting like it invented them

>> No.63314402
File: 28 KB, 200x209, sentientcabbage.gif [View same] [iqdb] [saucenao] [google] [report]

>(see: charles cabbage)

>> No.63314407

Wipe the monitor, pajeet

>> No.63314443
File: 579 KB, 612x816, 1505960153211.png [View same] [iqdb] [saucenao] [google] [report]

Making programming great again

>> No.63314506

redpill me on map vs reduce vs filter

also you guys just missed it: https://www.youtube.com/watch?v=FMLDTdmvXv4

>> No.63314510


It means you have like 10 for loops all up in each other. I'll clean your shit up a bit after I finish my sandwich and show you

>> No.63314545

bless you. I love you long time.

>> No.63314700

create separate functions to make this more readable, for example
files_xls = getAllXlsFilesFromDirectory(dir)

do this for every part of your giant loop which could be a separate functions

>> No.63314796


Ok, I broke it down into functions, now just tell me how to post code on this webzone

>> No.63314878

[code] [\code] [\code][/code]

>> No.63314884

but front one doesnt have slash

>> No.63314889


what's the _INCLUDED
code blocks auto writes it, code runs without it
whats a good reason to keep it or not to
>t.someone getting his toes wet in the sea of sea++

>> No.63314893

My thoughts:

Go doesn't do anything novel. Concurrency with channels is a concept you could learn off a single wikipedia page. Besides that, it's just yet another imperative algol language.

Haskell contains and develops contemporary FP ideas and concepts. You can learn many of the same concepts from languages like Scheme or OCaml, plus many interesting type system things exclusively in Haskell (you will miss out on a few things from the other languages).

Rust is basically just C++ combined with Haskell, plus the borrow checker. You would be better off learning Rust's FP-y concepts from an actual FP language (see previous paragraph). The borrow checker is the only completely novel thing about Rust, but it doesn't significantly influence how you design programs. I wish that people tried harder to find ways to design programs *around* linear types, but in Rust it just feels like a crutch that you can usually ignore but sometimes it bites you and makes it awkward to implement algorithms. That being said, Rust is still an excellent step up from C++ and its nice to see a language other than ML/Haskell embrace variant types.

>> No.63314925

def files_to_xlsx(files):
for file in files:
files_xls = []
if file.endswith('.xlsx'):

return files_xls

def process_cells_doing_whateverthefuckyourdoing_i_dont_know_excel(cell , wb):
cell_upper = str(cell.value).upper()

if searchterm in cell_upper:
row = str(cell.row)
for results in sheet['A'+row :get_column_letter(sheet.max_column)+row]:
line = []
for result in results:


def sheet_to_cells(sheet , wb):
sheet = wb.get_sheet_by_name(sheet)
for cells in sheet['A1':get_column_letter(sheet.max_column)+str(sheet.max_row)]:
for cell in cells:
process_cells_doing_whateverthefuckyourdoing_i_dont_know_excel(cell, wb)

def process_xls(file_xls):
wb = openpyxl.load_workbook(file_xls)
sheets_to_search = wb.get_sheet_names()
for sheet in sheets_to_search:
sheet_to_cells(sheet, wb)

#I guess this would be main

searchterm = input('what u lookin for? : ')
searchterm = searchterm.upper()
if os.path.isdir(filelocation) == True:
files = os.listdir(filelocation)

files_xls = files_to_xlsx(files)

for i in files_xls:

I didn't refactor it at all other than encapsulating some of it into functions. It should be easier to look at now. Other than it being ugly what was your problem? Does it even work?

>> No.63314936


Ah, I forgot to pass in the search term, I'm sure you can fix that

>> No.63314938

it checks if LCCP_H.. is defined
if it isn't, it does everything between #ifndef and #endif
if it is, it skips over that block

it ensure that things will only be included once

>> No.63314959

Obligitory Racket solution
#lang racket
(require rackunit)

(define (digit c)
(- (char->integer c)
(char->integer #\0)))

(define (luhn-sum s)
(for/sum ([c (reverse (string->list s))]
[k (in-cycle '(1 2))])
(define d (* k (digit c)))
(+ (quotient d 10)
(remainder d 10))))

(define (luhn s)
(zero? (remainder (luhn-sum s) 10)))

(check-true (luhn "49927398716"))
(check-false (luhn "49927398717"))
(check-false (luhn "1234567812345678"))
(check-true (luhn "1234567812345670"))

>> No.63315000

First off:
def get_excel_files(filelocation):
return [file for file in os.listdir(filelocation) if file.endswith('.xlsx') ] if os.path.isdir(filelocation) else []

Next, stop opening the first file once for every other excel file in your folder, that is stupid as fuck. Your code seems to show a complete misunderstanding of how nested loops work. Please stop being so stupid. Also please stop testing for equality with True with True on the right hand side, you are just begging for an accidental assignment.

Also stop using for declare empty list -> for loop + append so much, you are much better off using list comprehensions for this kind of task.


def workbook_sheets(wb):
return [wb.get_sheet_by_name(sh) for sh in wb.get_sheet_names()]

def filtered_cells(sheet,searchterm):
""" Generators that yield filtered cells. """
grid = sheet['A1':get_column_letter(sheet.max_column)+str(sheet.max_row)]
for cells in grid:
for cell in cells:
if searchterm in str(cell.value).upper():
yield cell

def result_lines(sheet,row):
"""Generator yielding the results for a given sheet and row """
resultgrid = sheet['A'+str(row) :get_column_letter(sheet.max_column)+str(row)]
for results in resultgrid:
line = [line.append(result.value) for result in results]
yield line

(none of the functions above have side-effects by the way, they are read-only).

which collapses the final script to:

searchterm = input('what u lookin for? : ').upper()
files = get_excel_files(filelocation)
for file in files:
wb = openpyxl.load_workbook(i)
sheets = workbook_sheets(wb)
for cell in filtered_cells(sheet,searchterm):
for line in result_lines(sheet,cell.row):

>> No.63315022

I was so deep in the loops I couldn't figure out how to pause the program after the search was done. everywhere I put the sleep command I essentially required 1000s of imputs to get past it.

>> No.63315037

result_lines should be:

def result_lines(sheet,row):
"""Generator yielding the results for a given sheet and row """
resultline = sheet['A'+str(row) :get_column_letter(sheet.max_column)+str(row)]
for results in resultline:
yield [result.value for result in results]

>> No.63315041

I hope he fires you desu

>> No.63315096

Also, I can reduce the size of this code by half using itertools cleverness, but I'm intentionally minimizing the number of features I'm using here.

>> No.63315103

>but I'm intentionally minimizing the number of features I'm using here.

I appreciate this more than you know.

>> No.63315282

It's been ~8 years since I touched an IDE, I prefer to program in nano, vim, or even just gedit. But I'm starting a project in java with some acquaintances from my Uni tomorrow and they're apparently all going to be using one IDE or another. I feel likeit's going to be beneficial to make myself use one for this, but which one do I pick? There's so goddamn many. I'm running arch, so anything I can grab from the official repo or the AUR would be ideal.

>> No.63315295

intellij is pretty comfy

>> No.63315315

How resource-intensive is it? The things that turned me off of IDEs in the first place are taking ~30 seconds to open a ten-line file, or being super cluttered graphically and eating up all my memory.

>> No.63315325

Why would working with others mandate you using a specific text editor or IDE?

>> No.63315337

Last time I worked with somebody on a project where they were using an IDE and I wasn't it was a pain in the ass digging through the folders and project files and whatever extra stuff the IDE threw in to get to the .c files I actually needed.

>> No.63315343

Use a proper build system, idiot.
Don't let the IDEfags drag you down.

>> No.63315362

Not for compiling. For editing. The IDE guy would just push his whole project folder to git. I don't have higher hopes for the chucklefucks I'm gonna be working with this time around.

>> No.63315393

Tell him to stop being a retard.
If you let him do that, then the only way you can "get by" is to use the exact same garbage IDE as him.

>> No.63315400

Fair enough. Thanks for the input anon.

>> No.63315467
File: 96 KB, 420x248, 1466894843388.png [View same] [iqdb] [saucenao] [google] [report]

Why does Rust not have function overloading and default argument? Pretty shit desu ne
struct Rectangle
width: u32,
height: u32,

impl Rectangle
fn new(w: u32, h: u32) -> Rectangle
Rectangle {
width: w,
height: h,
fn new_square(side: u32) -> Rectangle
Rectangle {
width: side,
height: side,
fn area(&self) -> u32
self.width * self.height
fn can_hold(&self, given: &Rectangle) -> bool
(self.width >= given.width && self.height >= given.height)
|| (self.height >= given.width && self.width >= self.height)

fn main()
let rec1 = Rectangle::new(4, 6);
let rec2 = Rectangle::new_square(3);

println!("{}", rec1.can_hold(&rec2));

>> No.63315474

If you're working in Java-land, I strongly suggest using an IDE. They do help quite a lot by being aware a codebase and making methods easily discoverable with tab-autocomplete.

I'd second >>63315295 and suggest intellij. One reason for this over other IDE's besides nice features is Kotlin support. You will want to kill yourself working with Java and Kotlin is a nice way to reduce the burden for some classes without really increasing the complexity of the project since it interops so well with Java.

It also has the best Scala integration afaik. Clojure on the other hand is pretty much an emacs-only language since it's a lisp.

>> No.63315488

Function overloading and default argument are shit and generally useless.
They just serve to obscure useful information from the programmer.

>> No.63315489

>If you're working in Java-land, I strongly suggest using an IDE.
Same goes for older languages like C#, C/C++, python etc as well.

>> No.63315490

Because traits let you do that. Also, Rustaceans (I hate that term) really love the builder pattern.

>> No.63315497

Why are you grouping two completely different languages together?
Also, are you seriously implying that the typical C programmer is an IDE cuck?

>> No.63315507

>the typical C programmer is an IDE cuck?

>the rare C programmer with a job

Ask me why

>> No.63315523

>>the rare C programmer with a job
I'm a C programmer, and I am employed as such.

>> No.63315532
File: 44 KB, 636x616, 12631280.jpg [View same] [iqdb] [saucenao] [google] [report]

Employed Haskell programmer reporting in.

>> No.63315536

Why do you always use that avatar.

>> No.63315631

>If you're working in Java-land, I strongly suggest using an IDE
As a die hard emacs fan who uses it for virtually every language, I still agree.
Java is so shit you actually need an IDE to get anything done. The IDEs like Eclipse/IntelliJ have a bunch of effort put into them. They are occasionally buggy and shit, but they have more features than the lackluster support in emacs/vim. Pick your poison I guess, but I've found it better to put down Emacs for my Java assignments in uni

>> No.63315715

Man, I fucking hate Rust's syntax. Like, wtf is this shit
w: u32, h: u32

I hate that label crap. I much prefer Go's syntax where I don't need to put a useless semicolon and I can just specific the types like so
w, h uint32

The declaration has less useless symbols and is more clear and direct. I also hate the fucking -> shit for return values. Say what you will about Go's design, but Go has top notch syntax, much cleaner than Rust's. I also prefer func over fn simply because fn is too short to be visible enough to the reader.

>> No.63315743

I'm not a huge fan of Rust, and I still think Rust looks much better than Go here. Go is shit.

>> No.63315759

That's what impl is for.

>> No.63315765

>fucking -> shit for return values
top brainlet. Even C++ has embracing trailing return type notation. And they aren't backing down.

>> No.63315807

func (foo Foo) myMethod(bar Bar) (Baz, Qux)
Go syntax is shit

>> No.63315823
File: 10 KB, 566x484, comfy.png [View same] [iqdb] [saucenao] [google] [report]

I don't know about you, but I think Go looks comfy.

>> No.63315828
File: 32 KB, 590x636, 21272365.jpg [View same] [iqdb] [saucenao] [google] [report]

Interesting. Is this coming for C++20 or later?

>> No.63315839

>his Area and Canhold is not hidden under Rectangle namespace
How come go is so shit, guys?

>> No.63315858

new thread pls

>> No.63315860

What are you even talking about?

>> No.63315864

Doesn't go have namespaces? Does it have function overloading? Don't tell me it has none.

>> No.63315869

Have you achieved satori yet, /dpt/?

>> No.63315874

That's fine.

I'm more concerned about the function name new being taken if anything. That and godawful syntax for the argument that has dot notation in the Area and CanHold functions.

>> No.63315877

It does have namespaces. It doesn't have function overloading per se, because it doesn't record the argument signature of functions, but it does for methods. This means you can have methods of the same name with different types received, which is important in interfaces.

>> No.63315888

Can't master define-syntax for some reason.

>> No.63315892

New being taken is a none issue because of namespaces. If New is in a different package you can reference it differently. If I have one package called rectangle and another called circle I can do this
import (

func main() {
circ := circle.New(3)
rec := rectangle.New(3, 4)

>> No.63315904

struct Rectangle {
height : i32,
width : i32

impl Rectangle {
fn area(self) -> i32 {
self.height * self.width

fn canHold(self, other : Rectangle) -> bool {
(self.height >= other.height && self.width >= other.width)
|| (self.width >= other.height && self.height >= other.width)

fn main() {
let a = Rectangle{ height : 10, width : 20 };


Rust wins again.

>> No.63315919

Okay, now what if there was a package called circle and you wanted to call a function named new declared in the package?

>> No.63315935

Literally the same syntax
x := circle.aMethod()
y :=> circle.aFunction()

>> No.63315943

What do you mean? If there were two packages called circle? Go allows you to rename packages like so
import (
mc "math/circle"

func main() {
circ1 := circle.New(3)
circ2 := mc.New(4)

>> No.63315957

kek so basically you don't know if you have called a function from another package or a method from a struct

Go somehow manages to shame itself no matter what it tries

>> No.63315974

You can't? If you name a variable the same as a package, it shadows the package in the scope of the variable. So no, there is no ambiguity.

>> No.63315975
File: 13 KB, 184x184, 882f3c4f2f3310c0f2dd8f99dbbd776dab470978_full.jpg [View same] [iqdb] [saucenao] [google] [report]

Hopefully Go2 will fix it

>> No.63315978

In Haskell this is just
data Rectangle = {w :: Int, h :: Int} deriving (Show)

new w h = Rectangle {w = w}

newSquare w = new w w

area (Rectangle {w,h}) = w*h

canHold (Rectangle {w1,h1}) (Rectangle {w2,h2}) = w1 >= w2 &&h1 >= h2 || w2 >= w1 && h2 >= h1

main = println canHold r1 r2 where
r1 = new 4 6
r2 = new 3

>> No.63315980
File: 5 KB, 668x379, clock_1.png [View same] [iqdb] [saucenao] [google] [report]

>> No.63315983


new w h = Rectangle {w = w,h = h}

>> No.63315991

This has fewer Int declaration than the Go version due to type inference, without the annoying assymetry.

>> No.63316009

This pretty cool I guess. I'm not really fond of the offside rule though.

>> No.63316016
File: 463 KB, 1070x601, 1489876205649.png [View same] [iqdb] [saucenao] [google] [report]

>be me, a numale rustlet
>figure i should try doing real work for once instead of the usual fizzbuzzing
>decide to write a opengl render
>every single opengl call is unsafe
>no problem, i'll just put them inside unsafe blocks and hide them behind a nice interface
>boy, my renderer sure is safe now
>and by extension, so is my entire program
>indirectly touch the "safe" renderer from different thread by accident
>get fucked
Can't believe I fell for this fucking meme.

>> No.63316042

Deprecated. Use Vulkan + OpenCL

>> No.63316047


>> No.63316088

>b-b-but opengl is deprecated
>muh vulkan
That's just too much hassle.

>> No.63316107

But it's true. Vulkan (which has OpenCL merged within) is the future. Especially now that Intel is hosting AMD GPU nowadays.

>> No.63316132

It's too long and it's split over too many modules to post here, and either way, I figured out the problem (which was coming from something triggering texture generation from a non-rendering thread). But my overall point is that I'm not sure how to deal with this situation. Giving the rendering interface a false facade of safety seems wrong, but if I mark everything rendering-related as unsafe, half of the program will have to be marked as unsafe.

>> No.63316142

New thread.

>> No.63316229

Jesus fucking christ. How is adding yet another way to do the same thing going to make that language any less shitty?

Name (leave empty)
Comment (leave empty)
Password [?]Password used for file deletion.