[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: 318
Thread images: 16

File: prog.jpg (105KB, 473x496px) Image search: [Google]
prog.jpg
105KB, 473x496px
Old thread: >>61683744

What are you working on. /g/?
>>
torrent client in python 3.

i've read the spec and still have no idea what i'm doing. just kinda stumbling through it.
>>
>>61694518
I hope it's better than IRC protocol.
As my first program I was trying to develop program that could transfer files in IRC trough DCC subprotocol. Seems there's no good specs out there and some other implementations had comments like
>we are supposed to do this but nobodys seems to care
>>
Haskell!
>>
File: s.png (161KB, 1680x1050px) Image search: [Google]
s.png
161KB, 1680x1050px
>>61694500
>What are you working on. /g/?

Exploring the deepest, darkest corners of Racket.
>>
Say hello to C++20's newly proposed lambda syntax!

[]<>(){}();
>>
>>61694694
Based committee making our professional moat stronger and stronger.
>>
>>61694694
>Making a lambda and executing it in place
but why
>>
>>61694756
[](){[](){}();}();

>valid C++
>>
>>61694555
desu the IRC protocol is one of the easiest protocols to implement and DCC isn't that complicated
http://www.irchelp.org/protocol/dccspec.html
>>
>>61694555
i've been told that the irc protocol is easier to implement. i've never done this sort of thing, and i was told to do something other than IRC cause it's been beaten to death by everyone.
>>
>>61694814
C++ has finally become so bloated that it comes with a Lisp parser.
>>
why does /dpt/ hate rust? isn't it the future?
>>
>>61694814
'(((((((((())))))))))

valid lisp
>>
>>61694841
because /dpt/ers are already a few levels above of what rust offers.
>>
>>61694841
/g/ hates everything

that said, armies of autists shouting "_____ is the future of programming!!!!" gets annoying no matter what is in the blank.
>>
>>61694862
>He thinks this looks even a iota more bloated or retarded than the C++ example
>>
>>61694870
>/g/ hates everything
untrue.
>>
>>61694841
anything but C89 or HASKELL is PURE GARBAGE in muh dee pee tee
>>
Can you recommend me some books on C# if I'm coming from a C++ background?
>>
>>61694862
That's just parentheses.
You can do that in C++.

(((((((((([](){[](){}();}))))))))))();
>>
>>61694907
Agda is good too
>>
>>61694919
you can do a lot of stupid shit in any language
none of this proves anything
>>
>>61694940
>none of this proves anything
You can stop the tough talk anon
We all know C++ is awful
We're all adults here
>>
>>61694935
MUH <some obscure garbo>
>>
>>61694919
Clearly, Python is the best language.
>>
C is the greatest language
>>
C was a mistake
>>
>>61694972
>C
>a language
more like a pidgin dialect at this point
>>
>>61694951
>We all know C++ is awful
No shit. It's not hard to prove with actual code, so why do you get all autistic with bullshit non-examples?
>>
>>61694972
>>61694982
C was/is the greatest mistake
>>
>>61695018
biggest*
>>
>>61694756
const auto foo = [] { if (...) return X; else return Y }();[.code]

This pops up every now and then.
>>
>>61695022
big and great aren't the same, but manlets are certainly not great
>>
>>61695027

That's what the ternary operator is for.
>>
>>61695027
Shit, I messed it up, but you get the point.
>>
>>61695040
>big and great aren't the same
Exactly
>>
>>61695056
Yes, and C was/is the greatest mistake, not the biggest.
C++ was the biggest mistake.
>>
>>61694870
>_____
>dumpfags prefix their shit like this in hopes of no name collision even though the language has namespaces
Why do sepplesfags do this?
>>
For those who're interested in the JVM:
https://www.youtube.com/playlist?list=PLX8CzqL3ArzXJ2EGftrmz4SzS6NRr6p2n
>>
>>61695064
Nope, C really was the biggest mistake, C++ came into fruition only because C existed
>>
>>61694982
>>61695018
What would be the universal language for embedded systems be if Dennis died before he created C?
>>
>>61694841
If it's the future, tell me why not even Rust shills use RedoxOS?
>>
>>61695148
ALGOL
>>
>>61695153
Same reason most of /g/ uses windows instead of OpenBSD. There are more software and games for Windows. Difference is, Redox does not try to compete with Windows, Linux does.
>>
>>61694500
How to git gud?
>>
>>61695198
Hackerrank
>>
>>61694823
Most of IRC is really easy, but DCC often goes implemented because, as that anon said, no one seems to care
>>
>>61694841
https://www.reddit.com/r/rust/comments/6qv2s5/rust_not_so_great_for_codec_implementing/
>b...but it's in nightly!
>b...but it's not idiomatic!
>b...but we're working on it!
>>
>>61695107
>Nope, C really was the biggest mistake
Not really. C was there to define the "most common ground", that could be very easily translated to underlying assembly.
The BIG MISTAKE was languages that tried to be compatible with but broke the ABI compatibility.
There was a change to build proper superset over C platform semantics(the same used in System V ABI specs) but every language had to go their own way into introducing new monster to world.
>>
Here's haskell code where, no matter how many arguments you gize 'z', it still returns zero. Note: Haskell does not have variadic arguments.

class ZZZ a where { z :: a }
instance ZZZ Integer where { z = 0 }
instance ZZZ a => ZZZ (b -> a) where { z _ = z }

z 1 2 3 "a" "b" (1,2) [1,2,3] (8,True) Nothing 9 4
--> 0[/code
>>
>>61695213
"
Rust does not allow you to mutably borrow parts of the same array even when it should be completely safe like let mut a = &mut arr[0..pivot]; let mut b = &mut arr[pivot..];

isn't that just split_at_mut?

permalinkembedsavereportgive goldreply

[–]dobkeratops rustfind 73 points 1 day ago*

it is, but it's hard to discover this."

Looks like people should do more research before bitching and moaning about everything
>>
>Haskill
Who cares?
>>
Trying to make a crappy space shooter game. Each time the spacebar is pressed I want to create a new bullet.

What is wrong with this?

private class KeyHandler implements KeyListener {
@Override
public void keyPressed(KeyEvent e) {

if(e.getKeyCode()==KeyEvent.VK_SPACE){ //if space is pressed create a new bullet
bullets[ammo] = new Bullet(game,3,ship.getX()); //game, speed, and the x position of the ship
ammo++;
}

else

ship.pressed(e); //else go to the ship pressed method, moves ship left or right

}

@Override
public void keyReleased(KeyEvent e) {
ship.released(e);
}

@Override
public void keyTyped(KeyEvent e) {
} }
>>
>>61695282
You tell me.
>>
>>61694613
Go deeper. Have you seen:
> sweet-expressions
> at-expressions, scribble
> racket's object model ("augment", "augride", "overment")
> Turnstile or Redex
>>
>>61695245
id, fmap and const are all variadic, despite not using type classes

you could also look at printf from Text.Printf, which uses the same type class trick
>>
>>61695184
Except Windows users don't shill for OpenBSD. I don't know what you're even trying to say, you deluded Rustard - what do games have to do with anything? Redox came out with intentions to surpass the Linux kernel, and in obnoxious manner proclaimed superiority, only to end up as just another microkernel piece of shit. Rust is utter trash, and its users even worst.
>>
>>61695282
>What is wrong with this?

OOP.
>>
>>61695313
i am still learning how to build my own data structures by nesting cons
>>
>>61695322
>what do games have to do with anything?
Attracts users, thus devs, thus software. Do not pretend that you don't know this already.
>Redox came out with intentions to surpass the Linux kernel
Can I have a source of this claim?
>and in obnoxious manner proclaimed superiority, only to end up as just another microkernel piece of shit.
Microkernels adhere to the Unix philosophy.
>Rust is utter trash, and its users even worst.
Now this one is incoherent? What about rust triggers /g/ basement dweller's autistic screeching this much?
>>
>>61695359
not an argument.

provide reasonable arguments why OOP is bad.
>>
>>61695389
Also, the author himself says that he does not want to compete with Linux since it's made for x86 unlike Linux
https://youtu.be/eH5JgMlNE8o?t=28m16s
>>
>>61695359
OOP is perfectly suited to GUIs.
>>
>>61695415
>inb4 poo memes and no arguments
>>
>>61695359
OOP is good. FP is good. Combine them for super sayan language.
>>
>>61695445
>Comes to 4chan for actual arguments
lmao
>>
>>61695452
>OOP is good
[citation needed]
>>
>>61695458
>FP is good
[citation needed]
>>
>>61695458
We've been using OOP for years now. I wonder why...
>>
>>61695430
OP is writing a game.
>>
>>61695471
Money talks
>>
>>61695452
OOP and FP are already alike.
>>
>>61695471
"We've been always doing it that way."-people are the most uninspiring, boring kind.
>>
>>61695490
Is that why people switch to new languages every month?
>>
Why do modern webdevs get hardons for fp?
>>
>>61695534
To compensate for their lack of degree.
>>
>>61695389
>Attracts users
That is irrelevant to the point of discussion. I never asked why Redox wasn't competing with Windows, I asked why Rust shills don't use their own OS. I myself use GNU/Linux, Linux being written in C. C wins again, it seems.
>Can I have a source of this claim?
Of course a goddamn spewing retard like yourself wouldn't know the first thing about anything. Way to waste my time - it turns out I know more about Rust than the Rust shill himself: https://linux.slashdot.org/story/16/03/21/1315235/rust-based-redox-os-devs-slam-linux-unix-gpl
It was somewhat big news, because it caused some anger and community in the Linux community.
>Microkernels adhere
Strawman. Read what you type before spewing.
>screeching
I'm not the one screeching, you Rust shills are. Linux is written in C, and Linux is usable - I use it. Redox is Written in Rust, and Redox is unusable, and nobody, not even diehard Rust shills, use it. I don't think you can even browse 4chan on Redox. Keep your shit language where it belongs: in the trash.
>>
>>61695476
?
>>61695485
>>61695490
OOP languages get FP features. FP languages get OOP features. You want the best of both worlds.
>>
>>61695557
>their lack of degree.
?
>>
>>61695534
FP was one of the many elements in the unfocused and rushed mess that was Javascript, the language webdevs have stockholm syndrome for.
>>
>>61694814
>>61694862
This is valid Rust
fn main() {
let x = ||||||||||();
assert_eq!((), x()()()()());
}
>>
>>61695588
||
Please explain
>>
>>61695568
*worst of both worlds
>>
>>61695593
That's how you introduce a lambda expression, I believe.
>>
>>61695593
Ruby cuck tier closure.
>>
File: gkvcdttm42p2kw1cytvz.jpg (66KB, 800x450px) Image search: [Google]
gkvcdttm42p2kw1cytvz.jpg
66KB, 800x450px
So you know Pushbullet? It's an app that allows you to send messages/notifications between your devices (among other things).
I want to make a similar thing, mostly for myself.

I don't really want to write a messaging backend for it, so I have to pick some already existing messaging platform.

I want something that I can connect to from small Python scripts, C++ programs, Android apps, hopefully browser extensions, etc. So it needs to be pretty light, but not too low level (like IRC, which I don't particularly like). Hopefully it can be """scalable""" if I decide to release it to the public at some point.

Any suggestions?
>>
>>61695607
t. Fortran programmer
>>
>>61695593
closures in Rust look this:
let closure = |<params>|<expr>;

Basically, I am defining closures within closures, where the innermost closure returns Unit (https://en.wikipedia.org/wiki/Unit_type).
>>
>>61695611
Redis? ZeroMQ? RabbitMQ? Just use any message queue that allows for publishing/subscription.
>>
>>61695650
>>61695609
>>61695608
but why that syntax?
>>
>>61695662
Who knows, it looks awful
>>
>>61695662
They stole it from Ruby.
Remember: Rust combines shit syntax from all kind of languages.
>>
File: just_graduated.png (31KB, 184x194px) Image search: [Google]
just_graduated.png
31KB, 184x194px
      if (cp[0] == 0)
return cp - str;
if (cp[1] == 0)
return cp - str + 1;
if (cp[2] == 0)
return cp - str + 2;
if (cp[3] == 0)
return cp - str + 3;
if (sizeof (longword) > 4)
{
if (cp[4] == 0)
return cp - str + 4;
if (cp[5] == 0)
return cp - str + 5;
if (cp[6] == 0)
return cp - str + 6;
if (cp[7] == 0)
return cp - str + 7;
}
}


https://github.com/lattera/glibc/blob/master/string/strlen.c
>>
>>61695702
Optimizations.
>>
>>61695702
>Instead of the traditional loop which tests each character,
>we will test a longword at a time. The tricky part is testing
>if *any of the four* bytes in the longword in question are zero.
This is actually optimal.
>>
>>61695566
>I asked why Rust shills don't use their own OS.
And I specified exactly why. Why are you _so desperately_ trying to avoid the point?
People use Linux because they have their software ported to it
People use Windows because they have their software ported to it
Both Linux and windows are consumer grade OSes, backed by millions of donors or a multimillion dollar company. Linux has been here for a good 30 years. And it's slowly getting traction. Windows has a big company behind it, people pay for windows and Bill gates worked for it. You must be seriously delusional to think that everyone should be using their own language kernel.

By that logic, C#, Java, Haskell, and even C++ people would not be using computers. Rust simply was not there when Linus and Bell labs were developing OSes. Stop pretending to be a pedantic idiot and stick to the point.
> https://linux.slashdot.org/story/16/03/21/1315235/rust-based-redox-os-devs-slam-linux-unix-gpl
1. You claimed Redox is made to be an alternative to Linux and no where in your link has this been claimed.
2. The link you posted is about complaints against GPL. GPL is NOT flawless and this begets a different conversation, YOU are deliberately changing the topic. Learn why Linus stayed with GPLv2
>Strawman.
Do you know what ``strawman`` means? I just gave a simple answer why Redox OS might have chosen a microkernel arc. How is that a ``trawman``?

>and nobody, not even diehard Rust shills, use it.
AGAIN with your stupid argument. I explained this well and clear before.

It's pretty hilarious when GPL tars screech over MUHHH FREEDUMB while browsing 4chan
>>
>>61695654
This is radically different than what I had in mind, so thanks. I'll see if I can figure it out.
>>
>>61695729
Premature*
>>61695737
>This is actually optimal.
Post benchmarks.
>>
>>61695069
what are you even talking about you autistic faggot
>>
>>61695695
Sounds like PHP.
>>
//Bunch of imports
public class SpacePanel extends JPanel{

private Space game;
private Ship ship;
private Bullet[] bullets;
private Monster[] monsters;
private int score;
int ammo = 0;

public SpacePanel(Space game){

setBackground(Color.BLACK);
ship = new Ship(game);
bullets = new Bullet[50];
monsters = new Monster[20];
Timer timer = new Timer(5, new TimerHandler());
timer.start();

addKeyListener(new KeyHandler());
setFocusable(true);
}

public void update(){
ship.updatePosition(); //update ship positoin
if (ammo > 0) //if a bullet is fired update bullet position also
bullets[ammo].updatePosition();
repaint();

}

@Override
public void paint(Graphics g) {
super.paint(g);
ship.paint(g);
}

private class KeyHandler implements KeyListener {
@Override
public void keyPressed(KeyEvent e) {

if(e.getKeyCode()==KeyEvent.VK_SPACE){ //if space is pressed create a new bullet
bullets[ammo] = new Bullet(game,3,ship.getX()); //game, speed, and the x position of the ship
ammo++;
}

else

ship.pressed(e); //else go to the ship pressed method, moves ship left or right

}

@Override
public void keyReleased(KeyEvent e) {
ship.released(e);
}

@Override
public void keyTyped(KeyEvent e) {
}
}
private class TimerHandler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
update();
}

}
}
>>
>>61695796
Fix your indentation first and I might help you.
>>
>>61695794
PHP only stole from Perl and C++.

In other words, it stole from the two messiest languages on the planet.
>>
>>61695791
>Premature*
yeah it surely is a premature optimization in glibc lmao
>>
>Python is pseudo-code

Python users are pseudo-programmers.
>>
>>61695566
>>61695322
no one is going to re-invent the wheel (Windows, Linux, OSX) your argument is stupid. Rust might suck but this is not a very strong reason
>>
>>61695836
>>Python is pseudo-code
Wrong
>Python users are pseudo-programmers.
Wrong
>>
File: 1494449551899.png (677KB, 800x2000px) Image search: [Google]
1494449551899.png
677KB, 800x2000px
>>61695776
Here, learn something!

Wait, nevermind. You're an idiot anyway.
>>
Has anyone here read 'The Little Schemer'? Would you recommend it?
>>
>>61695807
Gookmoot won't let me post on /g/ from my PC without buying a 4chan pass so I have to upload it too Google docs and post from my phone sorry
>>
>>61695865
So you finally changed the topic to GPL vs BSD. Why am I not surprised?
>>
>>61695875
Are you from Taiwan by any chance?
What is he code supposed to do? What does it do now?
>>
>>61695566
>slashdot
Wow so this is why people hate slashdot, Fake news from line #01
>>
>>61695865
If anything, as we've successfully established in these threads >>61694523 and >>61513412, GPL is the real cuck license.
>>
>>61695916
I am the one he is arguing with. GPL has its uses and it preserves consumers' right to the source. We went through this hundreds of times
>>
>>61695865
Arguing with a BSD cuck is like telling a Muslim why Islam is bad.
>>
>>61695931
>GPL has its uses
Sure. To the Chinese gov't.
>>
>>61695916
Thanks for shilling your thread, wang tao jun
>>
I like C++
>>
>>61695959
lul
>>
>>61695959
So do I, even though it sucks in a lot of ways.
I wish D didn't fuck up.
>>
>>61695959
I like Java
>>
>>61695993
What do you like about i?
>>
>>61695993
I also like Java when it's not overengineered FactoryFactory bullshit
>>
>>61695959
I like ruby
>>
>>61696018
So never?
>>
>>61695791
glibc strlen:
real    0m0.345s
user 0m0.344s
sys 0m0.000s


Unoptimized strlen:
real    0m49.185s
user 0m49.184s
sys 0m0.000s

The kode:
#include <stdio.h>
#include <string.h>
char * benis = "benisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenisbenis";
int shittystrlen(char * c) {
char * cursor = c;
while(*(++cursor) != 0);
return cursor - c;
}
void main() {
int i;
for(int j = 0; j < 10000000; j++)
i = strlen(benis);
printf("%i\n",i);
}
>>
>>61696044
>type time in terminal
>prints this
real 0m0.000s
user 0m0.000s
sys 0m0.000s
am I better than you
>>
>>61695865
GPL really doesn't work in practise though. Every large company steals GPL code for its' proprietary products. They are very rarely caught and even more rarely are they actually even punished for it. If you post your source code somewhere, accept that it has been stolen by somebody, regardless of what license you use.
>>
>>61694862
for i in 1..100 do((i%3==0)&&(i%5==0))?(puts"fizzbuzz"):(i%3==0?(puts"fizz"):(i%5==0?(puts"buzz"):nil))end

this is valid fizzbuzz ruby
>>
>>61696070
I'm not sure if that greentext is in english desu

>>>/g/wdg/
>>
>>61696004
The language is consistent.
>>
Where do I start on learning how to make cool geometric patterns? I know very little about geometry, btw
>>
>>61696170
>I know very little about geometry
>>
>>61694911
There's an MSDN article specifically for this (if a bit dated):
https://msdn.microsoft.com/en-us/library/yyaad03b(v=vs.90).aspx

Otherwise, you could try the C# Yellow Book. It's free. It's mostly geared towards new programmers, so it might be a bit dry at first, but it'll help you see the mechanical differences.

I'm unaware of a book that teaches C# that is also specifically geared towards experienced C++ programmers.
>>
>>61696170
I don't know, Anon. Have you considered looking into geometry?
>>
>>61695852
Except Linux had already picked up steam in the same timeframe Redox has been in development. Redox has no excuse.
>>
>>61696176
What are you implying, anon?
>>61696194
Yeah, I guess that would be a logical first step. I wish I weren't such a brainlet, sometimes.
>>
>>61696208
Actually, kys. It's kids like you that bring in 50 shitposts with shittiest logic that makes me cringe
>>
The big O for insertion and deletion for an array is given as O(n). Why is this the case? Is it because you presume you're inserting to the worst possible point and are either shifting the elements to fill the empty space left by deletion or to create space for insertion?
>>
>>61696264
Constants are ignored in big o notation. It's just variables.

But the expect amount of shifting is n/2
>>
>>61696239
You can also look into fractals if you want cool patterns.
>>
>>61696264
Big O is always worst case
>>
so i've been trying to compile C using some similar libraries i downloaded (new to C). i've never been able to compile anything though. i always use the make command and compile the libraries first. but whenever i try to use them in my code, it never compiles and says the library functions don't exists. any ideas?
>>
>>61696306
>big o is always worst case
lol nope. Quicksort is o(nlogn) but it's worst case is o(n*n).

Best case, worst case, and average case are important distinct measures when selecting an algorithm for your data.
>>
>>61696330
after you compile a library you have to either install it or instruct the compiler to use the library
for the 1st, most of the time "sudo make install" after make will work
for the 2nd, you'll need to pass -L and -I flags to the compiler with paths to the library when you build code that depends on the library
>>
>>61696347
Where are installed libraries stored in linux?
>>
>>61696347
/usr/include and /usr/lib unless you specify a different install dir
>>
>>61695654
I read a bit about ZeroMQ and pub/sub in general, and it's mostly worthless for me, if I understand it correctly (I most likely don't). I need a different kind of messaging.

Basically I'm building a messenger where devices/programs are people. So I need a way to identify and send data to them without having to open ports. Pub/sub doesn't help me with that at all, since I need to become a publisher (i.e. bind to an open port with a static IP) to "reply to messages".

Unless I'm misunderstanding something.
>>
File: aa.jpg (43KB, 448x300px) Image search: [Google]
aa.jpg
43KB, 448x300px
Do you guys program anything related to data science / machine learning?

should someone invest in this fad?
>>
>>61696392
meant for >>61696363

>>61696433
nah the mq instance would be a publisher, devices would be subscribers, and then you'd just tell the mq (through some other soft in the middle probably) that you have a message that you want to be published
>>
>>61696449
Machine learning is already solved. The only missing component is data, which is only a matter of time
>>
>>61696495
>Machine learning is already solved
?
>>
>>61696539
Boolean machine_learning_solved = true;
>>
>>61695776
Anon, stop feeding trolls.
>>
Any one know Vulkan here

Can someone explain Command-Pool, Command-Family, and Command-Buffer in brainlet-speak?

Like if I want to have multiple,threads giving graphics or compute commands to one GPU, how would I set things up and what would each thread need
>>
>>61696488
>and then you'd just tell the mq (through some other soft in the middle probably)
This is the part I was struggling with.
If I need to use some other thing to send messages from devices, then I guess I need to find that other thing (which shouldn't be too hard, might as well do it through ZeroMQ as well, but with a server/client pattern).

Thanks!
>>
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0045r1.pdf

even more bandages being added
you can't fix a broken language
>>
>>61697331
Sorry to break it you lad
But that's how things in the real world work
Bandages over bandages
>>
>>61697376
there is a better way
>>
>>61697331
That's not a super drastic change or anything.
>>
>>61697440
You really don't need a million special cases and ifs and buts in your language definition
>>
>>61697413
There is.

Anyone hyped for Jai here?
>>
>>61697449
Do you even enterprise?
>>
>>61697478
Fuck off nv
>>
>>61697376
>But that's how things in the real world work
Everyone has their breaking point. Even JS artisans have a term for it and are moving to transpiled languages.
>>
>>61697478
Jai more like why
>>
>>61697478
Not with that syntax.
>>
>>61697590
Syntax is not final (nothing is, really. not even the name).
>>
>>61697606
Isn't he already implementing a game in it or something, or does that count as prototyping?
>>
>>61697639
Hes releasing an OS sokoban with the compiler.
>>
Trying to figure a way, without branching or using a table, to create a function that returns:
16 = 1
8 = 1
4 = 2
2 = 4
1 = 8

Have been thinking about ways of masking and bitwise stuff, but to no avail. I do not want to be forced to accept that an if else approach is most efficient.
>>
>>61697639
The game will ship along with the compiler as an example project.
The syntax is not that bad, so any changes that may arise won't be drastic enough to render the existing code unfixable.
>>
>>61697666
Why not? Some mathematical functions are only expressible with if-else statements.
>>
>>61697727
Pretty sure arithmetic is turing complete, doing weird shit with +
>>
>>61697750
Don't know either way. But how would you express f(x) = (x >= 1) without an (implied or otherwise) if-else.
>>
>>61697782
Well it's encoded and shit, it's not boolean
>>
>>61697727
It just doesn't feel necessary and seems to be ugly. Branching, and the benefit of correct branch prediction, ideally has a need and a reason behind it's use. I also don't want any function calls, like a ceiling function (in the rest of the formula, which relies on this particular result).
>>
>>61697666
def thing(i)
return (8.0 / i).round
end

this is in ruby but you get the idea
>>
>>61697666
8/clamp(i, 1 , 8)
This works but not really sure of the point of this pattern though.
>>
>>61697810
Hm. I'm working in integers, but maybe I could cast to a float.
>>
>>61697802
Fit a fifth-order polynomial to it then if you necessarily want something analytical.
>>
>>61697782
ever heard of lambda calculus?
>>
>>61697952
No.
>>
>>61697952
He wants no conditionals or branches
>>
working on college C assignment. In my program, user can type a function and the program would execute it, so far i have this code:
struct fTable {
char *fName;
void (*function)(void *args);
}

void function1 (void *args) {
//do stuff
}
void function2 (void *args) {
//do stuff
}
void function3 (void *args) {
//do stuff
}

and in main:
struct fAssoc fTable[] = {
{"function1", function1},
{"function2", function2},
{"function3", function3}
}

but then i'm stuck and don't know how to call the function after the user has chose one. please help?
>>
File: 1454010963720.jpg (12KB, 347x371px) Image search: [Google]
1454010963720.jpg
12KB, 347x371px
>Server on localhost randomly doesnt respond 2/3 of the time
Oh boy I'm sure happy to fix that one
>>
>>61698046
there's a typo in my code, it should be
struct fAssoc {
//etc
}
>>
>>61698046
ftable[0].function();
>>
>>61695282
Maybe you should post the whole class and tell us what the problem is.
>>
>>61698046
Windows: system()
LOONIX: fork() then execv()
>>
>>61698127
What are you talking about?
it's clearly >>61698082
>>
>>61698127
>>61698046
Nevermind Im retarded
>>
>>61698082
ok thanks, but i want to execute the function by having its name, not an index in the array...
>>
Redpill me on linear types, preferably with sources
>>
>>61698189
int c;
if(!srtcmp(input, "function1")) {
c = 1;
.
.
.
ftable[c].function();
>>
>>61698189
strcmp its name with the input, then call it by indexing into the array, desu
>>
>>61698190
Theyre stupid.
citation: My objective opinion.
>>
>>61694500
Stop wasting time. Computer programming is so sad. It's a black hole of obsoleteness.
>>
>>61695796
Found the mistake. You never actually paint the bullets.
>>
>>61695729
>>61695737
That's awesome, but why not just do:
  for (i=0; (cp[i] <> 0) && (i<sizeof(longword)); ++i);
return cp - str + i;

That code might be optimized and shit, but it was obviously written by a CS sophomore. And you two are obviously dumb sophomores too.
>>
>>61697666
16 = 1 or 16 = 0?
>>
>>61698227
It's a black hole of obsoleteness? So you're saying it sucks obsoleteness in and leaves everything else to flourish?
>>
File: source.gif (1MB, 2048x2048px) Image search: [Google]
source.gif
1MB, 2048x2048px
>>61698266
>(cp[i] <> 0)
>>
>>61698227
what isn't den
>>
>>61698189
for(int i=0;i<MAXFUNCTIONS;i++){
if(!srtcmp(input, fTable[i].fName)) {
fTable[i.function(NULL); //replace null with parsed args if that's what you wanted
break;
}
}

From your description I don't think you wanted to have to pass void* args to these functions but rather have them be void functions, change the struct fAssoc to have
void (*function)(void);

instead of
void (*function)(void* args);

if that's the case and just omit the null. in the code above.
>>
>>61698363
>>61698218
>>61698213
thanks guys
>>
>>61697666
here one that doesn't have any branching. it could probably be optimized further but i am too sleepy for that.

(define (n x)
(+ (arithmetic-shift #b10000 (- (integer-length x)))
(arithmetic-shift x -4)))


integer-length is the position of the first 1 bit. see https://en.wikipedia.org/wiki/Find_first_set
>>
>>61698440
Both me (>>61698363) and >>61698213 made the mistake of writing srtcmp instead of strcmp.
If you hadn't noticed.
>>
>>61697666
>I do not want to be forced to accept that an if else approach is most efficient.
Bad attitude. If it were you absolutely should.
>>
>>61698466
>>61698440
This you need to write the following at the top of your file
#define srtcmp strcmp

Then itll work
>>
>>61698316
Damn, I'm shitfaced! Also, check for size of longword should come first to short-circuit dereferencing cp out of bounds. But my question still stands, why not just use a loop instead?
>>
>>61698227

Fuck you, coding cures depression. Can't be sad if you don't give yourself time to think.
>>
>>61698547
>Can't be sad if you don't give yourself time to think.
Truer words were never spoken
>>
>>61698463
>>61697666
C version
int f(int x)
{
return (16 >> __builtin_ffs(x)) + (x >> 4);
}


x64 with gcc
[codep
f:
bsfl %edi, %ecx
movl $-1, %eax
cmove %eax, %ecx
movl $16, %eax
sarl $4, %edi
addl $1, %ecx
sarl %cl, %eax
addl %edi, %eax
ret


with clang
f:                                      # @f
bsfl %edi, %ecx
movl $8, %edx
shrl %cl, %edx
testl %edi, %edi
movl $16, %eax
cmovnel %edx, %eax
sarl $4, %edi
addl %edi, %eax
retq
>>
>>61698634
>AT&T
Nobody's gonna read that shit
>>
>>61697666
Branch mispredictions cap out at 20 cycles. Branches which predict successfully cost ONE cycle.

That's chump change compared to a single hard cache miss, which is around ~200 cycles on modern hardware.

A virtual function call can cost up to 600 cycles due to potentially 3 cache misses.

This isn't even considering out of order execution which can ease branch mispredictions a whole lot more relatively than compared to cache misses.

algorithms > cache lines > branching
>>
File: umarusee.jpg (113KB, 1280x720px) Image search: [Google]
umarusee.jpg
113KB, 1280x720px
>>61698463
>>61697666
>>61698634
>>61698642

here a much better one

int fopt(int x)
{
return (8 >> __builtin_ctz(x)) + (x >> 4);
}


gcc:
        xor     ecx, ecx
mov eax, 16
rep bsf ecx, edi
sar edi, 4
sar eax, cl
add eax, edi
ret


clang:
fopt:                                   # @fopt
bsf ecx, edi
mov eax, 16
shr eax, cl
sar edi, 4
add eax, edi
ret
>>
>>61698546
Because loop unrolling.

https://en.wikipedia.org/wiki/Loop_unrolling
>>
Compiling C HW with Visual studio with /FA flag gives 3kb C asm code
Compiling C++ HW with Visual studio /FA flag gives 243kb asm code.

Is there any trick that will give me only clear few lines of code that I need?
>>
>>61697666
int f (int n) {                                                                |
return 7 / n + 1; }


nice triples
>>
>>61698820
noice
>>
>>61698848
Integer division is masqueraded ifthenelse
>>
>>61698923
Is it really? Doesn't the code just discard the decimal part? Not sure on the implementation
>>
>>61698978
>Doesn't the code just discard the decimal part?
Yes. And it's a trick to do ifthenelse. Exactly like I did in >>61698820
>>
>>61699000
>>61698978
What? On x86 integer division is a distinct single instruction. It's a pain in the ass to set up the registers, but there's no branching.
>>
>>61698463
how'd you get your font to look so clean
is it just a font, or is it a font-renderer setting?
>>
>>61698923
What are you smoking
>>
>>61699020
Example
you have 0 <= n < 20
and you want 13 if n < 10 and 42 for 10 <= n < 20
with n / 10 you'll obtain 0 or 1 and if you have an array a with 13 and 42, a[n / 10] will do the trick.

>>61699065
We're not on the same level my little code monkey. You should learn from me instead. For you I am a wizard.
>>
>>61699079
Not really a masqueraded branch though. It's slower than branching. Actually a de-optimization.
>>
>>61699118
>branch
branch, if, for, while are exactly the same things
>de-optimization.
Clearly out of subject.
>>
>>61699159
You're talking about optimizing array element selection. Totally within topic.
>>
>>61699168
>optimizing
No. It was never about optimization. It was about coding >>61697666 without branching or a table. And I did the trick by hiding the branching by using the integer division operator.
>>
>>61699041
it's both
>>
>>61699228
But why? The only valid reason would be for optimization.
>>
>>61699284
Look at >>61697666
Probably an exercise gave by a "hacker" teacher.
>>
Anyone has experience with Windows API programming?
Trying to get some buttons going and the official documentation says to use CreateWindow to create buttons, which seems insane, especially that when alt-tabing from the program, all buttons appear as active windows. Is there any way around this bull-crap?
>>
>>61699418
literally why are you trying to do buttons that way.
Just do it like every other library does and draw a rectangle.
>>
>>61699418
>Windows API
>which seems insane

Sounds about right, buddy.
>>
File: UI-rendering.png (111KB, 619x619px) Image search: [Google]
UI-rendering.png
111KB, 619x619px
Been working on my minecraft clone's UI. Looking to generate nice renders of the blocks instead of icons.

The renderer to generate them is looking good. It was pretty fun deriving the magic constants to make it render right. Been a while since I've done a geometric proof. If anyone's interested I can clean up my proofs and scan them up.

Next step is to render onto a texture instead of the screen. After that it's easy to make my UI surfaces reference said texture.

    gl_Position = (scene_matrix * ((vertex + vec4(-0.5, -0.5, -0.5, 0))));
//It can be shown that the longest side of the hexagon is 2sqrt(2)/sqrt(3)
gl_Position.y /= (8 * 0.816496580927726032);
gl_Position.x /= (8 * 0.816496580927726032);
gl_Position.z *= -1; //I have no idea why this is necessary
gl_Position.y += 0.875;
gl_Position.x -= 0.875;
int x_coord = baseinstance % 8;
int y_coord = baseinstance / 8;
gl_Position.y -= y_coord * 0.25;
gl_Position.x += x_coord * 0.25;

And the code to generate the scene matrix
    //angles to have camera look at vertex
float pio4 = 0.7853981634;
float other = 0.615479708670387;
mat4x4_rotate(tmp, threequarters, 1, 0, 0, other);
mat4x4_rotate(threequarters, tmp, 0, 1, 0, pio4);


>>61699418
You're not "supposed" to touch winapi directly. It's designed to be compiler friendly not programmer friendly. Use a framework.
>>
>>61699418
Did you set their parent window properly? >>61699526
Damn near everything drawn on the screen is a window at its core.
>>
>>61698046
just give up, you clearly didn't pay attention in the classes
>>
>>61699702
No, buttons are just supposed to be shapes you give front-end magic.
>>
>>61699526
Wanted to make something from scratch using Windows API at least once before jumping onto fancier graphical frameworks and thought that creating buttons the Windows way cannot be that messed up.

>>61699702
I was under impression that I did, but turns out CreateWindow jumps to message loop with WM_CREATE, and so it skipped initialization steps of the main window and tried creating buttons without the parent handle ready.
>>
>>61699418
Doesn't X11 basically do the same thing? (with everything being a window)
>>
>>61699684
Pretty cool anon.
>>
So far I'm nothing but unimpressed with C++. I'm only using it because I want the full Qt5 and Rust does not have it.
God, C++ is boring and dumb.
>>
>>61699960
How can a language be boring, Anon.
>>
>>61699974
I can't use or find powerful itertools in C++.
It doesn't even have zipWith or transpose
>>
>>61699988
It's so easy to implement zip with map, which C++ has. And transpose is just zip. You are too dependent on libraries. Read SICP
>>
>>61700045
Cool, let me implement all my tools first with a shitty macro system and then start working -_-
>>
ARM Assembly question
I know you can use
LDMDB sp!{LR}

to pop the link register, but how do you actually remove the copy of LR's contents from the stack? So far I've just been relying on having my code overwrite the spot after I'm done with it.
>>
>>61699684
Can you compile your thing in wasm senpai?
>>
>>61700063
You don't need macros to easily write zip with map, you stupid library addict.
#;1> (use srfi-1)
; loading /var/lib//chicken/8/srfi-1.import.so ...
; loading library srfi-1 ...
#;2> (define zip (cut map list <...>))

Note: assignment to imported value binding: zip
#;3> (zip '(1 2) '(a b))
((1 a) (2 b))
#;4> (apply zip (zip '(1 2) '(a b)))
((1 2) (a b))

Wait, zip is just map with a tuple constructor? So hard.
>>
Is it worth to get gud with directx?
>>
>>61700115
>cut map list
Do it in C++ please
>>
if i ask a project euler question will i get bullied
t. mathematician
>>
>>61700147
>t. mathematician
Ill bully you anyway just for being a fucking nerd.
>>
>>61700161
pretty mean desu
>>
>>61700105
That sounds pretty neat if it's possible. Guessing there's a C compiler for wasm. I imagine I'd have to port the input handling as I'm using SDL.

What about rendering though? My code is heavily reliant on Opengl 4.4.

>>61700142
I uninstalled g++ a long time ago. Besides I wouldn't want to spoonfeed you if I think your library addiction is a problem. Do it yourself:
http://www.cplusplus.com/reference/algorithm/transform/
>>
>Netflix open-sources one of their D libraries
https://github.com/Netflix/vectorflow
>>
>>61700169
you can ask your question though, desu.
>>
>>61699798
what styles did you pass to CreateWindow (or CreateWindowEx for extended styles)?

// in your WndProc
switch(msg) {
case WM_CREATE:
CreateWindowW(L"Button", L"Hello",
WS_VISIBLE | WS_CHILD,
20, 50, 80, 25, // x, y, w, h
hwnd, // parent
nullptr, nullptr, nullptr);


the WS_CHILD style makes it a child window (i.e. no titlebar, taskbar representation (alt-tab, as well), etc);

and btw, you should create the child windows (basically everything in Windows is a window. I wonder why they called the OS as such..) after the WM_CREATE message is received (or WM_INITDIALOG if you're using the resource editor and dialogs instead of windows)
>>
>>61700179
sdl is completely ported iirc

opengl might be a problem, ye
>>
I'm going through SICP and I'm just past the first chapter

I have finished the question it asks for taking in three integers and returnin the sum of the larger ones, whilst ignoring the smaller one.


(defun smaller_a (a b c)
(cond ((and (< a b)
(< a c))
(setq a 0)))
(+ a b c))

(defun smaller_b (a b c)
(cond ((and (< b a)
(< b c))
(setq b 0)))
(+ a b c))

(defun smaller_c (a b c)
(cond ((and (< c a)
(< c b))
(setq c 0))))
(+ a b c))

(defun ignore_smaller (a b c)
(cond ((and (< c a)
(< c b))
(setq c 0)))
(cond ((and (< b a)
(< b c))
(setq b 0)))
(cond ((and (< a b)
(< a c))
(setq a 0)))
(+ a b c))

How can I [spoiler] blockquote my code? [/spoiler] use the previous three functions in the last one? When I change the values inside the functions they go back to their original values once the function has ended.

Yes, I'm using common lisp instead of scheme because I didn't have the patience to set up scheme in SLIME mode instead of SBCL.
>>
>>61700346
>I'm using common lisp instead of scheme because I didn't have the patience to set up scheme in SLIME

>being this dependent on slime
question discarded
>>
>>61700346
read the sticky
>>
>>61700183
Maybe there's hope for D.
>>
>>61700346
>setq
Eww anon. You shouldn't use mutation for something that simple

Anyway the program seems overengineered.

First write the ignore_smaller procedure as if you had fancy predicates like (a-smallest? a b c), then implement those predicates.

But if you really wanna use those methods it would be something like:
(cond ((not (eq? (smaller_a a b c) (+ a b c))) (smaller_a a b c)))


>Yes, I'm using common lisp instead of scheme because I didn't have the patience to set up scheme in SLIME mode instead of SBCL.
You're going to fucking hate chapter 2 where you start passing functions around as data.

[spoiler]>How do I blockquote
[spoiler]with \[code\] tags[/spoiler][/spoiler]
>>
>>61694500
I am trying to write a program in C that takes user input and prints a histogram of the lengths of the words.

Here is what I have so far:
https://hastebin.com/ixomedejuq.cpp
This will get me the number of words in the input, but I'm stuck in regards to keeping track of the word lengths and displaying the histogram. Since this exercise is in the array section, i assume I'm supposed to create an array to store this information, but the array length of course depends on the input, and once my while loop reaches EOF, as far as I know, I can't access the beginning of the input again with the getchar() function.

Any advice would be most appreciated.
>>
>>61695282
bullets[ammo++] ...
>>
>>61700492
Uh like make a 256 char array if you're dealing with ASCII.
>>
File: Flesh Wound Pepe.jpg (50KB, 499x499px) Image search: [Google]
Flesh Wound Pepe.jpg
50KB, 499x499px
>Supposed to have made a python dictionary that pulls shit from webpages/APIs and can encode/decode in JSON
I have no idea where to start here, its for a project with 3 other grad students, but I'm a 1st year undergrad student who's only taken two classes of the curriculum (Intro course and Java data structures)

I know most of the Python syntax as I taught it myself a while back, but I'm pretty fucking clueless on this JSON shit. Where exactly do I learn about this?

I'm assuming something like this is pretty easy, and that I'm just being a dense retard. Oh god I should drop out of CS why the fuck am doing this jesus christ when will it get better.
>>
>>61700492
start by assuming the word lengths are no more than 15. that should get you started.
>>
>>61700585
nigger
>>
>>61700585
literally google "python json" and click the first link
>>
>>61700585
JSON is just a super stripped down Javascript, used for nothing more than holding data. You can convert python dictionaries and arrays to JSON with json.dumps and convert back with json.loads.
>>
>>61700585
You asked this yesterday, Anon.
>>
>>61694500

Why does everything have to have a hash attached to it in the software development world
>>
>>61700579
ah good call, this is just what i needed! thanks!

>>61700591
thank you
>>
>>61700585

is that what grad students are working on these days?

That's pathetic
>>
>>61700585

If you've ever even seen a JSON anything then it would be immediately obvious what it is and what it is for
>>
>>61700610
to add: JSON appears to be a subset of Javascript but there are incompatibilities. So its not a strict subset. JSON allows U+2028 and U+2029 in the strings while Javascript does not.

JSON:
>A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

Javascript:
DoubleStringCharacter ::
SourceCharacter but not double-quote " or backslash \ or LineTerminator
\ EscapeSequence

SingleStringCharacter ::
SourceCharacter but not single-quote ' or backslash \ or LineTerminator
\ EscapeSequence
//and

The following characters are consider to be line terminators:

\u000A - Line Feed
\u000D - Carriage Return
\u2028 - Line separator
\u2029 - Paragraph separator
>>
File: 1501708899680.png (378KB, 1450x1080px) Image search: [Google]
1501708899680.png
378KB, 1450x1080px
post the "rolling" pics like this one
>>
File: Puking TMNT Pepe.jpg (87KB, 627x528px) Image search: [Google]
Puking TMNT Pepe.jpg
87KB, 627x528px
>>61700665
This is really only a small part of the project, I'm assuming they're aware that I'm the weakest link.

Unless I'm misinterpreting things, this sounds very easy in theory. I already wrote a dictionary in Python that maintains placeholder data that I just wrote in, I guess the next step is pulling actual data from webpages and converting it to and from JSON. This dictionary I'm making is just something that the main application is going to reference for specific operations.

Part of me is just worried that I'm a brainlet and that it's not actually as easy as I thought and that I'm going to hand something in tomorrow that is fucking useless.

Can someone just sincerely say I'm being a fucking moron and that this is doable if I just sit down, read material and code for a few hours?

This is all part of a larger conflict where I keep doing good/okay in my CS classes but feel like I'm not actually learning to understand code and that I'm going to be fucking exposed sooner or later.
>>
>>61700820
This is all because you're not messing with things on your own in your spare time.
>>
>>61700820
Converting to and from json is piss easy, Python has a module for it and it's named exactly what you expect.
No idea what to use for pulling data from websites but there's bound to be modules for that too.

>>61700836
also this. Do this.
>>
>>61700820
You ever heard of imposter syndrome anon?
>>
>>61694500
Inventory based calendar system in Python
>>
File: unknown.png (30KB, 809x360px) Image search: [Google]
unknown.png
30KB, 809x360px
>>61700820
>>> import json
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
['foo', {'bar': ['baz', None, 1.0, 2]}]


hmm. I wonder.
>>
>>61700876
>inventory based calendar system
So an advent calendar?
>>
>>61700737
No. Stop posting that garbage.
Make a new thread for it.
>>
>>61700891
I don't want to make any garbage thread, I just want ideas for short projects and those seem ok
thread is near the reply cap so even if some dumb fags actually roll any of these it's not harmful to the thread
>>
>>61700890
Sorry
A countdown calendar system that tracks plant inventory and bloom dates
>>
>>61700870
Yes, I've sort of been having a crisis over it the past year or so.

>>61700836
>>61700841
I definitely need to get more into coding on my own time, I think about this pretty frequently. My motivation in general has just been so bad the past few years that it's been hard to sit down and learn like I did back when I taught myself python in highschool. Computers have pretty much been my whole life, I don't really see myself being more motivated or "fired up" in a different field.
>>
>>61701127
>coding
You're shit. You will always be shit.
Fuck off, frogposter.
>>
File: 1501629921474.png (1MB, 3840x2160px) Image search: [Google]
1501629921474.png
1MB, 3840x2160px
>>61700737
>>
Reminder to stay hydrated while artisaning your codings.
>>
>>61701162
How is that sentence any different if I say programming?
>>
>>61701290
Stop it
>>
>>61701311
no u
>>
>>61701306
Saying "coding" proves that you're a retard.
The frogposting was enough proof already, though.
>>
I just started SICP and am working on exercise 1.7. I came up with this solution which works very well:

(define (sqrt x)

(define (good-enough? guess last-guess)
(< (abs (- guess last-guess)) 0.00000001))

(define (improve guess)
(average guess (/ x guess)))

(define (sqrt-iter guess last-guess)
(display "guess: ")
(display guess) (newline)
(if (good-enough? guess last-guess)
guess
(sqrt-iter (improve guess) guess)))

(sqrt-iter (/ x 2.0) 0))

(define (average x y)
(/ (+ x y) 2.0))


I'm wondering if there's any way to improve on this. Thanks fellas.
>>
Someone wrote this bash script for me yesterday, can't get it to work though, here is what I have:
#!/bin/bash
total=$(wc -l < animals.txt)
words=$(sort --unique < animals.txt)

for word in $words; do
count=$(cat list | grep -F "$word" | wc -l)
percent=$(bc <<< "scale=2; $count / $total;" | cut -d. -f2)
echo "$word $percent%"
done


and animals.txt
dog
cat
dog
dog
rabbit
dog
cat
mouse


I've run on ubuntu and it cygwin, get same errors -

calculate.sh: line 4: $'\r': command not found
calculate.sh: line 5: syntax error near unexpected token `$'do\r''
calculate.sh: line 5: `for word in $words; do


wouldn't even know where to begin with those errors, seeing as '\r' doesn't even appear in the code, but im a noob. The code is supposed to take each unique line appearance, and output it alongside the percentage of total lines it appears.

Any help greatly appreciated.
>>
>>61701370
What is it trying to do?
>>
>>61701339
This ain't C. you don't need to specify 2.0. / promotes ints to fractions and floats as needed. The scheme equivalent of C's / is quotient.

Other than that there's not much to improve on. I guess you could improve good-enough so that it's percent error rather than absolute error, so you don't get weird results when doing (sqrt 0.0000000000000000000000000000000000001).
>>
>>61701370
looks like there is a return character in there instead of a newline. Try this instead:

#!/bin/bash
total=$(wc -l < animals.txt)
words=$(sort --unique < animals.txt)

for word in $words; do
count=$(cat list | grep -F "$word" | wc -l)
percent=$(bc <<< "scale=2; $count / $total;" | cut -d. -f2)
echo "$word $percent%"
done
>>
>>61701382
so the output should be:
dog 50%
cat 25%
rabbit 12.5%
mouse 12.5%
>>
>>61701370
dos2unix
>>
>>61701407
What have you changed?
>>
>>61701339
>>61701398
Actually, I don't remember the rules of convergence for fixed point iteration so there's a possibility the babylonian method doesn't converge for numbers less than one. Meh.
>>
New thread:

>>61701466
>>61701466
>>61701466
>>
>>61701458
I've replaced the return character with a newline. Not visible, but try it.
>>
>>61697666
https://en.wikipedia.org/wiki/Newton_polynomial
https://en.wikipedia.org/wiki/Lagrange_polynomial
>>
Learning C and going to write a small music player as a learning exercise
>>
>>61701615
learn rust instead
>>
>>61701723
Fuck off
Thread posts: 318
Thread images: 16


[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.