[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 339
Thread images: 24

File: haskell..png (7KB, 397x131px) Image search: [Google]
haskell..png
7KB, 397x131px
Previous Thread: >>57110498

What are you working on, /g/?
>>
>>57113677
Thank you for using an anime image
>>
File: ass.png (60KB, 757x627px) Image search: [Google]
ass.png
60KB, 757x627px
>>57113677
>>
File: 1475143072125.jpg (15KB, 448x283px) Image search: [Google]
1475143072125.jpg
15KB, 448x283px
>>57113688
You're welcome
>>
>>57113677
First for rewriting Haskell in Python
>>
Any good resources for learning how to make good Makefiles?
>>
>>57113720
https://www.gnu.org/software/make/manual/make.html
>>
>>57113731
Thanks but how does a good Makefile look like?
>>
File: AiVRDmR[1].jpg (28KB, 758x342px) Image search: [Google]
AiVRDmR[1].jpg
28KB, 758x342px
>>57113677
Does someone understands VHDL? I'm forced to """"""""'learn""""""" this shit with 30min class a week with a shit teacher and shit FPGAs and no material nor incentive. I know VHDL isn't "programming" but still. What I need to do is simple, make a device that gives 1 to 5 in binary in the rising edge of the clock. (The clock is manual so it doesn't do this 5 bagazilion times a second)

I've already done it with description, now I need to do a behavioral approach and VHDL has a retarded syntax which I don't know because the teacher sucks balls and nobody cares for HDL on the interwebs. The decoder is ready, the top file is ready, the rising edge is ready. I have no idea of what I'm doing. I'm forced to use quartus because of > alterra and quartus error reporting isn't helping.
EA= current state
PE=Next state
Contagem=Countdown
library ieee;
use ieee.std_logic_1164.all;
entity FSM_Conta is
contagem: out std_logic_vector(3 downto 0);
clock: in std_logic;
reset: in std_logic;
end;
architecture bhv of FSM_Conta is
type STATES is (E0, E1, E2, E3, E4);
signal EA, PE: STATES;
begin
P1: process(clock, reset)
begin
if reset= '0' then
EA <= E0;
elsif clock'event and clock= '0' then
EA <= PE;
end if;
end process;
P2: process(EA, PE)
begin
case EA is
when E0 => '0001'
contagem <= '0001';
PE <= E1;
when PE => '0010'
contagem <= '0010';
PE <= E2;
when PE => '0010'
contagem <= '0011';
PE <= E3
when PE => '0011'
contagem => '0100';
PE <= E4
when PE => '0100'
contagem =>'0101';
PE <= E0

end case;
end process;
end bhv;
>>
>>57113770
Depends on your preference. Many people swear to recursive Makefiles (one for each subfolder), I hate that and prefer one "master" Makefile for each logical unit of a project. I also try to write them as generic as possible, so I don't have to modify the makefile whenever I add or remove a file, for example.

Also, in my opinion, source and build should be separate, and I think intermediate steps should be separate from source (meaning: i place object files in a separate catalogue). I know many people will disagree with me there, because Make has a concept of intermediate steps itself.
>>
>>57113802
recursive make is absolutely disgusting and harmful

http://aegis.sourceforge.net/auug97.pdf
>>
>>57113798
I haven't done VHDL in ages, but two tips that helped me:
1) everything happens in parallel, which is why the syntax is retarded
2) use the quartus tool to visualise the circuit, if it synthesizes to a giant multiplexer instead of nice sequential logic gates, you're doing something wrong
>>
>>57113677
How does functional programming compare to OOP?
How FP may be more efficient than OOP?
>>
>>57113842
Thank you for the link.
>>
>>57113864
Don't. I know you are that troll from the previous thread, so just don't.
>>
>>57113860
The problem is that it's not even synthesize anything because of syntax errors. Allegedly missing ";"s and other things when they look right. Also how do I visualize the circuit? (You have no idea of how bad this class is, it's literally copy one thing from a slide into quartus and it werks :^) so when we come to simple shit like this I'm left with my dick in my hands, they also teach barely anything about quartus, it's a literal cargo cultĀ“)
>>
File: discord-logo.jpg (36KB, 1080x675px) Image search: [Google]
discord-logo.jpg
36KB, 1080x675px
dpt discord @ https://discord.gg/2PCRq
>>
>>57113864
FP covers a managerie of more composable techniques that leads to a great deal of modularity.

OOP relies heavily on such things as type/method associations and inheritance and many things that are very bad for composability and lead to very closed, fixed designs.
>>
>>57113890
>Also how do I visualize the circuit?
I don't remember, it's some option in the menu IIRC.
>>
>>57113597
>>
>>57113879
FUG U XDDDDDDDD
>>
>>57113905
Ok thanks. Also fuck I forgot to remove my /vg/ ironic shitposting trip. Sorry
>>
File: Screenshot_2016-10-17_15-44-21.png (100KB, 885x723px) Image search: [Google]
Screenshot_2016-10-17_15-44-21.png
100KB, 885x723px
Just finished refactoring and optimising a Go video and audio thumbnailing/meta retrieval library.
>>
>>57113906
That's entirely location specific. Where I live, it's impossible because everyone has a degree since university is """free""".
>>
>>57113924
>d, err = ...
>if err != nil
..
Monads would improve this.

>if (f ==nil)
...
(x2)
Monads and FP would improve this.

>(if f == nil)
...
Monads would improve this.
>>
>>57113924
is that peacock?
>>
>>57113943
Maybe
>>
>>57113966
I see what you did there.
>>
>>57113966
>>57113972
Either way, monads would help
>>
>>57113943
Monads would make this unreadable, unmaintainable and slower X3

>>57113951
A what?
>>
>>57113919
>>57113905
>>57113890
Ok the error seems to be here and cascades down because it doesn't recognizes "contagem"
library ieee;
use ieee.std_logic_1164.all;
entity FSM_Conta is
contagem: out std_logic_vector(3 downto 0);
clock: in std_logic;
reset: in std_logic;
end;

It says :
Error (10500): VHDL syntax error at FSM_conta.vhd(4) near text "contagem";  expecting "end", or "begin", or a declaration statement
>>
>>57113980
no they wouldnt
>>
>>57113980
monads would be just as readable, more maintainable (changing the monadic interface would propogate those changes to everywhere you use the monads (since you're using the function abstraction for what it was made for)), and the performance difference would be negligible
>>
>>57113677
I think i'm actually starting to have fun with my audio project.
Even though progress is horribly slow that would get me fired if i was working for an employer.
>>
>>57113798
using clock'event and clock='0' means your clocked part is 'active low', if you want state transitions during a rising edge use risingedge(clk) in your process
i have no memory of the state transition case-syntax so can't help there
>>
>>57114001
Yes, they would.
>>
>>57114007
>>57114001
Stop pretending that monads are superior in every aspect, they are nice and neat abstractions but for bare metal system programming they obscure things for the programmer.
>>
>>57114019
Oops sorry it was a in lower edge. It doesn't matter, it will only affect if it goes forward when you press the button or when you press and release it. See
>>57113996
>>
>>57114028
>he says, as he writes in a garbage collected language with green threads
>>
>>57114034
I hate Go with a passion (not because of GC, but the shitty import/include system where you pull code from github with no concept of versioning), but saying that "monads would be better, please rewrite everything in a language that has maybe monads as part of the language" doesn't help anyone you.
>>
>>57114032
entity is
port(
...
...
)
>>
File: 91i328.jpg (142KB, 740x740px) Image search: [Google]
91i328.jpg
142KB, 740x740px
>>57114043
>maybe monads as a part of the language
Absolutely disgusting.
>>
>>57114059
Fuck! Forgot to do the portmap in the top.vhdl file. WIll try and report back. Thanks anon
>>
>>57113691
I saw this on stackexchange workplace but it was about a diva type person not a she. Why would you specify the gender?
>>
Where to start with Python and basic GUI? Built-in tkinter module or what?
>>
>>57114101
Why are you assuming gender, shitlord?
>>
>>57114103
kivy
>>
Really makes you think...

https://www.reddit.com/r/haskell/comments/45q90s/is_anything_being_done_to_remedy_the_soul/
>>
>>57114150
i havent noticed this
>>
>>57114043
My point is that Go should have generics desu.
>>
Currently working on a haiku generator.

Don't fall for the uni meme, week 6 and we haven't even hit looping constructs on Java
>>
File: Quark_2375.jpg (100KB, 417x393px) Image search: [Google]
Quark_2375.jpg
100KB, 417x393px
>>57114072
>there is a difference between ' and " and they are both used in similar circumstances
>you literally have to download 3 gb of shit to do something and it can't tell when you use ' or "

Even C in Vim is smarter than this. Jesus fucking Christ.
>>
>>57114163
HKTs when
>>
>>57113798
Second process shouldn't have pe in the sensitivity list because it is the one driving it. Also this could be done with 1 process with 1 state signal and it would be cleaner.
>>
>>57114205
Yeah I noticed my retards. I fixed it, now I'm hunting errors down oin the top file. Thanks anon
>>
Is there a word for taking the binary value of one variable and putting it into another variable of a different type? I've got a function that does this with doubles to u64s but I can't think of a name.
>>
>>57114242
Like casting?
>>
>>57114242
reinterpret cast
>>
File: dolibarr_logo1.png (23KB, 363x116px) Image search: [Google]
dolibarr_logo1.png
23KB, 363x116px
Does anyone got any experience developing custom modules for Dolibarr?
>>
>>57114178
probably "Google programmers aren't smart enough to use this"
>>
>>57114169
What's wrong with C in Vim
>>
File: simon.jpg (80KB, 536x649px) Image search: [Google]
simon.jpg
80KB, 536x649px
>>57113677
>>
https://skillsmatter.com/skillscasts/8392-a-reflection-on-types-simon-peyton-jones-microsoft-research

>Haskell has had dynamic types for ages, in the form of the Typeable class, but recent developments has made it feasible to support type-indexed type run-time type representations.

>type-indexed type run-time type representations

What did he mean by this?
>>
How much of a pain is it to develop a Windows GUI application using Haskell?
>>
>>57114530
depends what you want to achieve
>>
>>57114530
Nightmare mode
>>
>>57114534
Image manipulation program.

More than a few Windows system calls.
>>
>>57114546
http://book.realworldhaskell.org/read/gui-programming-with-gtk-hs.html
>>
>>57114546
image processing in Haskell sounds slow as fuck.
>>
>>57113891
The invite expired, could you make a new please?
>>
>>57114561
people do it in python
>>
>>57114584
I know.

It's slow as fuck.
>>
>>57114574
>discord supposedly filled with "programmers"
>can't post permanent invite link
why bother going there?
>>
>>57114589
we don't want the invite to be shared everywhere.
>>
>>57114585
haskell has unboxed vectors
>>
>>57114596
how do you mutate them?
>>
>>57114601
monads
>>
>>57114620
i presume that involved bound checking.

I think one of my issues with haskell, is that it hides a lot the stuff regarding how long code takes to execute. You need to have deep knowledge of how code is optimised by the compiler.

How intuitive is it then every time a monad creates a new universe, that that really ends up just being a single value mutation at run time?
>>
>>57114574
maybe, who are you ?
>>
>>57113677
How does Scala's type system compare to Haskell's?
>>
>>57114638
no, you use a monad that can execute primitive ops exposed in a library i cant remember the name of
>>
>>57114656
Scala is a distaster
https://www.youtube.com/watch?v=uiJycy6dFSQ
>>
>>57114657
>no
no what?
>>
>>57114655
I am a NEET who wants to complain about languages with other people
No I'm not indian
>>
File: 1476627340286.png (198KB, 599x607px) Image search: [Google]
1476627340286.png
198KB, 599x607px
>>57114666
go away satan
>>
>>57114666
https://hackage.haskell.org/package/ghc-prim-0.4.0.0/candidate/docs/GHC-Prim.html
>>
>>57114682
do you have any github/bitbucket?
>>
>>57114574
https://discord.gg/ssqhh
>>
>>57114178
Once Go gets dependent types.
>>
>>57114706
Actually I don't even know how to program and want to shitpost and trigger you guys
Ez join :^)

>>57114717
Thanks
>>
>>57114663
Thanks, watching it now
>>
>>57114150
>At work we have about 250kloc of Haskell code compiled with ghc, and 2.5Mloc compiled with our own Haskell compiler. So I can offer some observations both as a ghc user and a compiler writer.
>ghc compile times have pretty consistently gone up with every new release of ghc. Usually 5-10%, unless there's a ghc performance bug (and they get fixed). I've done these measurement since around 2009, but sadly I never saved any results.
>The performance of the compiled code has pretty consistently gone down with every ghc release. Again, I've saved no numbers. Also around 5% per release.

I don't even. Haskell fags will defend this.
>>
>>57114829
>250k loc
>haskell
>>
>>57114862
You mean 2.75 million.
>>
>>57114862
>2.5Mloc
>Haskell
>>
File: fuck.jpg (79KB, 960x720px) Image search: [Google]
fuck.jpg
79KB, 960x720px
>hey guys, i think this language we're making might be too easy
>I know! Let's make it so that some variable types are handled differently than others!
>>
>>57114882
>he doesn't understand the difference between value and reference types
hmm
>>
>>57114829
Holy shit.

Wonder what the project is though...
>>
>>57114882
Fuck you, literally all non-meme languages do that.
>>
>>57114946
D does that and is a meme language
>>
>>57114946
???????????????????????
>>
>>57114970
I didn't claim all meme langugaes do not do this. learn to binary operations.

>>57114975
Spit it out you stupid fuck.
>>
>>57114903
what did you want it to do, raise typeError?
I actually like this, as you can easily do
my_list = 3*[A] + 4*[B]
>>
>>57114903
Is that really how python behaves?
>>
>>57115027
Multiply each element of the vector tbqh
>>
>>57115027
>what did you want it to do, raise typeError?
that would be nice
>>
>>57115044
but what if the list contains nonnumerical elements?
you can ofcourse use numpy.matrix if you want this behavior or:
map(lambda x:x*3, mylist)
>>
>>57113677
got some free server resources, what should I do with it ?
>>
Why does everything about Haskell scream "unpleasant neckbeards with zero social skills?"
>>
>>57115109
because of all the unpleasant neckbeards with zero social skills that use it.
>>
>>57115109
Haskell is a nice language
>>
File: c_0.png (25KB, 195x195px) Image search: [Google]
c_0.png
25KB, 195x195px
How do I read multiple values separated by a space in one line with an overloaded >> in C++? (aka operator chaining

Here's what I have
istream& operator>>(istream &input, MyClass &rhs) {
int temp;
input >> temp;
rhs.insert(temp);
return input;
}


I use it like that:
   cout << "Enter multiple ints:  " << endl;
cin >> A;


I enter
1 2 3 4 5


Then I press enter, but it only reads the first number (1).
>>
>>57115291
Do you want multiple values to be put into A?
if so, do lots of >>s in the operator

Otherwise
cin >> A >> B >> C;
>>
>>57115291
>c++
>cin-cout
>being this new

you don't even need to overload that
>>
>>57115109
It doesn't though?
Neckbeards aren't usually the ones who like math.
>>
>>57115413
Meh
>>
>>57115362
Yes, I need multiple values to be put into A.

It's an unspecified amount, so can be 1 or 10, all separated by a space.

Basically I'm trying to figure out if it's possible for the overloaded operator to process something like
1 2 3 4 5


without me going

input >> temp1 >> temp2 >> temp3...


And without me processing the input manually character by character.

>if so, do lots of >>s in the operator
What do you mean by that?

>>57115392
If you're not gonna help, fuck off.

I HAVE to do it like that, as these are the specific requirements for the assignment. It's not a choice. I wouldn't bother with this shit otherwise.
>>
File: 1469885154538.jpg (282KB, 718x960px) Image search: [Google]
1469885154538.jpg
282KB, 718x960px
>>57113677
>be me
>have to take Java course because fuck me
>learning material already online
>look at GUI learning material
>Swing and AWT
>fuck this and fuck the ruski Ivan IT professional lecturer
/rant
>>
>>57115445
for loop

while (cin >> temp)
>>
>>57115095
>but what if the list contains nonnumerical elements?
Then in a sane language it would not of type int[] or similar and exhibit different behavior.
>>
File: c1_0.png (27KB, 195x195px) Image search: [Google]
c1_0.png
27KB, 195x195px
>>57115291
>>57115517

>>57115517
This by itself doesn't work, I also need to check for the new line character because that's what get put into the input stream when I press enter, but thanks for the replies.

Here's what I got:

istream& operator>>(istream &input, MyClass &rhs) {
int temp;

while (input >> temp) {
rhs.insert(temp);
}

return input;
}


It works as expected now, when I enter
1 2 3 4 5

and press enter, all 5 numbers get inserted into the set.
>>
>>57115517
>>57115601

Shit, I meant this code:
istream& operator>>(istream &input, MyClass &rhs) {
int temp;

while (input.peek() != '\n' && input >> temp) {
rhs.insert(temp);
}

return input;
}
>>
I have a, probably dumb, idea for a language feature. I'd like to hear /g/'s thoughts. Overloaded specifies

class A 
{
int x;
int y;
virtual void whatever()
{
cout<<"I'm A\n";
}
}

specifier const : A
{
const int x;
const int y;
void whatever()override
{
cout<<"I'm const A\n";
}
}

int main()
{
A a;
const A b;
a.whatever(); //I'm A
b.whatever(); //I'm const A
}


Const and static would of course default to their normal use like the assignment operator. Are there any languages that do this?
>>
>>57115628
C++ already does this

class A {
int x;
int y;
void whatever();
void whatever() const;
}


produces the same result as your code.
>>
>>57115291
>>57115601
>>57115611
>>57115517

Apparently that was wrong too since I couldn't do
   cout << "Enter ints for set A:  " << endl;
cin >> A;
cout << "Enter ints for set B: " << endl;
cin >> B;


Because the last character in the input stream was a newline character, so it would skip over the cin >> B.

The final and correct code for what I was trying to do is:
istream& operator>>(istream &input, MyClass &rhs) {
int temp;

do {
input >> temp;
rhs.insert(temp);
} while (input.peek() != '\n');

return input;
}
>>
>>57115658
Const was probably not the best example.

 
specifier unsigned : A
{
unsigned int x;
unsigned int y;
void whatever()override
{
cout<<"I'm unsigned A\n";
}
}
>>
>can't use (sizeof(a)/sizeof(a[0])) in arrays passed to functions to get their size

crap, I've been with this shit for an hour now thinking something else in the code was wrong
>>
>>57115740
That's an abomination. Just keep track of the size.
>>
>>57115740
std::vector does not have this problem.
>>
>>57115755
I was advised to use a macro and define size as that to have it as a global variable, but it seems pretty useless after this.
>Just keep track of the size.
What do you mean?
>>57115776
Is that for C++? I'm starting with C right now.
>>
>>57115809
>What do you mean?
You shouldn't have to recalculate the size of your array each time.
>>
>>57115776
Instead it has many other problems.
>>
>>57115838
sizeof is compile-time only, so it would get compiled into a constant in the executable anyway.

But yes, he should be using a size_t to keep track of the length at run time if the array is to be passed around.
>>
>>57115862
Such as?
>>
>>57115862
Name some.
>>
>>57115740
std::array
>>
>>57115881
>>57115883
Pass the last 10 of 100000 elements of a vector to an array that accepts a vector.
>>
>>57115902
*to a function that accepts a vector or a reference to a vector.
>>
File: anime.png (300KB, 1192x734px) Image search: [Google]
anime.png
300KB, 1192x734px
Writing an anime Usenet indexer.

Daily fucking blog:
I have to get the series information from an online database, aniDB. After about 1000 queries, I get banned. It gets lifted, I make another 100, get banned again. Fairly reasonable, since it sort of goes against their leeching rules.

Then I find a database dump of exactly what I need. It should let me skip thousands of queries. It also includes an image dump! The database dump matches the anime series to an image that should be in the image dump. Except the fucking database includes image references that aren't in the fucking image dump, so now I have random missing images.

In the dump there is also airing dates for the series. This would be great, except that anything that aired before 1970/01/01 has its air date set to 0.

There is also a column for related anime, but instead of giving the ID of the related anime and how its related (sequel, prequel etc.) it just gives the fucking TITLE of the show that's related.

They also just randomly skipped certain columns like episode count for whatever fucking reason, even though that information is provided in the query that you need to make to aniDB.
>>
//Declaring variables
while (Mag(ax, ay, az) >= 0) {
scanf( //Scan time, ax, ay, az );
timeNew = time / 1000.0 //Time is scanned in as milliseconds; converting to seconds
velocityNew = velocityOld + (9.8 - (Mag(ax, ay, az) * 9.8)) * (timeNew - timeOld);
positionNew = positionOld + (velocityNew * (timeNew - timeOld));
positionOld = positionNew;
timeOld = timeNew;
velocityOld = velocity New;
printf("\npositionNew is: %.2lf", positionNew);

Any idea on why this might be acting up? Prints out 0.00 then 7.96 until the while loop exits. Should be printing out increasing values up to the final position, 7.96

E.g. :
0.00
0.23
0.93
1.56
2.67
.....
7.96
>>
>>57115902
f(std::vector<>(v.begin() + 99990, v.end()));
>>
>>57115953
I don't know that operator. What does it do?
>>
>>57115968
I removed the type that would normally go between the <> because it wasn't specified in the question.
>>
>>57115981
Why are you copying the elements?
>>
>>57115989
The problem did not specify that the elements of the original vector needed to be modified.
>>
>>57115950
Terrible naming.

delta = now() / 1000.0 - time;
velocity += 9.81 * delta * (1 - Mag(ax, ay, az));
position += velocity * delta;
time += delta;
>>
>>57116020
If the function does not modify the elements, why would you copy them?
>>
>>57116032
The function may modify them, but that doesn't mean the elements of the original vector should be modified.
>>
>>57115902
>>57115915
>>57115989
Be more specific. If the function takes a reference to a vector, you would just pass the vector and have the function handle what elements it affects. If the function a vector itself, you would copy the last 10 elements into a new vector and pass that. Alternatively, you could pass an iterator.

yourVector.end()-10 but really you should just pass vectors by reference.
>>
>>57116083
>If the function takes a reference to a vector, you would just pass the vector and have the function handle what elements it affects.
Ridiculous.
>If the function a vector itself, you would copy the last 10 elements into a new vector and pass that.
I sure hope not.
>Alternatively, you could pass an iterator.
But then how do I know the length?

0/10 C++ tried.

It's no surprise that it's been said that chromium performs 20,000 allocations every time you press a key in the address bar.

It's honestly embarrassing that it took the committee 20 years to realize that reference types such as string_ref are needed in an efficient language.
>>
>>57116031
Won't work for the implementation I need. Didn't fix my problem anyway.. I forgot to update my variables within the loop. Thanks anyhow though
>>
>>57116119
>Ridiculous

Why is it ridiculous?

>I sure hope not

You hope wrong. If you wanted to pass a vector of a specific size as an argument that's not a reference(god knows why you'd do this), you'd copy the relevant elements into a new vector.

>But then how do I know the length?

Sorry that was a brain fart, I mean you'd pass iterators for a beginning and end.
>>
>>57116198
>I mean you'd pass iterators for a beginning and end.
I might just pass a pointer and a length.

You seem to think that a type that can only represent owned data (such as vector) can do the same job as a type that can represent both owned and borrowed data (such as a pointer). You are wrong.
>>
>>57116119
>string_ref
char*

What ever you say
>>
>>57116258
Are you living under a rock? string_ref has been accepted into C++17 (under the name string_view.)
>>
>>57116244
>I might just pass a pointer and a length.

Why?

Please give an example. What do you want this function to do?
>>
>>57116280
A function that calculates the average of an arbitrary number of integers living in continuous memory.
>>
>>57116276
>I'm pleb. I don't think. I follow the convention.
What an argument
>>
>>57116308
Everyone with half a brain has already written a string_ref type for every serious C++ project they were involved in.
>>
>>57116324
>Everyone does it therefor it's good
Again...
I don't care though. Char* is everything you need and you can't prove me wrong.
>>
>>57116342
https://www.youtube.com/watch?v=HMqZ2PPOLik
>>
>>57116294
>arbitrary number of integers living in continuous memory
So, an array of ints?
>>
>implying your puny language has anything that matches the sheer computational rigour, raw unbounded power, and rapidity of strtotime()
>>
>>57116405
That's right.
>>
File: tegaki.png (5KB, 400x400px) Image search: [Google]
tegaki.png
5KB, 400x400px
Cubical type theory!
p āˆ˜ q ā‰œ (āŸØyāŸ© coeįµ§ (a = qįµ§) p)1
>>
>>57116466
>he doesn't work on tesseractic type theory
topkek why are you even on /g/
>>
>>57116489
It's really hypercubical because it generalizes to all numbers of dimensions.
>>
>>57116504
what about rational non-integer dimensions
>>
>>57116294
Well that's completely different from the last 10 elements of a vector.

 
template<typename T>
T average(std::vector<T> &vec)
{
T total=0;
int elem=0;
for(T t : vec)
{
total+=t;
++elem;
}
T average = total/elem;
return average;
}

int main()
{
std::vector<double> A{5,1,3,5,7};
std::cout<< average(A) << std::endl; //4.2
std::vector<int> B{5,1,3,5,7};
std::cout<< average(B) << std::endl; //4
}


If you want an arbitrary section of a vector, then you pass iterators. But you need to be sure the iterator is valid so you'd need to know begin() and end(). I'd do that by passing the vector by reference and the two iterators I want, rather than passing 4 iterators.
>>
>>57116504
>he doesn't work on uncountably dimensional type theory
why even post on /g/ you pleb
>>
>>57116519
>>57116539
Demonstrate a practical utility of that.
>>
>If you want an arbitrary section of a vector, then you pass iterators.
Your function doesn't accept an iterator. Or are you gonna write two functions?
>>
>>57116551
are you talking to >>57116466
>>
>>57116559
The practical utility of cubical type theory is that it is homotopy type theory but it behaves well computationally and is easier to use.
>>
>>57116551
>practical utility
>not programming in the realm of the purely abstract and useless
WHY EVEN
>>
>>57116575
such as
>>
>>57116580
What do you mean, "such as"?
>>
>>57116590
What do you mean what do I mean? I mean such as
>>
Why don't more languages have actually readable Error messages?
>>
lol>>57116653
>>
>>57116653
this is why you should use haskell
>>
>>57116653
language <> compiler
>>
>>57116653
C#'s are fairly straightforward most of the time.
>>
>>57116689
There are definitely languages for which it isn't possible to have both readable and accurate error messages.
>>
>>57116653
What's hard to read about that exactly?
>>
>>57116600
Well, "such as" is kind of a nonsensical response to that statement.
>>
>>57116703
I meant that as an example of readable messages.
>>
>>57116717
>kind of
kind have
>>
>>57116653
With python, errors are objects that you can inspect and analyze. really the greatest language ever designed.
>>
>>57116725
oh right. Some languages just suck i guess.
>>
HAHA SEI GAY INSGUQEEIOAGNDSH89z
>>
>>57116717
explain
>>
>>57116735
He's talking about the error messages the compiler itself prints out. Not what gets return when your are compiling shit code inside another python script.
>>
>>57116735
>implying this is a unique feature of Python
>>
>>57116748
>The practical utility of cubical type theory is that it is homotopy type theory but it behaves well computationally and is easier to use, such as...
>>
>>57116735
>errors are objects that you can inspect and analyze

Same with Rust, I was talking about compile-time errors.
>>
I'm modeling ranges of integers and cartesian products of ranges in Java.

I'm using iterators to generate the ranges.

I'm supposed to have methods that
1) give the number at index i in the range (or cartesian product)
2) give the index of a given number in the range (or cartesian product)

Since I'm not actually keeping all the integers in any lists is there any way of doing this in an O(1) way? Obviously i can just iterate from start until desired index or element but this is O(n).

Can i somehow say to my iterator to skip a bunch of steps?
>>
>>57116682
Haskell error messages are incomprehensible to me. It might as well just say shit's broken in this function, good luck.
>>
File: 1401194922988.jpg (174KB, 800x388px) Image search: [Google]
1401194922988.jpg
174KB, 800x388px
>>57116763
>he doesn't know the -i flag
>>57116790
me too
>>
>>57114875
Yet dptfags still go
>Haskelel is useless
>>
Can someone point me to a resource how to hash a constant size char array to size_t?
>>
>>57116735
>syntax errors
no
>>
Just wrote a paper on it so I have to ask - save Ruby on Rails, is Ruby even used anywhere/worth using anywhere? Outside of web development I can't find a practical use for it, or any real advantageous reason. I get the whole "everything's an object and this is a scripting language LISP/Smalltalk/Perl conglomerate" thing, but is there really any instance in which you'd find yourself thinking "man it'd be so much easier if I were programming in Ruby to accomplish x"?
>>
>>57116830
have you tried google?
>>
>>57116824
>over the last 7 years compile times have gone up 5% each GHC release
>over the last 7 years performance of our program has gone down 5% each GHC release
this company will soon be in ruins
>>
>>57116791
>Can i somehow say to my iterator to skip a bunch of steps?
no. Don't use an iterator.
>>
>>57116840
yes
>>
>>57116824
>literally takes 2.5 MILLION LINES of code to make a useful haskell program
>>
>>57116791
if you don't want to iterate, don't use iterators.
>>
>>57116859
>there are no invalid python programs

well done
>>
>>57116859
only if you're compiling python within another python script. Any langugae with an eval() method can do that.
>>
I have a script in Python that I'd like to play a small alert sound at a set interval: for now it's every 20 minutes.

I tried putting the system time check in a while loop and it ate some ~25% of my CPU. Putting it in a self-referencing if/else statement gave a recursion error after a few minutes.

This is the recursion error version:

''' import time modules '''
from time import gmtime, strftime
import time
''' import sound modules '''
from sound import *

''' define time function '''
def check_time():
read_time = strftime('%M', gmtime())
return read_time

''' set alert loop '''
def check_loop():
if check_time() == "20" or check_time() == "40" or check_time() == "00":
play_alert()
check_loop()
else:
time.sleep(1)
check_loop()

check_loop()


I am a complete noob and really have no clue what to do or if maybe my program idea isn't possible.

Any help would be hugely appreciated.
>>
>>57116850
General-purpose descriptive scripting, if you like Ruby. Some game engines use it, like RPG Maker.
>>
>>57116888
>or if maybe my program idea isn't possible
This is correct, it is absolutely impossible to play sounds on a timer in Python without overflowing the stack.
>>
>>57116888
>what is
time.sleep()
>>
>>57116888
>self-referencing if/else statement
>reinventing recursion
Nice! I fucking hate people who complain that recursion is too hard but want to be programmers. You'll go far kid
>>
>>57116830
If it's passwords or secret info, use libsodium.
Otherwise use literally anything.
>>
>current year
>still textual HTTP headers
I can't even...
>>
>>57116852
I have, or rather i am, but it doesn't hurt to ask for help as well.
>>
>>57116888
>I tried putting the system time check in a while loop and it ate some ~25% of my CPU.
But it seemed to work right? Please confirm

Here's the idea: compute the next beep moment just once, and use sleep to jump directly to it. That way your program won't eat any CPU time at all in the meantime.

Also nice trips.
>>
>>57116932
They are actually binary-encoded now.
>>
>>57116939
1. pick a hashing algorithm (because 'hashing' is vague just fyi)
2. implement it, or use an existing implementation of it.

was that so hard?
>>
>>57116981
>binary-encoded
means both everything and nothing at the same time. congrats!
>>
>>57116888
does time.sleep(1) actually make the thread sleep? or does it just keep the CPU doing work until 1ms has passed?
>>
>>57116931
What, like take every
sizeof(arr)/sizeof(size_t)
th byte?
>>
>>57117000
It does. And it can take any value greater or lesser than 1 too.
>>
>>57117000
It asks the OS to not run the thread.

>>57117010
That's the most retarded hashing scheme I've ever heard, but if it's not crypto at least your code will just be bad instead of criminally insecure.
>>
>>57116881
>only if you're compiling python within another python script.
no
>>
>>57116987
I don't know any hash algorithms, and specifically i don't know any that has to sizeof(size_t)
>>
Good beginner reads on ML/Neural Networks? Bonus points if pseudocode.
>>
>>57117023
okay, how do you receive python objects from compiling python without using python.
>>
>>57117019
and it's 1 second just in case. 1ms would be
time.sleep(1e-3)
time.sleep(0.001)
>>
>>57117021
>That's the most retarded hashing scheme I've ever heard
So you see why i felt the need to ask for help.
>>
>>57116998
What I mean is they are encoded and packed tightly with bitmasks, numeric identifiers and whatnot, instead of plain text.
>>
>>57117024
>specifically i don't know any that has to sizeof(size_t)
>sizeof(size_t)
what? That-s not what you actually mean, is it?
>>
>>57116527
Keep it idiomatic senpai.

template <typename T>
const T average(const std::vector<T> &vec)
{
T total = 0;
std::for_each(vec.begin(), vec.end(), [&total](const T &value) {
total += value;
});

return total / vec.size();
}
>>
>>57117046
What I see is that you still haven't googled it.
You shouldn't be proud of being helpless.

https://download.libsodium.org/doc/password_hashing/

https://download.libsodium.org/doc/hashing/generic_hashing.html
>>
>>57117031
>without using python.
what? how do you want to compile without using python?
>>
>>57117052
interesting... source? is that http/2 or some compression done on top of it?
>>
>>57116966
The while version did work anon, yes. I think it was eating so much CPU because it was just
while True
.

So I think I get what you're saying, should it be something more like:
1. Start program, get system time
2. Calculate time until next beep and put to sleep
3. Beep, go to 2
>>
>>57117071
using the python compiler and a prewritten python file to be compiled.
>>
>>57117078
HTTP/2. Just read the spec/some blog posts.
>>
>>57117062
That's wrong but it's also not correct.
>>
>>57117058
Y-yes?
http://www.cplusplus.com/reference/functional/hash/
>>
python code is interpreted
>>
>>57117062
>std::for_each instead of range-for
For what pvrpose
>>
>>57117086
You're right. A simple check once per second shouldn't eat up 25% of a recent CPU, I should have remembered that.

>So I think I get what you're saying, should it be something more like:
>1. Start program, get system time
>2. Calculate time until next beep and put to sleep
>3. Beep, go to 2
Yes that-s what I was thinking of. Not saying it's the word of God, but I think that's a more elaborate and performant design and a good exercise for you to write, assuming that's what you came for right?
>>
>>57117124
well, technically it compiles to a bytecode first, so Python itself isn't interpreted
>>
>>57117135
>called std::for_each
>still need to pass begin and end

how did it take so many fucking years for some genius C++ fag to realise you could put two iterators together
>>
>>57117156
this is implementation detail and it's transparent to the programmer.
>>
>>57117182
Sure, but then you can't really say "python code is interpreted" for the same reason
>>
>>57117182
interpretation is an implementation detail
>>
>>57117098

Maybe "pickle"?
>>
>>57116856
They're compiling most of the code (an order of magnitude more) on their in-house compiler, which supposedly uses a restricted subset of standard Haskell, so I guess their performance isn't that bad.
>>
>>57116558
Funny enough, I just discovered you can't assign a default argument to an iterator, so yes I'd have to overload the function.
>>
>>57117232
you seems to be confused.

interpreter: execute the code.
compiler: translates the code.

with python, i give a source file to the interpreter. what it does internally is irrelevant to me.
with gcc, i give a source file to the compiler which doesn't execute the code but translates it into machine code. i must then execute the binary file

see the difference now ?
>>
>>57113677
Why is it that Rust, despite being a low-level, zero-overhead language built using LLVM, still lags behind C and C++ in the benchmarks game?
>>
>>57117315
That's full retard. Let me put you out of your misery.

#include <iostream>
#include <vector>

template<typename T>
class slice {
public:
slice(T* start, T* end) : start_{start}, end_{end} { }
slice(T* start, size_t n) : slice(start, start+n) { }
template<std::size_t n> slice(T (&a)[n]) : slice(&a[0], n) { }
slice(std::vector<T>& v) : slice(&*v.begin(), &*v.end()) { }

slice<T> cut(size_t from, size_t to) {
return { start_+from, start_+to };
}

slice<T> cut_from(size_t from) {
return { start_+from, end };
}

slice<T> cut_to(size_t to) {
return { start_, start_+to };
}

slice(const slice<T>&) = default;
slice& operator=(const slice<T>&) = default;

T* begin() { return start_; }
T* end() { return end_; }

size_t size() {
return end_ - start_;
}

private:
T* start_;
T* end_;
};

template<typename T>
T f(slice<T> s) {
T avg { };
for (auto& v : s) {
avg += v;
}
return avg / s.size();
}

int main()
{
{
int i[] = { 1, 2, 3, 4, 5, 6 };
slice<int> s { i };
std::cout << "avg of array slice: " << f(s.cut(1, 4)) << "\n";
}

{
std::vector<int> v { 1, 2, 3, 4, 5, 6 };
slice<int> s { v };
std::cout << "avg of vector slice: " << f(s.cut(1, 4)) << "\n";
}
}
>>
>>57113691
Why did you copypaste this from Stack Exchange and change the gender?
>>
>>57117403
Because it's not low level and not zero-overhead
>>
>>57117403
Unoptimized compiler vs. decades of optimizations
>>
>>57117381
You are confused, gcc is not a programming language.

Since it is equally possible for a program to be passed C code and execute it transparently, C code is also interpreted, right?
>>
>>57117403
Because C++ (and C to a lesser extent) have a rich type system and plenty of undefined behaviors that allow compilers to make a lot of assumptions and a lot of optimizations.

Without UB, C and C++ would run much slower.
>>
>>57117457
Rust does to an even greater extent.
>>
>>57117449
Just wanted to 3rd party this discussion. You are definitely the confused one. He was comparing an interpreter (the python one) to a compiler (gcc). What you said doesn't have any relevance, but yes there are C interpreters as well as compilers.
>>
>>57117439
>rust's llvm is slower than clang's llvm
what did he mean by this?
>>
>>57117487
I meant by this that the Rust compiler spits out suboptimal LLVM IR
>>
>>57117523
Maybe so. But the real answer is that Rust's benchmarks game code just isn't good. Back in the day I wrote the reverse complement benchmark for rust which was the fastest implementation in the game by some significant margin. But then they changed to code to make it more "rust" and now it's no longer the fastest.
>>
File: dehydrated.jpg (27KB, 423x315px) Image search: [Google]
dehydrated.jpg
27KB, 423x315px
>>57117467
Not at all.
For example in Rust signed integers are defined to wrap on overflow (and even worse, then trap on overflow in debug mode!).

In C or C++ a compiler can completely optimize away code like this:
int stupid(int a) {
return a+1 > a;
}


Because overflow is UB, and so the compiler assumes overflow will not happen, hence a+1 is always more than a.

You might say "but that's an artificial example, no one writes code like that!".

But it actually happens all the time under the hood.
Access an array using an unsigned or wrapping index variable? The generated code will be several times bigger and several times slower than with a C/C++ signed index variable, because the compiler doesn't have to check for overflow at every step.

And signed overflow is just one of the many UBs that allow powerful optimizations.
I could talk all day about this.
>>
https://groups.google.com/forum/#!topic/scala-internals/r2GnzCFc3TY

LOL
>>
>>57117556
Yeah, that's one counterexample. Though I guess it's a pretty important one since the benchmarks game is basically all numerical stuff. I'd say Rust was not particularly designed for programs that do a lot of number crunching, and rather for programs that do a lot of memory management.

That said, it's more like default Rust generally allows the compiler to make more optimizations than default C. The affine types mean you have a lot of non-aliased pointers (restrict in C), for example.
>>
>>57117603
Scala is a very sad langugae
>>
>>57117410
>slice(T* start, T* end) : start_{start}, end_{end} { }

What did he mean by this?
>>
>>57117603
>Scala is fairly well-known by now. There are no beginners out there, because everyone already knows Scala. No need for better beginner documentation.
>>
>>57117438
>not low level
fair enough
>not zero-overhead
I'm not aware of anything in the language that you have to pay for, whether you use it or not.
>>57117523
Makes sense.
>>57117551
So Rusty idioms get in the way of the language's full potential? I'd be interested in details.
>>57117556
This makes sense.
>>57117607
>Rust was not particularly designed for programs that do a lot of number crunching, and rather for programs that do a lot of memory management.
Are there any benchmarks that show this off?

>>57117671
If you mean the past-the-colon stuff, those are member initializers. It allows calling the ctors of members, instead of assigning to them after a default-construction.
>>
>>57117603
This is what happens when java fags try to copy the beauty of Haskell
>>
>>57117449
>C code is also interpreted, right?
depends

>>57117449
>gcc is not a programming language.
python has no formal standard. the standard is that any implementations must mimic the official implementation know as CPython
>>
>>57117713
>So Rusty idioms get in the way of the language's full potential? I'd be interested in details.
The problem with high magic languages is that you have to know the compiler very well to know which parts of the magic will be optimized and which won't. It's the same with claims that Haskell can be faster than C. It probably can if you've a PhD in GHC internals.

Back in the day I spent more than a day tweaking that code to get the right performance. The C code on the other hand was straightforward.
>>
>>57117760
>Haskell can be faster than C

but only for strenuous definitions of can
>>
>not using types to ensure that overflow really can't happen
// type of 32-bit integers up to a limit up to 2^32
U32 : Fin (2^32) -> Type

// doesn't compile if it could possibly overflow
add : U32 m -> U32 n -> U32 (m + n)
>>
>>57117790
Write code in that which calculates the average of a list of ints.
>>
>>57117790
Might as well shutdown your computer so you don't do any mistakes
>>
>>57117790
Agda?

And how do you statically enforce that, if you need to add to a user-provided value.
>>
>>57117823
you literally have to prove to the compiler that you've accounted for all eventualities
>>
>>57117828
/dpt/ can't even prove that 30 + 30 = 60.
>>
>>57117833
what
>>
>>57117840
Do it then. I'll grade it.
>>
File: PrincipiaMathematica54-43.png (43KB, 800x333px) Image search: [Google]
PrincipiaMathematica54-43.png
43KB, 800x333px
>>57117833
>prove that 30 + 30 = 60.
I can do that in just a couple hundred pages.
>>
>>57117833
what are the premises
>>
>>57117846
If I have 30 apples and 30 apples, I have 60 apples.
>>
>>57117828
So... you can't take a user-provided value? Unless you use a parser to parse the entered string into a (possibly inaccurate) valid range?
>>
>>57117852
Peano.
>>
>>57117833
here you go
https://www.youtube.com/watch?v=BE657F9sqyQ
>>
>>57117804
Well, a cop-out solution would be to make the type be:
avg : Vec (


>>57117823
It's just dependently typed pseudocode, but inspired by Agda syntax. As for the user-provided thing, probably you'd just limit the user input to a constant upper limit.
>>
>>57117804
>>57117865
I need to stop replying to multiple posts at once.
avg : Vec (U32 (2^32 / n)) n -> U32 (2^32)

It would be pretty straightforward to implement if you're used to dependently typed programming but I don't feel like writing it and all the premises out.
>>
>royally fucked up a coding test on friday
>had an interview scheduled for today beforehand
>thought for sure it would be cancelled
>ended up answering every single question they gave me and doing so pretty damn well
>Even the SQL question
>And taught the interviewer about xpath
>>
>>57117893
What if one is 2^32-1 and the rest are 0?
>>
>>57114530
Please do this.
>>
>>57117861
Z + m = m
S n + m = S (n + m)


(30 + 30) ~ 60 = ? // typechecker pls do this for me
>>
>>57114530
Harder than doing it in ASM.

At least in ASM you can use Qt, GTK or even the WINAPI easily.
>>
>>57116840
Syntax errors are also objects in python like any other exception.
>>
>>57117920
Define 30.
>>
>>57117904
Well, it wouldn't work, hence the cop-out solution part.

You could also make the type ensure that the sum of the limits is sufficiently small, but that would still be too restrictive a type. That's assuming that the implementation is just summing everything and then dividing. A smarter implementation would allow you to refine the type more.
>>
>>57117936
The set {29, {}}
>>
>>57114530
Do you need native Win32, or would Qt bindings prove satisfactory?

https://hackage.haskell.org/package/qt
>>
>>57117949
Define 29.
>>
>>57117936
30 = S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (Z
>>
>>57117957
Define 60 and prove that 30 + 30 = 60.
>>
>>57117956
I fucked up.
29 is actually {0, 1, ... , 28}, with the note that 0 is {}.
>>
>>57114663
Jesus fucking christ.
>>
>>57117969
60 = S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (Z

the proof is trivial
>>
>>57117982
Is it, though?
>>
>+300
We need a new thread now!
>>
>>57117989
yes


Z = Z
(n = m) -> S n = S m

apply the latter 30 ish times
>>
>>57117989
The proof is just reflexivity since 30 + 30 reduces to 60, definitionally.
>>
>>57117996
310*
>>
>>57118005
>>57118017
Sounds like you need to develop a theory of symbols first to avoid writing a very long proof.
>>
>>57118031
This is why computerized proof assistants exist.
>>
>>57118031
What are you talking about?
I gave you what you wanted
>>
>>57118045
>/dpt/ can't even prove 30 + 30 = 60 without taking out their coqs.
>>
>>57117833
By definition, 30 = 29 + 1
Hence 30 + 30 = 30 + (29 + 1) = 30 + 1 + 29 = 31 + 29

By applying this process iteratively, we arrive at 30 + 30 = 58 + 2, and 2 = 1 + 1, hence 30 + 30 = 58 + 1 + 1 = 60.

Cogito jacta est.
>>
>>57118059
It would take a lot of typing out of trivial reductions otherwise.
>>
>>57118061
You haven't even defined what 58 is yet.
>>
>>57118059
>>57118076
Also, considering this is a PROGRAMMING thread you'd kind of have to expect that people are going to use proof assistants/dependently typed total languages.
>>
>>57118077
If we assume 30 = 29+1, iteratively we arrive at 58 = 57 + 1 = 0 + 1 + .... + 1
>>
>>57118077
50 : YourMom = ASlut
>>
>>57118091
What's 57 though?
>>
>>57118096
58 - 1
>>
>>57118103
58 has not been defined yet.
>>
>>57118114
57 + 1
>>
NEW THREAD!!

>>57118110
>>
S 59 = 60
S 58 = 59
S 57 = 58
>>
>>57117833

I'm only calculating in base 5.

What's a "6" ?
>>
>>57118198
>I'm only calculating in base 5.
You mean base 10? What's a '5'
>>
>>57118245
Sorry, I only know base 4.2
>>
Any resources where i can learn this shit?
(C++, C#, Python)
>>
>>57118554
Free book, PDF download on page.

http://www.robmiles.com/c-yellow-book/
>>
>>57118586
Thanks man
Thread posts: 339
Thread images: 24


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.