/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: 1537917658000.jpg (1200x1091, 1.25M)

Other urls found in this thread:

ix.io/1nW7
shenlanguage.org/
clhs.lisp.se/Body/d_type.htm
clhs.lisp.se/Body/m_deftp.htm
clhs.lisp.se/Body/04_bc.htm
wiki.haskell.org/GHC/Memory_Management
crystal-lang.org/
nim-lang.org/
wiki.haskell.org/Handling_errors_in_Haskell
twitter.com/NSFWRedditImage

what the fuck is up!!!!!!!!

WebAssembly, I can now play my CHIP-8 emulator on the web with a PS4 controller

Unfortunately, SDL natively deals with the keypad differently to emscripten's SDL

Attached: 1537904224252.jpg (800x934, 121K)

help
ix.io/1nW7

Attached: download (7).jpg (225x225, 9K)

mommy

Lisp is the most powerful programming language.

Lisp does not have and cannot have a powerful static type system

Is Pascal still a relevant language?
Why does Jow Forums never talk about pascal?

Because C won.

*dependently type checks your path*
shenlanguage.org/

clhs.lisp.se/Body/d_type.htm
clhs.lisp.se/Body/m_deftp.htm
clhs.lisp.se/Body/04_bc.htm

I saw one (1) offer for a delphi job in my entire life. I don't think many people still care.

t. bowsette nigger

That's eelette, negroid. This is bowsette

Attached: 1537904673118.jpg (724x1024, 85K)

JavaScript rocks!

up vote

Unironically this

you mean JavaScript bricks
like bricks your device

I want to MAKE LOVE to Bowsette!

The only people who say shit like this are faggots who are either too cowardly to try different languages, or too stupid to understand why other languages are superior.

I also love javascript, it's so useful and gratifying to use. Fuck yeah javascript.

>That's dumb weeb shit. This is dumb weeb shit.
What's the point of your post, you disgusting attention whoring anime pedo faggot?

>javascript

Attached: javascript.png (270x175, 5K)

theres literally nothing wrong with this

I am unironically learning this so that I can get a job competing against Raj and Dirpreek. Tired of being a neet. upvoted

>javascript

Attached: js.jpg (1024x576, 103K)

[5,1,20,10].sort() // [1,10,20,5]
Is the default behavior to reinterpret the numbers as strings? kek

>0 == ""
n-nani?

You learn to live with it eventually.
It's the one language that everybody with a modern browser can use, so of course it's a mighty force to compete with.

Attached: 2018-09-30_18-21-29.png (171x121, 3K)

Hey Haskell folk

Is there any way to turn a [ IO () ] into a IO ()

Like if I had

[ putStrLn "WOW"
, putStrLn "OKAY"
]

could I lay it all out like
do
listOfPutStrLns

somehow?

>JavaScript

Attached: js.webm (1280x720, 1.66M)

Flatten a list of lists in your language of choice
here's Javascript
const flatten = ([first, ...rest]) => [
...(Array.isArray(first) ? flatten(first) : [first]),
...(Array.isArray(rest) && rest.length ? flatten(rest) : []),
];

flatten([[1,2,3], [[4,5,6], [7,8,9]], [10,11,12]]);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

Looks dumb when the array is only numbers but it also work with arrays of anything. At which point it's still dumb but the kind of dumb you expect from javascript.

Attached: Pajeet.jpg (3000x1688, 461K)

ArrayFlatten[A]

Attached: compact_semisimple_Lie_touhous.png (711x514, 348K)

JavaScript is the language of trash devs.

>Weapon of DURGASOFT
w-what is nagoor babu planning?

[5,1,20,10].sort((a,b)=>a>b)

Fucking Javascript

That's interesting. What is that, some kind of pattern matching on arrays?

please

[[1,2,3],[4,5,6],[7,8,9]].join.writeln;

woo Haskell
List.concat

If I want to learn how to manipulate windows function, i,e, something like behavior of window, wifi switch automatically, hotkey for changing language, what is the best book for it for beginner? Preferably in C++ but I can also do C if I have to.

Data.Foldable.traverse_

These don't flatten any more than one level deep

It's just recursive application of the spread operator

>do this
>i do that
>faggot like you adds another random stipulation
every time

my bad, you don't want to pull it through a function
Data.Foldable.sequenceA_

>don't know what flattening is
>literally has example code showing exactly what it should do
>do a different thing that is only part of what was asked
>waaah u dun changed the requirements
Fuck off retard

That's a consequence of weak typing, which I personally don't like, and nobody who uses JS really takes advantage of it. You can get ugly shit with a lot of languages, eg I love Python, C and C++, but C++ has loads of constructs you can abuse in combination, C has a lot of obfuscated examples and define macros can really fuck shit up, and Python has loads of built-in conveniences that make FizzBuzz of the Christ possible

>example is flattening a range of ranges
>i do that
>NO YOU'RE WRONG
wwwwwwwwww

Thanks. Ill look into these

which?

{
switch {
...
default:
return defaultReturn
}
}


{
switch {
...
}
return defaultReturn
}
[

(define (flatten l)
(if (list? l)
(apply append (map flatten l))
(list l)))

Not him, but where do you even get your definition of flatten? I'm sure by default everyone knows that the common flatten problem (which has appeared in some of my interviews) is of variable depth

I fucked up the second one.

{
switch {
...
}
return defaultReturn
}

Except you aren't flattening. Joining a list of list is not the same thing as flattening.

How do you deal with out of memory failures in Haskell?
For example if a closure needs to allocate memory and you're out of memory.

I'm trying to get into JavaScript (coming from C/C++). The prototype inheritance is really .... intriguing. But I'll figure it out.

Attached: 1482332911481.jpg (655x527, 36K)

flatten by the OP's example.
i read example output
i provide such output.
If you want me to do a different problem, supply it.

def flatten(arr):
if type(arr) is not list:
return [arr]
new_arr = []
for ele in arr:
new_arr.extend(flatten(ele))
return new_arr

Re-read the OP's example. The second element is a list of lists, which he properly handles and you do not.
Go be stupid somewhere else

function flatten() {
throw new Error("Stop being an asshole and try learning a real programming language");
}

>flatten by the OP's example.
Nope you didn't

Just fyi I dont think anyone really looks at that kind of thing because JS people try and be functional.

If you're out of memory, you have to wait until memory is free.

wiki.haskell.org/GHC/Memory_Management

nice
you should use isinstance
if not isinstance(arr, list):
return [arr]

I personally hated OOP in most languages, which is why I prefer C. Prototypal inheritance is definitely intriguing, cant say it's good or bad, since professional, it's not something you deal with unless you're making a library/framework, but best way to deal with objects in JS in general is to just imagine you're dealing with JSON instead of a conventional language's objects

>which?
Neither. Don't use switch statements unless you're actually in a situation where you need to take advantage of fallthrough (probably never). They generally offer no control flow benefits past existing constructs and make it far easier to accidentally insert bugs. There's a reason modern languages have dropped it entirely in favor of match statements, which are much more useful and safe.

Yes, but how do you catch it in your program so you can deal with it gracefully?
It's a must if you wanna write reliable software.

my daily work is in ruby, but I've been wanting to branch out. never done anything serious in a compiled language, and I'm trying to decide between haskell and go.

haskell seems really interesting but I don't know what kind of things I can do with it for fun projects. with go, I could build a home media server, irc client, etc

anyone have any suggestions, or ideas for haskell projects? I know the basic syntax and concept of fp, but I just don't see any use cases in my personal life.

>my daily work is in ruby
>want to try a compiled language
Crystal

Completely forgot about it, thanks

llvm clang vs gcc

fight

i get the appeal, but I'd prefer to go to something as different from ruby as possible. I want to improve and push my limits basically

crystal-lang.org/
nim-lang.org/

Go is shite, Carmack is using Haskell to do the Doom engine, plus there is an NES emulator in Haskell. Its conventions means that some FP fans hate it, but it's quite elegant

>ideas
maybe an emulator for the architecture at challenge.synacor.com

Alternatively, C can be pretty fun

GHC

I know less now than I did 5 minutes ago, how is that possible?

Attached: 3.jpg (952x720, 81K)

>best way to deal with objects in JS in general is to just imagine you're dealing with JSON instead of a conventional language's objects
Yeah, I know. I just have to get used to it.

wiki.haskell.org/Handling_errors_in_Haskell

Please give me some interview questions to practice, guys. I'll try my best to solve them.

Yes, I can already do fizbuzz

What language would get me a gf like Bowsette?

kys

Write an emulator

GCC has been around longer and is more ingrained than LLVM, but LLVM is clearly better designed and caught up to GCC's years of performance tweaks very quickly. Its introduction also finally caused GCC to add some much needed features just to compete, as it was stagnating before LLVM came along.
I would say LLVM is now better than GCC and I only expect its lead to grow from this point on.

Not an interview question but i've already made a small chip-8 emulator

Flatten a variable depth list

Let's see? If not the code, just a webm or gif or image

it still has a small, but very active community. I think of it kinda like the Plan9 of programming languages- a good idea from a bygone time, with a cult following buried somewhere on the internet.

Okay, give me a few minutes

Sorry, it was for a class a few years ago. I'll see if I can find it on my old computer

please call it a rose tree
a list shouldn't contain both elements and lists

Okay, how's this?
test_array = [[1,2,3], [[4, 5], 6, 7], 8, [[[9]]], [[[[[[[10]]]]]]]]

def flatten(arr):
result = []
for entry in arr:
if type(entry) == list:
result += flatten(entry)
else:
result += [entry]
return result

print(flatten(test_array)) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Attached: dpt.png (457x185, 53K)

Nim

I'm currently working on Go. I already know JavaScript, and am thinking of trying TypeScript after I can competently code in Go.

Nothing. Though if you want to impress normies and girls learn Swift.

Pretty damn similar to mine posted earlier, nice
>tfw I was asked this during an interview and never heard of the problem and completely blew it

I need some serious help anons. Basically, there is a program vulnerable to string format vulnerability on a little endian machine. I need to modify a single int from 0 to 1 in order to accomplish a task. I figured out that the int is always stored as the 8th item on the stack but the address is changed every time the program is run. Now what string format do I need to send in the modify the variable at that stack to 1? Please help anons. I know you all are amazing at C

now do it in O(1) space