[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: 317
Thread images: 30

File: 1466719458577.png (147KB, 358x398px) Image search: [Google]
1466719458577.png
147KB, 358x398px
Previous thread: >>56007502

What are you working on, /g/?
>>
learning me a haskell
>>
File: pre.webm (494KB, 916x635px) Image search: [Google]
pre.webm
494KB, 916x635px
>>
>>56011602
neat, where is this code hosted?
>>
>>56011602
ebin
>>
File: pathfinding.png (8KB, 770x385px) Image search: [Google]
pathfinding.png
8KB, 770x385px
Learning A*
>>
File: pathfinding2.png (9KB, 770x385px) Image search: [Google]
pathfinding2.png
9KB, 770x385px
>>56011733
Not that A* yet...
>>
Now watch me whip, watch me nae nae, watch me whip whip watch me nae nae
>>
>>56011866
https://www.youtube.com/watch?v=Pe8d2W2Ma98
>>
Does anyone here program in Erlang?
>>
>in update loop
>every tick, check if condition is true
>if so, call a function
>except I only want the function to be called once
>what do
>>
>>56011465
Me too
>>
>>56011928
set a flag
>>
>>56011940
You mean like, a boolean? I could check if it's false, and then set it to true when I first call the function. That seems really hacky, though, is there not a better way to do it?
>>
>>56011928
>>what do
Easy, stop abusing quotes.
>>
>>56011927
I hope not.
>>
>>56011928
set condition to false
>>
>>56011973
Yeah what's the deal with Erlang?
>>
File: 1470743205649.jpg (136KB, 960x1280px) Image search: [Google]
1470743205649.jpg
136KB, 960x1280px
wtf i love emacs now
>>
long swap_bits(long n, unsigned i, unsigned j)
{
// how?
}

send help gee
>>
>>56012427
kind of hacky solution
n ^ ((n >> i ^ n >> j) & 1 ? 1 << i | 1 << j : 0)

Toggles the ith and jth bits if they're different. Perhaps the ternary operator can be turned into another bitwise operation.
>>
In c#, is it possible to pass multiple parameters to a list with just a .txt file via something like File.ReadAllLines? e.x.:

foreach (breed, location in dogShop)
{
dogs.Add(new Dog(breed, location));
}
>>
>>56012522
Yes.

What does you text file look like?
>>
>>56012531
Exactly like the example. Breed, Location per line so:
St. Bernard, Milwaukee
Welsh Corgi, Baltimore
>>
File: anal beads.png (27KB, 866x514px) Image search: [Google]
anal beads.png
27KB, 866x514px
>>56012522
>>56012573
There's probably a better way of doing it, but here's a quick and dirty one liner.
>>
>>56012625
Thank you, resident c# wizard Pajeetslayer, for once again lighting the way.
(I like both)
>>
File: anal beads.png (32KB, 958x638px) Image search: [Google]
anal beads.png
32KB, 958x638px
>>56012660
Also, if you want to get really crazy, you can make a constructor that accepts a single string and attempts to separate it into the properties of the object.

PROTIP: Don't let anyone see you do some dumb bullshit like this.

public Dog(string _commaseparatedline)
{
Breed = _commaseparatedline.Split(',')[0];
Location = _commaseparatedline.Split(',')[1];
}


Then you can just do:
var ayy = ReadAllLines(@"C:\temp\cats are better.txt")
.Select(x => new Dog(x))
.ToList();


Note that my code requires the following in the header:
using static System.Console;
using static System.IO.File;
>>
I just did my firs FizzBuzz. Can I be a game developer now?
>>
>>56012784
No.
>>
>>56012784
yes >>>/vg/agdg
>>
>>56012791
but it is a application made in node.js though
>>
>>56012830
Did you do it in one line?
>>
File: rlydinksutink.webm (71KB, 672x464px) Image search: [Google]
rlydinksutink.webm
71KB, 672x464px
>>56011432
automated shitposting so I can sage while doing actual work
pic related
>>
>>56012805
I didn't know they had threads like this on vg.
There are some interesting projects there.
>>
>>56012835
I see you generating sentences based on a single simplistic grammar structure.

How is that "automated shitposting"? Doesn't even post to 4chan.
>>
>>56012834
>open in Vi
>keep pressing shift j
>:wq

Gee, I made a one-liner
>>
>>56012835
so it just prints sentences to the terminal?

really made me think
>>
File: 1459487295667.png (249KB, 340x314px) Image search: [Google]
1459487295667.png
249KB, 340x314px
>>56012707
>make a constructor that accepts a single string and attempts to separate it into the properties of the object
Breed = _commaseparatedline.Split(',')[0];
Location = _commaseparatedline.Split(',')[1];


Holy lel. I bet you have some good stories.
>>
Somebody the other day was spending like 20 quid on some book called continuous enterprise dev in Java

So I'm reading it now this shit is bollocks
>>
File: varables.png (27KB, 804x445px) Image search: [Google]
varables.png
27KB, 804x445px
>>56012880
I would be lying if I said I haven't seen worse in some of the code I've had to maintain.

Bonus points for when the god damn foreigners start making up words and using them in the code, like
UpgradationImplimentator
and
Authentificationism
.
>>
>>56012930
so its good?
>>
>>56012835
>copy paste synonyms of 3 words from thesaurus
>randomly pick elements from each list
>concatenate them together
really made me think
>>
>>56012853
i was half-joking about being ready to make games, it's actually quite easy to get started with using a game engine, but if you want to get serious about making games you have many things you should learn, and not just programming-related things
>>
>>56012947
That is a sexy color scheme. What's the name of it?
>>
>>56012975
I don't really see the point in it, it just tells you to use the tools every Java dev does
>>
>>56013144
It's literally Visual Studio's default dark theme.
>>
>>56013181
What's the name of it?
>>
>>56012835
>pretending you can cheat the captcha
You'd make gorallions senpai
>>
>>56013218
If you have VS go look in the options. I guarantee you'll find it immediately.
>>
What's faster, passing a vector through a function by reference, or calling getVector() (which also returns a reference)?
>>
>>56013218
>>56013245
>he can't even change IDE themes
There's no hope, friend.
>>
>>56013257
DOES
NOT
MATTER

seriously anon, caring even ironically about such non-issues is plain retarded
>>
File: GOD FUCKING DAMN IT.png (6KB, 521x108px) Image search: [Google]
GOD FUCKING DAMN IT.png
6KB, 521x108px
>>56013218
click options
it's the first fucking thing

IT'S THE FIRST FUCKING THING REEEEEEEEEEEEEEEE
>>
>>56013257
No idea whoch language you mean but getV has extra function call so pass by ref is better
>>
>>56013257
If your function isn't being called hundreds of millions of times per second, it DOES NOT FUCKING MATTER.
>>
>>56013257
The former although the difference is insignificant.
>>
What VIM theme are you guys using?
>>
>>56013343
gruvbox
>>
File: 1460745934527.png (233KB, 520x423px) Image search: [Google]
1460745934527.png
233KB, 520x423px
The message comming out of a queue is wrong and it is mapping wrong somewhere and i cant find it and i dont want to go home feeling a failure like I did yesterday.
>>
if your post is not programming related, go to /sqt/ or elsewhere please
>>
>>56013353
that's fucking beautiful thanks <3
>>
>>56013257
the former, the code is cleaner and it does matter for performance depending on what you're doing
>>
>>56013315
You should always code as if your code is going to be scaled millions of times.
>>
>>56013512
should i scale my fizzbuzz program?
>>
I'm a noob learning could someone help me with conditionals inside a foreach loop I want to pick specific items out of an array.
>>
>>56013545
post the fucking code you fucking faggot.
>>
>>56013545
Learning power shell*
>>
>>56013529
Yes, every CPU cycle of your FizzBuzz should be micro-optimized at the Assembly level.

Readability doesn't matter, you can always tell your programmers to just git gud.
>>
>>56013560

$numbers = 10,20,30,40,50

$count = 0

write-host "ForEach selecting"

foreach($num in $numbers) {
if($num -lt 30){
$count++
}
}

write-host $numbers.length "took the test."
write-host $count "failed"

pause

c

>>
>>56011962
> That seems really hacky, though, is there not a better way to do it?
It's the simplest way of doing what you described.
>>
File: katy_perry_muppet.gif (4MB, 473x581px) Image search: [Google]
katy_perry_muppet.gif
4MB, 473x581px
>>56011593
Yes it is. Anything but CP will do.
>>
>>56011928
self-modifying code
>>
>>56013529
there is not even much you can do, the standard fizzbuzz is both cleanly written and reasonably performant, you can't optimize away the console I/O which is the big drain on performance, performance matters more for resource-intensive applications and highly interactive multimedia like games
>>
File: 1466023841336-b.png (25KB, 655x650px) Image search: [Google]
1466023841336-b.png
25KB, 655x650px
>>56011928
only call the function once :^)
>>
>>56013771
>you can't optimize away the console I/O which is the big drain on performance
Yes, you can.

Nearly every FizzBuzz writes a line on every iteration.

You could construct a single block of text and deliver it all at once to the console, which is much more performant.
>>
>>56013767
who needs DEP
>>
>>56013821
you won't gain much by building a string buffer or hardcoding the entire fizzbuzz string
>>
>>56013852
True, but it's possibly the biggest performance-affecting design decision in something like a FizzBuzz.

It really depends on if you're doing 100 or 100,000,000 iterations.
>>
>>56013649
Expected output?
Actual Output?
>>
File: Screenshot (1).png (98KB, 1366x768px) Image search: [Google]
Screenshot (1).png
98KB, 1366x768px
>>56014126
I got it to work, I don't know where I was going wrong... but I got it.
>>
>>56013360
Update: I have figured it out. I won't be killing myself today
>>
>>56011432
>>56011432
why doesn't my function work correctly?
function isEven(n) {
var a;
(n < 0) ? a = -n : a = n
function even(j) {
if (j == 0) return true;
if (j == 1) return false;
even(j-2);
}
return even(a)
}

its js btw
>>
>>56012707
>>56012625
>splitting twice

For what purpose?
>>
>>56014565
>(n < 0) ? a = -n : a = n
I don't understand that gibberish, but why don't use the remainder operator?
>>
>>56014565
You're not returning from the even(j - 2) call so if you pass anything greater than 1 to the function it won't return anything.
>>
>>56014723
thats weird, if (j - 2) is 1, say, then wont it result in the expression "return return false"?
>>
>>56014801
No because it won't return anything if the number is greater than 1, you need to return from even call in order to get the return from the recursive call so just substitute that line with:
return even(j - 2);


And it will work.
>>
>>56014565
I don't even
>>
I am using the Twitter API to build an application that assigns a general to the mood of Twitter at any given time.

I am just starting, and thinking of how to accomplish it. I was thinking of making a method for each emotion I will cover, searching from a general library of terms that I think fit each emotion, and +1ing an int assigned to each emotion.

The issue with that is the Twitter search function returns 30 Tweets with that phrase - including ones you've already covered. So it would just be +30 for each int. So I was thinking I need a way to determine if a Tweet has already been covered by search or not.

This is my first more complicated project outside of a class for my comp sci classes so I would appreciate any pointers
>>
What exactly do people mean that C is portable?
>>
>>56011432
a blackjack game in python
currently trying to make split possible and make user decide the value of ace
>>
>>56015103
So why not something like this (in pseudo code):
integer list visited
tweet list tweets <- search
integer score

for tweet in tweets
if tweet.id in visited
continue

score <- score + getScore(tweet.content)
visited.append tweet.id
>>
>>56008747
Haskell has both.
>>
>>56015121
Google.
>Portability is how easily one can take a program and run it on all of the platforms one cares about.
>>
>>56011602
what client is this
>>
>>56014684
Doesn't really matter.

You could certainly split once, assign to a variable, then use the result.

Unless you're working with millions of lines, the difference in performance is negligible.

Hell, it might even already be optimized out by the compiler; it might be caching the result of the first split and using it instead of actually splitting the second time.
>>
>>56015184
It's clearly a homebrew GUI that she's developing herself.
>>
>>56015149
I didn't know each tweet had an ID, but that makes sense. Thanks!
>>
>>56015184
Maybe it's the one they are programming, since this is /dpt/
>>
>>56015121
you can compile C code for pretty much every platform. portability of C code heavily depends on the retardation of the programmer though. there's often implementation defined or even undefined behavior involved (and also use of compiler specific extensions, this is a major problem). other languages may prevent the programmer from being exceedingly retarded
>>
You should learn Python. Here are 5 reasons why...

Versatile. Simple. Easy to learn. If you've overlooked Python, you're missing out. Take it from an expert and start learning Python now.
>>
>>56015346
Tired of all the fucking Python shills we've had day in day out this entire fucking year
>>
>>56015346
>5 reasons
>gives only three
Sasuga pythonfag
>>
>>56014565

Are you serious, mate..?

function isEven(n) { 
return 0 == n%2;
}
>>
>>56015346
It is a bad language.
>>
>>56015480
(0 ==) . (`rem` 2)
>>
>>56015480
>comparison, constant left
I like you.
>>
File: output.png (1MB, 942x512px) Image search: [Google]
output.png
1MB, 942x512px
Building a linify.me clone, right now it's about 3x faster than linify.me.
Speed peaks at 25k-30k tested lines per second(250-300 drawn lines per second with 100 tests per line) on my crusty old Phenom II.
Pic related took 228 seconds to render(36k lines, 100 tests/line, 8 thickness). Such a render would probably take more than 15 minutes on linify.me.
>>
File: 1469323138359.png (1MB, 3840x2160px) Image search: [Google]
1469323138359.png
1MB, 3840x2160px
0-3: C
4-6: java
7-9: python

rollin
>>
>>56015536
That's disgusting desu, sure you can't missplace there an assignment operator, but I think it makes the comparison look unnatural.
>>
>>56015480
>not n&1

TOP FUGGIN KEK
>>
>>56015582
not portable
>>
>>56015480
nigga I was told to use just substraction
im aware remaineder is an option
>>
>>56015598
why?
>>
>>56015513

Is that Lisp?
>>
>>56015513
*even
>>
>>56015610
It's Haskell
>>
>>56015598
Javascript is not portable.
>>
>>56015629
Yes it is, nerd.
>>
>>56015602
function iseven(n)
{
while(n >= 0)
n -= 2;
return n == 0;
}
>>
>>56015622

Eew..
>>
>>56015651
it's not though, nerd.
>>
>>56015629
Javascript is soon going to be as portable as C

How does that make you feel, faggot?
>>
>>56015652
I was asked to use recursion
>>
File: The_Pick_120112.jpg (140KB, 555x409px) Image search: [Google]
The_Pick_120112.jpg
140KB, 555x409px
>using Ruby for scripting instead of Lua

I don't get it
>>
>>56015675
function iseven(n)
{
if (n <= 0)
return n == 0;
return iseven(n - 2);
}
>>
>>56011602
>1.85GB
>1080p
LOL

This is either some new advanced compression codec or looks like shit.
>>
File: 2016-08-10-161041_963x409_scrot.png (57KB, 963x409px) Image search: [Google]
2016-08-10-161041_963x409_scrot.png
57KB, 963x409px
>>56015688
I was told to use the rules in pic related
>>
>>56015720
function iseven(n)
{
if (n <= 1)
return n == 0;
return iseven(n - 2);
}


Kill yourself, now.
>>
>>56015677
lua has no packages
>>
How do I into programming something with a GUI?

I've been practicing C++/Java for a while now just doing simple Project Euler-like programming challenges. I'm getting pretty good at it, but I'm still really intimidated by anything more complex.

How did people here get into "real" programming?
>>
>>56015731
>tries to be consise
>doesn't even maximum consise
function even(n) {
if (n <= 1) return n == 0;
return even(n-2);
}
>>
>>56015700
>What is h.265
>>
>>56015846
You just removed a newline and broke indentation, retard.
>>
>>56015665
Explain
>>
>>56015846
Not him, but:
>inline if
I don't even have a proper image of a disgusted anime girl.
>>
>>56015846
seriously?
function even(n) { return (n <= 1) ? (n == 0) : even(n-2); } 
>>
File: proof completion.png (39KB, 494x627px) Image search: [Google]
proof completion.png
39KB, 494x627px
>>56015720
Why didn't you just use Agda?
It will prove it for you
>>
File: dess-ka.png (233KB, 524x541px) Image search: [Google]
dess-ka.png
233KB, 524x541px
any haskellfags can tell me why this doesn't work?
data Statement a b = a;b deriving (Show, Eq)

b ? (x;y) = if b then x else y
>>
>>56015897
whoops, test0 shouldn't be at the top, you can't see
data N : Set where
Zero : N
Suc : N -> N
>>
>>56015897
tell me about this code
what does it mean
im not an agdafag so pls
>>
>>56015903
Type Operators have to begin with :
data Statement a b = a:b deriving (Show, Eq)
b ? (x : y) | b = x
| not b = y

you could also do a
b ?? (x : y) | b = Left x
| not b = Right y
-- x and y can be different types
>>
>>56015893
seriously?
function even(n) { return (n <= 1) ? !n : even(n-2); } 
>>
In programming jobs, is it normal for one's employer to provide free shots at lunch?
>>
recommend me a book /g/, preferably on java/jee/spring

>inb4 poo
>>
>>56016014
He wants to reach Ballmer's peak.
>>
>>56015933
-- Natural numbers are a set where
data N : Set where
Zero : N
-- Zero is a natural number
Suc : N -> N
-- The successor to a natural number is a natural number

One = Suc Zero
-- One is the successor to Zero

Two = Suc One
-- Two is the successor to One

_+_ : N -> N -> N
-- x + y, where x and y are in N, is in N

Zero + x = x
-- 0 + x = x

x + Zero = x
-- x + 0 = x

(Suc x) + y = Suc (x + y)
-- (x + 1) + y = (x + y) + 1

data _isEven : N -> Set where
-- isEven takes a certain kind of natural number (an even one) and gives you back a set (of constructors)
zeroEven : Zero isEven
-- zero is an even number, we can use this variable as a proof
_SucEven : (x : N) -> x isEven -> (x + Two) isEven
-- [x SucEven] is a proof that if [x is Even] then [(x + 2) isEven]

test0 : ((Zero + Two) + Two) isEven
-- 0 + 2 + 2 is even (this isn't known by default)
test0 = ?
-- ask the program to prove it via keyboard input
-- it generates the proof

-- test0 = (Suc (Suc Zero) SucEven) ((Zero SucEven) ZeroEven)
-- zero is even (zeroEven)
-- the successor to the successor to zero (2) is even (SucEven)
-- x2 to get to 4



>>56016014
Are you the opposite sex?
>>
>>56016089
But today we each got two double shots of different vodkas, and we had to drink both and rate them. I felt significantly beyond the Ballmer peak after them.
>>
>>56016104
Everyone gets it, regardless of sex.
>>
>>56016142
that doesn't mean the boss isn't trying to sleep with someone
obviously they're not gonna go and say shots for all the women
>>
>>56015953
oh, I see, but then the benefit of Either a b is hindered by the fact that one has to extract the value everytime

but even then, original if then requires the same type, so I guess it doesn't matter

data Cond a b =  a :> b deriving (Show, Eq)

infixr 2 ?
b ? (x :> y) = if b then x else y
>>
>>56016156
But the company is about 80% men.
>>
>>56016167
No you don't, use monads.
>>
>>56015251
How do you know that he's a girl?
>>
>>56016180
that doesn't mean he isn't trying to sleep with a woman

>>56016167
you should implement functor and bifunctor for Cond
>>
>>56016195
All programmers are female or pre-female.
>>
>>56016193
applicative maybe but I don't see that being a monad case, he doesn't necessarily want something right or left biased
>>
>>56016215
He wants a monad, everyone does. Semicolons were a bad idea.
>>
>>56016104
so agda is all about sets and proving that something belongs to a set?

im interested to see how other data structures such as trees are handled in this language
>>
>>56016197
I guess. It's been a company tradition since before we had any women, though.
>>
>>56016267
data Tree : (A : Set) -> Set where
Leaf :: A -> Tree A
Node :: A -> Tree A -> Tree A -> Tree A

you could do this in Haskell too using GADTs
or just use constructors

this is the same as

data Tree a = Leaf a | Node a (Tree a) (Tree a)
>>
>>56016193
im not versed in monads
how would they help here?
>>
>>56016311
They let you let values depend on previous values in a computation which is useful because then you can compose things using bind.
>>
>>56016311
They wouldn't
>>
Do you write function comments in imperative or descriptive form? Or something else?

>Descriptive:
// Returns true if foo is valid, false otherwise.
bool isValid(foo)

>Imperative:
// Return true if foo is valid, false otherwise.
bool isValid(foo)

I've always used imperative. I think about the comment as a plain English version of the function, that you could substitute into places where you can the function. My company requires descriptive style, though.
>>
>>56016322
I cant find anything regarding the implementation of instance Monad Either a

jog my memory here
>>
>>56016374
types are comments
>>
>>56015663
>Not knowing Lisp from Haskell
>Having an opinion
Fuck off, dilettante
>>
>>56016394
Obviously the comment isn't necessary in this case, since the function name and signature communicate the same information. It was just an example.
>>
>>56016014
Are we talking vaccines or alcohol? Either way yes.
>>
>>56016389
Well as I said earlier, it wouldn't be Either, you've got a pair of values, it would be (,) a

But that doesn't really help your situation because that's a biased monad, i.e. if you've got
do x <- (a, b)
return x

It's defined so that it'll give you the first element (or the second, I forget which one)


Either is also a monad, so you COULD use that with the secondary if statement I suggested earlier, i.e. the one that returns Left x or Right y, but that's also a biased monad where it considers Right to be proper values and Left to be exceptions
>>
>>56016389
Error handling
>>
>>56016435
>>56016389

And this is why I said bifunctor (which is in the prelude)

You should do biapplicative too, there's a bifunctor library that has it,
and bitransversable and bifoldable (you only have a single element for each type)
>>
>>56016424
Alcohol.

Today was vodka. Yesterday was gin. Monday was absinthe.
>>
guys, is there any way to incorporate a custom function to your preulude?
>>
>>56016486
What do you mean?
Define your own prelude library?
>>
>>56016486
No.
>>
File: WP_20130628_004.jpg (213KB, 1600x901px) Image search: [Google]
WP_20130628_004.jpg
213KB, 1600x901px
Had a project proposed to display an interactive video on a wall of tablets, as if it was one screen. I haven't done any real research into it yet but I'm thinking UDP multicast, maybe pipe a streamed ffmpeg output to a small application that casts it over a LAN. Then have each tablet running a web app (so I don't have to figure out how to build and deliver a native app to 50+ devices every time I want to update something). Dunno if I can do streaming video like that in a web browser though. Each web app would grab the full video stream but crop it to the portion it needs to display, based on the alignment configuration. Got a couple ideas about how to do that but not too worried about that bit of the project. Interactions would be sent back to the server (WebSockets if I do go web-based) which would be able to manipulate the video output.

Could be in way over my head here, anyone got any experience with video streaming like this?
>>
>>56016494
like, if prelude was Prelude.hs
and it contained
import Data.List
import Control.Monad
import ...
....

then I would add
import FileWithMyCustomFunction
>>
>>56016528
module MyModule (stuffYouWantToExport) where
...
...
>>
>>56016517
Sounds like a plan, have a central server that crops the video based on geometry settings and streams the data over numbered channels that go like channel -> geometry region. Then you can have each browser be connected to a specific channel (say a fullscreen browser loaded to server.domain/channelId). The problem is that you cannot have UDP in a browser natively, so you would have to write a browser plugin for that, or just use TCP with WebSockets (or maybe some RTMP channel? But that's also TCP IIRC).
>>
>>56016537
here's the thing
i don't wanna import it everytime
thats why I want it in prelude
because its always there
>>
>>56016475
too bad im too much of a haskell newfag to understand those
>>
>>56016574
Prelude is the only thing automatically imported unless using NoImplicitPrelude
>>
>>56016574
I think either cabal or GHC had an option for a custom Prelude
>>
File: 1470862404118.png (5KB, 208x242px) Image search: [Google]
1470862404118.png
5KB, 208x242px
>>
>>56016604
Bifunctor is like a functor with two type variables
With a bifunctor you can map over both of these (or just the first, or just the second)

e.g.
functor
fmap :: a -> b -> f a -> f b

bifunctor
bimap :: (a -> b) -> (x -> y) -> bf a x -> bf b y

in a bifunctor, bf a b
first f = bimap f id -- map all the a's
second f = bimap id f -- map all the b's


Biapplicative gives you bipure
>>
>>56016517
Your problem is delay and synchronicity.
A web app will exacerbate both.
A native app will suppress synchronicity problems.
A native app with preloaded video will suppress both, limited by the GPU of each tablet, supposing the app were hardware accelerated.
>>
>>56015852
h.265 still isn't this good
>>
>>56016645
so for instance, bifunctor for (,) lets you map the first or second element of a pair

first (+1) (3, "hello") = (4, "hello")
second (++"!") (3, "hello") = (3, "hello!")
bimap (+1) (++"!") (3, "hello") = (4, "hello!")

bifunctor for Either works like this
bimap (+1) (++"!") (Left "hello") = (Left "hello!")
bimap (+1) (++"!") (Right 3) = (Right 4)
first (+1) (Left 3) = (Left 4)

second (++"!") (Left 3) = (Left 3)
-- we have a [Left a], so we do nothing to it because we're mapping over [b]
>>
>>56016517
I tried to do something similar with audio. The biggest issue was getting the streams synchronized. Even if you are playing a UDP multicast stream, the latencies on the devices vary.

I think you ultimately need a sufficiently accurate clock sync across the devices, which will allow you to present the frames with accurate timing.

That said, jitter is likely much more acceptable in video then audio. With audio, one 60th of a second is extremely noticeable, with video it doesn't really matter if devices are on +/- one frame across displays.
>>
Is Daala dead?
>>
>>56016517
>interactive video
Interactive in what sense?
>>
Why is python so shit at functional programming?
from operator import add
from itertools import repeat
map(add, range(10), repeat(1))

This fails because map appends the shorter list with None to the length of the longest list. But in this case the longer one is an infinite iterator.
Back to list comprehensions I guess.
>>
>>56016704

ok these make sense
and for Biapplicatives, its pretty much applicatives but for data structures with two subtypes

still confusing because although I understand applicatives, I haven't seen a good case use for them
>>
>>56016822
>Why is {non functional language} so shit at functional programming?

The real question is why do they pretend they're any good at it?
>>
>>56016822
A better question is: why is Python so shit at programming?
>>
>>56016857
wtf u biggot
all languages can be who they want to be
who r u to tell them otherwise

map and reduce is enough to make one a functional programming lang, u biggot
>>
>>56016822
the question is: why are you so shit at programming?
>>
>>56016846
I've read that applicative parsers are equivalent to context-free parsing
>>
>>56012835
That's not a shitpost generator

make a markov chain sentence generator, that thing is pure shitposting.
>>
>>56016895
I've read that you're equivalent to a cuck
>>
>>56016857
>The real question is why do they pretend they're any good at it?
Well Guido is pretty open in his dislike for FP, isn't he?
>>56016887
come fite me irl
>>
>>56016846
yes

applicatives have injection and sequencing but don't depend on prior values, they're more general and apparently easier to optimise

they also give you <*>


>>56016895
yes, monads give you dependency on prior values, but applicatives don't
>>
>>56016916
Well Guido's just a moron isn't he?

Python is what happens when you ignore 30 years of PL research.
>>
>>56016822
I completely retract this post, I didn't realize itertools literally has its own map for this purpose
https://docs.python.org/2.7/library/itertools.html#itertools.imap
> Like map() but stops when the shortest iterable is exhausted instead of filling in None for shorter iterables. The reason for the difference is that infinite iterator arguments are typically an error for map() (because the output is fully evaluated) but represent a common and useful way of supplying arguments to imap().
>>
>>56016936
I thought that was Go?
>>
>>56016922
i don't understand
in
Just (+) <*> Just 2 <*> Just 3

clearly the 2 depends on the function
and 3 depends on the binary function
>>
guys, so in javascript
is everything built on object and lists?
even trees?
>>
>>56016977
And you'd be right.
>>
>>56016997
No they don't, they're always Just 2 and Just 3. If you could change it, for example to Just 4 based on a previous computation, that would be depending on something
>>
#include "SingletonClass.h"

class Foo {
public:
void Bar(){
SingletonClass::Instance()->someFunction();
}
}


Why do I get a "SingletonClass has not been declared" error? I also tried forward declaration but it didn't like that.
>>
>>56015598
>ones complement
No point compiling for that shit anyway
>>
>>56017044
post your header file
>>
>>56016997
You can't decide how to put it back into the context, you can only decide what the new value is

e.g. bind takes a
a -> m b

but apply takes a
a -> b

and applicatives don't have "join" so you can't turn an f (f a) into an f a
>>
>>56017057
Oh shit, my SingletonClass.h file #includes Foo.h. Will that cause a circular inclusion error? They're both using include guards.
>>
>>56017083
>Will that cause a circular inclusion error?
100% yes
>>
>>56017083
Yes, you should reboot because your IDE will have become stuck.
>>
>>56017083
You need to include one header in a header file and another in the source file to avoid that.
>>
>>56017136
Yeah, you're right. I inlined a function in the SingletonClass.h that created a Foo object. I just moved that function into the SingletonClass.cpp and now it works.
Thanks anons.
>>
JavaScript is actual fucking garbage (if you want to know why I would bother, I need to use a library that is JS-exclusive).
Can't read from stdin without a package, CANNOT read a password from stdin without echo.
Utter SHITE.
>>
>>56017293
The first rule of programming: It's always your fault
>>
noob here

why does this output funky things?

#include <stdio.h>

main()
{
int z[]={1,234,2,4,5,1,5};
int i;
int tot;

for (i=0;i<7;++i){
printf("%d\n", z[i]);
tot += z[i];
printf("%d\n",tot);
}

return 0;
}
>>
>>56017293
kys
>>
Alright
I need to simplify facorials in python. I have sympy and mpmath installed.
What i need is, for example, that x!/(x-2)! returns x**2 - x. This does not work using just sympy and mpmath, however, as it returns an error: TypeError("cannot create mpf from " + repr(x)),

Why does this happen? Am i doing anything wrong by expecting that
import sympy
import mpmath
x=sympy.symbols("x")
print(mpmath.fac(x)-mpmath.fac(x-2))


returns x**x - x?
I am new to python, so the solution is probably right in front of my face...
>>
>>56017346
I dunno, what is it outputting?
>>
>>56017346
it doesn't. you're just retarded
>>
>>56017374
nevermind, i resolved

The problem was
>
        printf("%d\n",tot);

being in the loop

>>56017385
i guess
>>
>>56017371
http://docs.sympy.org/dev/tutorial/simplification.html
>>
>>56017434
i have tried all of those, but none work for some reason.
>>
>>56017321
Not always, sometimes there's a compiler or kernel bug, or a bug in some other dependency.
>>
>>56017445
import numpy as np
import sympy as sp

n = sp.symbols("n")
F = sp.factorial

f = (F(n) + F(n + 1)) / F(n - 2)
print(f) # => (factorial(n) + factorial(n + 1))/factorial(n - 2)

f = f.simplify()
print(f) # => n*(n - 1)*(n + 2)
>>
I started a project of making Emacs a text editor. I am now investigating how to make it a bit more modular in a sane way. First business was removing all the toys (Tetris under "Tools" seriously now), which was easy. Removing their then empty menus was easy enough as well, and revealed bunch of oddities in code I'm now exploring.

Learning a great deal in process. Gotta hand it to GNU folks for immensely readable code. It's self-documenting.
>>
>>56017446
yes but in this case, it's your fault
>>
File: q.gif (499KB, 500x270px) Image search: [Google]
q.gif
499KB, 500x270px
>>56017483
>>
>>56017498
thats not even me, but how is it my fault that js is shit
>>
>>56017481
Yeah, i figured it out. Sympy has its own factorial function. Its a shame, since now my code will be even more messy than it already is. Thanks for the help regardless!
>>
>>56015677

Ruby is great for scripting, dude..

Can you show me this in Lua?

#!/usr/bin/env ruby

def say_hello
puts "Hello sir, what would you like to do?"
puts "1: Exit"
puts "2: List all pdf files in subdirectories"
puts "3: Put text input to file"
end

def programm_loop
say_hello
case gets.chomp.to_i
when 1 then puts "Goodbye!"; exit
when 2 then puts Dir["**/*.pdf"]
when 3 then puts "Enter filename and text:"
name, txt = gets.chomp.split(' ', 2)
File.open(name << ".txt", "w") do |f|
f.puts txt
f.puts "Fuck you, anon."
end
# file got closed automatically here
end
end

#execute programm
programm_loop
>>
>>56017498
It wasn't my problem, I just think that's a terrible rule to repeat. If you don't verify that the dependencies are functioning correctly, you might end up wasting a ton of time debugging correct code.

In general, if you've created a minimal test case that reproduces the issue, and still can't find an issue in your code, you should take a break, come back, take another pass through the code, then start looking into problems in the dependencies / toolchain, break out the debuggers, etc.
>>
>>56017530
That's pretty obvious if you stop to think about it. How the hell is sympy going to know what a different libraries function is supposed to do? It's not like mpmath is as well-established as something like numpy.
>>
QUICK, MAKE A REVERSE POLISH NOTATION CALCULATOR IN YOUR FAVORITE LANGUAGE

RPN "10 4 3 + 2 * -" ==  -4
>>
File: 1470687725229.png (301KB, 470x536px) Image search: [Google]
1470687725229.png
301KB, 470x536px
>becoming a programmer by going to college
Is this a good idea
>>
>>56017630
RPN is shit, use prefix like sexpressions do
>>
>>56017640
hahahahahahhahahahah
>>
>>56017640
no
>>
>>56017630
s=[]
for x in input().split():
try:s+=float(x),
except:o='-*+'.find(x);*s,a,b=s;s+=(a+b*~-o,a*b**o)[o%2],
print(s[0])
>>
>>56017537

Sorry, I jsut notice I forgot to put "programm_loop" as last statement into the definiton, this way it won't loop.


But anyway, it was just a quick example that you can do scripting just fine in Ruby..
>>
>>56017683
the fuck is this
I feel like you copied this from somewhere.
>>
>>56017749
get rekt pleb
>>
>>56017640
Buy/Pirate textbooks and study
>>
>>56017630
#include <stdlib.h>
#define kek *p>47|*(p+1)>47
char*p;
float lmao(float m) {
float n = strtof(p, &p);
kek ? n = lmao(n) : 0;
for (; *++p == 32;);
m = *p % 43 ? *p % 45 ? *p%42?m/n:m*n:m-n:m+n;
return *++p && kek ? lmao(m) : m;
} main(c, v) char**v; {
printf("%f\n", lmao(strtof(v[1], &p)));
}
>>
>>56017813
DON'T COMPILE THIS IT MAKES MUSTARD GAS!!!!!!!!!!!!!!!!!!!!
>>
>>56017813
yeah, this doesn't look like rpn
kys
>>
Anyone in here work with a team that is heavily influenced with office politics?

What about teams with Russians on them? How do you deal with them?
>>
>>56017882
>i can't understand the code
>better tell him it doesn't look like rpn
>that'll show him
fuck off retarded
>>
Am I the only one that feels sort of divinely inspired to write code after jerking it?
>>
>>56017899
>office politics
yuck
i heard about some meme blog that talks about machiavelian methods to establish control in your favor
>>
>>56017916
It probably means you were procrastinating it before and fapping released your tension
>>
>>56017913
make a webm of you compiling it and running, fag
>inb4 no screen capper
ffmpeg works
>>
>>56017927
we're two sprints away from code freeze and a customer escalation rep 'redesigned' the UI for a new feature because she likes it better, some how she has influence enough that this shit is even entertained.

I'm the new fish, its absolutely baffling to me.
>>
>>56017813
>*p % 43 ? *p % 45 ? *p%42
Unportable

>>56017882
It does for me actually
>>
>>56017945
do it yourself, fag
>>
File: Screenshot_2016-08-10_23-42-15.png (99KB, 916x522px) Image search: [Google]
Screenshot_2016-08-10_23-42-15.png
99KB, 916x522px
>>56017945
here you go baby
>>
>>56017959
does the new UI conflict heavily and makes new chores for other programmers?

if not, don't worry about it
>>
>>56017813
this shit is more unreadable than haskell
>>
>>56018013
They mostly are trying to make the web act like a windows form application ("Whats a toggle switch?", "No one uses mobile") and text changes (for the fifth time).

The dude i'm working with is so obviously checked out from all these, broken inside.

Just kinda worried about the future, venting.
>>
>>56018026
so not only u have a problem
more pipl = more power
just talk her up
if she doesn't care, just do the job that way
you're getting paid anyways, right?
>>
is being a good programmer genetics or can it be learned?
>>
>>56018105
Learned.
>>
>>56018105
Genetics.
>>
>>56018105
Both.
>>
>>56017630

def pol_notation i
eval = []
i.split.each do |i|
case i
when /\d/ then eval.push(i.to_f)
when "-", "/", "*", "+", "**"
op = eval.pop(2);
eval.push(op[0].send(i, op[1]))
end; end;
puts eval
end

pol_notation "23 2 * 4.5 -" # 41.5
>>
>>56018105
Neither.
>>
>>56018105
Neither.
>>
>>56018105
Could you repeat the question?
>>
>>56018105

i can fizz buzz but my mind goes blank when i try anything crazy hard

it sucks. Pretty sure genetics play a huge role
>>
>>56017630
Something like this

RPN[rpol_String] := Module[{ops},
ops = {"+", "-", "*", "/"};
NumericStringQ[s_String] := Quiet@NumericQ@ToExpression[s];
f[s_String] := g @@ StringSplit[s];
g[n_?NumericStringQ] := n;
g[stuff__, n_?NumericStringQ, op_?(MemberQ[ops, #] &)] := Sequence[n, op, "(", g[stuff], ")"];
g[n_?NumericStringQ, stuff__, op_?(MemberQ[ops, #] &)] := Sequence[n, op, "(", g[stuff], ")"];
ToExpression@StringJoin@f[rpol]
]
>>
>>56015500
>>56015451
>>56015346
Its not a bad language, it is a a tool with a purpose.

I like it right now as I have to quickly whip up back end tools for Webdev/ enterprise management. Most of the strength of what I do relies on SQL. Python quickly can take my workload off of the SQL server and into the hands of the local machine.


I plan on moving to C or C++ next, so long as there is modern application for it when I choose to.
>>
>>56018234
>>56018139
>>56017813
>>56017683
>>56017683
lmao not even extensible
what happens if I want "2 sin 3 + cos ln"

STABBED
>>
>>56018354
dunno. don't care.
>>
>>56018393
you failed faggot
>>
File: 0.2529995, 0.000249.png (51KB, 812x833px) Image search: [Google]
0.2529995, 0.000249.png
51KB, 812x833px
I made a thing that shows you the Mandelbrot set in ASCII, and it can zoom in and things.

Here's a picture of it zoomed in waaaaaay up inside the butthole of the set
>>
>>56018434
http://pastebin.com/zQ9KPtep

Did my part today of cluttering up pastebin with useless shit
>>
>>56017640
school is for the degree, skill only comes from yourself. If you can only push yourself to program from being cottled by an institution you'll just be fish food, otherwise go for it
>>
>>56018466
>>56018434
beautiful. you forgot
 #include <string.h> 
>>
>>56018578
Fuck, you are right, added that strlen function at the very end and forgot to put the library back in.
>>
>>56018629
you can use
 puts(output); 
instead of
 printf("%s\n", output); 
>>
>>56018677
I fucked around a lot with both of these functions because I'm too lazy to read manuals and used to the cout stream of c++, yes puts would be better here for sure
>>
what does this error mean and how do i fix it? pls help im desperate

> 'CommerceBuilder.Products.ProductCalculator' does not contain a definition for 'MSRP' and no extension method 'MSRP' accepting a first argument of type 'CommerceBuilder.Products.ProductCalculator' could be found (are you missing a using directive or an assembly reference?)
>>
>>56018354

OK birdmin, have your extensible reverse polish notation thing, just don't stab me, 'K?

def RPN i
o = []
i.split.each do |i|
if i =~ /\d/
o.push i.to_f
elsif i =~ /[a-z]/
t = o.pop
o.push(eval("Math." + i + "(t)"))
else
t = o.pop(2)
o.push(t[0].send(i, t[1]))
end
end
puts o
end

RPN "2.5 2 * 0 cos -" # 4
>>
>>56018778
just google they keywords of your error

http://stackoverflow.com/questions/27110994/string-does-not-contain-a-definition-for-fill-and-no-extension-method-fill


http://stackoverflow.com/questions/32169574/applicationdbcontext-does-not-contain-a-definition-for-items


you might find something
>>
newbie here

Is there a reason this works:
public int[] frontPiece(int[] nums) {

if (nums.length >= 2) {
int[] newarray = {nums[0], nums[1]};
return newarray;
} else {
return nums;
}
}



While this doesn't?
public int[] frontPiece(int[] nums) {

if (nums.length >= 2) {
int[] newarray = {nums[0], nums[1]};
} else {
int[] newarray = nums;
}

return newarray;
}
>>
>>56018893
newarray
falls out of scope.
>>
>>56018893

I'm not 100% sure since it's been a while since I coded in Java..

But I would say this line is the problem:
int[] newarray = nums;


Java is "call by value". But since an array is an object the new created "value" is a reference to the input array.

Now you have this local reference and put this reference to a new variable. Then you return the variable and the local reference gets destroyed. So you reference a destroyed reference.

I'm not 100% sure about this one, though.
>>
>>56019138
Java's memory model keeps everything alive as long as there's a reference to it

>>56018893
The reason is that both "newarray"'s scope are limited to their blocks.
>>
>>56019232

>Java's memory model keeps everything alive as long as there's a reference to it

I stand corrected..

But I don't understand this correctly:
>The reason is that both "newarray"'s scope are limited to their blocks.

The only difference between the "working" and the "non-working" version is this line:
int[] newarray = nums;


And since you pass "newarray", how can it be out of scope?
>>
Am I not able to pass list comprehensions as arguments to functions in Haskell?
>>
>>56019365
What are you talking about?

tail [ x * y | x <- [1..3], y <- [6..8] ]
>>
>>56019451
Huh, that's strange
I'm trying to implement the all function using foldr, but ghc is complaining about me passing a list comprehension to it
all2 :: (a -> Bool) -> [a] -> Bool
--all2 pred [] = True
--all2 pred (x:xs) = pred x && all2 pred xs
all2 pred xs = foldr (&&) True [x | x <- xs, pred x]


The code's wrong anyways though, since it always returns true
>>
>>56019498
This is the mistake you're making
[ x | x <- xs, pred x ]
or
filter pred xs
you're filtering a list of [a]s, to get back a list of [a]s

then you're trying to fold && on them, from True
they aren't bools, they're a's

try this instead

foldr (&&) True $ pred <$> xs
or
foldr (&&) True $ map pred xs
>>
>>56019541
or
foldr (&&) True $ [ pred x | x <- xs ]
>>
>>56019541
>>56019548
Well, it worked, but I haven't learned what the dollar sign does yet
>>
>>56019568
f $ x = f x
You mostly use it to avoid parentheses, because it has a different operator precedence
e.g.
foldr (&&) True (pred <$> xs)
foldr (&&) True (map pred xs)
vs
foldr (&&) True $ pred <$> xs
foldr (&&) True $ map pred xs
Also useful when you're composing functions, because you can do f . g $ x rather than (f . g) x

But you can also use it to explicitly refer to function application as a function (e.g. when passing it to a higher order function)
>>
Working on a facial recognition app. It's mostly finished, but suggestions and bug reports are welcome:

https://www.raskie.com/#mememe
>>
>>56019594
Oh wow, that's pretty simple (and useful). Thanks m8.
>>
on C with the visual studio compiler why can't i do this ?
const int n = 5;
array[n] = {0};

throw me a "expected constant expression"
>>
>>56019628

an example for function application would be this

let fs = zipWith ($) [ (+), (*), (/) ] [ 1.. 3] in
zipWith ($) fs [4..6]
>>
File: 1468157500901.png (588KB, 1440x810px) Image search: [Google]
1468157500901.png
588KB, 1440x810px
>>56019626
>>
File: ..jpg (104KB, 540x778px) Image search: [Google]
..jpg
104KB, 540x778px
How do you guys not burn out? :(
>>
>>56019648
mh i read the cpp example on msdn and not the c one.
I see i have to #define n 5. But why though? doesn't this work with other compiler ? is it bad in some way?
>>
>>56019648
In C, all const means is that the value is constant. It does not guarantee that the value is a compile time constant, which it has to be. Therefore the compiler throws an error.

You should do #define n 5

In C++, your code would be valid. It's not permitted in C essentially to make a C compiler simpler to write.
>>
NEW THREAD!!

>>56019764
>>
>>56019594
not him, but wtf man
why would you a $ in this case
>>
>>56019808
Brackets are the devil
>>
>>56019760
ok i get it ty for the explanation
>>
>>56019837
not sure about you, but I hate when parentesis are together
like in
nigger(ass(dick()))

but in a simplce case
of nigger(ass), im ok
its when they're adjacent that I hate them

thus

map (+2) (iterate id 2) is fine

but not
map (++[]) ([cycle [2], cycle [3]])

>>56019696
construct plans to kill people, almost go through with them, but always let them go, its perfect.
keps the sense of suvavial in my mind

for the fbi/cia, ^ was a joke
>>
>>56019345
Look at the code again. In the first one, the return is in the same block as newarray. In the second one, it is outside.
Thread posts: 317
Thread images: 30


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