/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1558990501763.jpg (768x1024, 128K)

Other urls found in this thread:

youtube.com/watch?v=48ko-s_ePbc
springer.com/gp/book/9781461444626
infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100748_0606_00_en/dwe1472208421505.html
leetcode.com/problems/valid-parentheses/solution/
twitter.com/AnonBabble

Learning Haskell right now.
Still trying to wrap my head around Applicatives and Monads

Lisp is the most powerful programming language.

applicatives are based and redpilled
monads are cringe and bluepilled

easy explanation of applicatives: functor f is applicative if it can be distributed over tuples
(f a, f b, f c, ...) -> f (a, b, c, ...)
pure a is () -> f (), then fmap (\() -> a)

post your code

Attached: ss.png (1889x1135, 455K)

Anone, you know you're behind on your JavaScript lessons, right?

Attached: d1073bf0fdf03391be4077f3a37429a8.jpg (592x888, 411K)

>monads are cringe and bluepilled
Still, I think do notation is pretty neat.

there's a GHC extension ApplicativeDo that will allow some things to be purely applicative, namely if you have
x

Still working on plugy stash reader.

>You don't need to break from the switch if you return from the function.
what does this mean? I'm a total beginner. Do I only need to use breaks if I'll use the outcome in the function as a helper function or?

Nice. Make sure to have something else lined up for when you realize that category wankery is not useful for real programs though.

yes
function* range(a, b) {
"use strict";
a |= 0;
b |= 0;

const c = a > b ? -1 : 1;

if (a ^ b) {
do {
yield a;
} while (b ^ (a += c));
}
}

If you do
int foo()
{
for (;;)
{
return 0;
}
}
Then you're automatically exiting the loop as part of exiting the function.

Is Erlang/Elixir useful at all for non-networking applications?

I need some ideas on how to make a decimal button from a calculator in gdscript

Attached: 155580232439.jpg (793x786, 62K)

ok, so I never need breaks in functions with a return x;?

@71236510
>mac hom OS X
>vs onions code
>webshit

Practicing pointers and datastructures.

71236687
dumb frogposter

yeah if you're returning within a loop you don't also need a break statement

>@

It depends. If you have a switch that returns only in some cases you still want your break.
i.e.
switch(cond){
case foo: return 3; //no break needed because return exits the function
case bar: x = 5;
break; //break neded because otherwise it continues on to the next case
case baz: ...;
}

Not really, no. If you want to do anything local I've found other functional languages suited far better because of available libraries and bindings for libraries.

Sometimes, I just want a simple global pointer variable.

Attached: Screenshot_20190603_001951.png (552x554, 42K)

That's what it looks like. So it's mostly only useful for telephone comms and WhatsApp

>needing unsafe to mutate a static variable
the ABSOLUTE state of Rust

ok, I'm wondering about this video
youtube.com/watch?v=48ko-s_ePbc
so just to be sure the breaks in the code at around 4:00 are just taking up space right, since she already has a return statement for everything?

I agree. The "b-b-b-ut it's not th-thread safe" justification is dumb. This programming will never run on multiple threads.

yeah, they're useless.

I'd assume it's also really neat if you want to have a distributed network of *anything* and have it run forever. It could even just start programs written in other languages doing more complicated stuff while the Erlang code just distributes the results between the nodes.

I have come to the conclusion that this is the best use-case for Erlang (as long as you're not doing telephony or chat servers).

moan ads are just burritos, what's the hard?

Rust's obsession with immutability is a blight. Most shit isn't going to be threaded, making it so difficult to mutate is asinine.

thread safety isn't the only thing you get of immutability

If you need that, why not just plug in into RabbitMQ or Kafka?

>need to add feature X to code base I haven't touched in a while
>it's similar to existing feature Y (almost the same thing but in reverse) so I figure it won't be too hard
>look closer, realize it's a bit more complicated than that
>will require a different data structure and algorithm
>spirit sinks a bit since it's a much bigger job than I expected
>suddenly notice data structure and associated functions to do X already exist
>commit from July last year "Add X structure for symmetry with Y"

YAGNI my ass.

I owe last year me a beer.

Attached: mua.jpg (462x533, 68K)

It's the only thing you get out of mandatory immutability.

Happens all the time.

nice anecdotal evidence

RabbitMQ is written in Erlang.
Kafka: Why would anyone run Java if they could avoid it?

>It's the only thing you get out of mandatory immutability.

Attached: 1532775354305.png (800x450, 141K)

dumb rust poster

>drinking alcohol

>making it so difficult to mutate is asinine
If it's not in performance critical code then you can just use the appropriate smart pointers if you don't want an unsafe block.

If it is performance critical then the chances are you may later come back to optimize it through parallelisation. At which point your assumptions would be wrong and then you'd have to remember all the assumptions you made and modify them. Possibly leading to bugs if you forget something.

Honestly I can't see what the problem is.

Attached: 1556670283732.png (1280x720, 753K)

/dpt/-chan, daisuki~

>What are you working on, Jow Forums?

Crafted an Emacs native module to dynamically change font rendering settings (see webm where i turn anti-aliasing on/off several times.).

Attached: scr-2019-06-02_23.41.47.webm (1668x880, 934K)

how do you get rid off the feeling of complete disgust after spending a bunch of time on the same problem

Attached: sleep.jpg (440x440, 30K)

Solving the problem and moving on to the next one.

Masturbation

Some guy simulate brain activities using model concurrency in erlang.

Handbook of Neuroevolution Through Erlang
springer.com/gp/book/9781461444626

Jeff Dean google engineer had that book in this photo.

Attached: E7065F1C-4797-4FE5-9A77-A44E4437AF6D.jpg (659x466, 51K)

is there any reason to take a std::function by rvalue reference instead of const reference?

>RabbitMQ is written in Erlang.
It is.
>Kafka: Why would anyone run Java if they could avoid it?
Apparently has higher throughput than RMQ and is overall better for data pipelines.

If you want to move the lifetime? std::function does a heap allocation

>|= 0
why

it's an int32 cast

some awkward hack as a cast? oh right, it's javascript, nevermind.

It's not a hack. Why would it be a hack? Bitwise operations convert their operands to the required types which are (u)int32, unless one is a bigint then both are required to be bigints.

That's kind of cool, it would make it convenient to test font settings.

It's a hack because you're using bitwise OR to cast to an int. Not to do a fucking bitwise OR.

Why is x | 0 not a legitimate use of a bitwise OR?

Kill yourself to death immediately

Because in any sane language x | 0 would be a no-op.

why should or eax, 0 not be a valid instruction?

>arguing semantics
I really don't care for this. If you think that casting to int by |= 0 makes sense then good for you.

I'm having a uni project where I want to run C code on an ARM-processor as fast as possible.
It seems like GCC won't compile it to 64-bit, unless I am mistaken. But that's what I saw when inspecting the .o files with objdump

I found the ARM Compiler 6. I am not quite sure how it works but it seems like you just use command line argument like
armclang --target=aarch64-arm-none-eabi hello.c
to compile C code to AArch64 assembly, seen here:
infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100748_0606_00_en/dwe1472208421505.html

I tried installing it on Linux, but whenever I try to type in armclang, it just says command not found.
What should I do? Would really appreciate some help. If there's just some workaround with GCC to make it compile to AArch64, I would be happy to know

Attached: 1477171792288.jpg (625x833, 125K)

Well, you should check whether it's in your path (echo $PATH) and has executable rights for your user.

gcc does support aarch64, you need a cross-compiler. look into how to build one one for your distro.

So it's useful in neutral networks. That's neat.

>build one
Most distro's will have one in the repos. On debian it's gcc-aarch64-linux-gnu.

this was nigger challenge. made things way too complicated then i relaized how easy it could be.

def valid_parenthesis(s):
symbols = ['()', '[]', '{}']
count = 0
a = 0
for i in s[a:]:
for c in s[::-1]:
if i + c in symbols:
count += 1
break
if count == int(len(s))/2:
return True
else:
return False
print(valid_parenthesis('(()[]{})'))

how do I add an integer to the end of a float right at the right most value?

Attached: 1555533395828.png (1373x833, 59K)

retarded frogposter

that's wrong though
>print(valid_parenthesis('((][]{})'))
>True
use a stack.

user, I....
just use a stack machine user.
use recursion.
find a bracket; call the function again for the inside, and await the last bracket afterwards.

thanks, although I figured out that already.
However, I am confused again:
I compiled it on my PC, transferred it to a USB-pen and then compared the obdump output with the objdump on C files compiled on the 64-bit Raspberry(running Ubuntu for AArch64), and they are practically identical.
I then decided to compare it with the same code compiled on Rasbpian(32-bit) and they are slight different, however both only use 32-bit instructions.
Here's the first 5 instructions on the AArch64
7b4: d13f03ff sub sp, sp, #0xfc0
7b8: a9007bfd stp x29, x30, [sp]
7bc: 910003fd mov x29, sp
7c0: 90000080 adrp x0, 10000
7c4: f947f000 ldr x0, [x0, #4064]

And here's for ARMv7:
10500: e92d4800 push {fp, lr}
10504: e28db004 add fp, sp, #4
10508: e24ddefb sub sp, sp, #4016 ; 0xfb0
1050c: e24dd008 sub sp, sp, #8
10510: e3a03000 mov r3, #0

So could it be that GCC on my Ubuntu build does indeed compile to AArch64, but the reason why 32-bit instructions are used is because the compilers might be using Thumb-2?

Attached: 1454443526069.jpg (421x421, 57K)

Cancerous code. Kys

Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.

i don't know what a stack machine is.

Times ten
Plus single digit number
This is basic math you retard

that doesnt work for decimals.

Why do web devs make more money than most other programmers?

oh i see now.

because web development is the only kind of development that matters nowadays

perhaps your cross-compiler is making generic code that is not tuned similarly to the rPi compiler.

try this command on your rpi

gcc -march=native -dM -E - < /dev/null


and ensure that your x-compiler isn't adding or removing certain flags such as thumb stuff or some tuning in relation to certain 64-bit operations being slower or something

You're ? For a calculator maybe store the floating point number in 2 integers and convert that when doing arithmetic.

Devide the added number by 10

"Break" exits the current "for" or "while" cycle. It also gets to the next "switch-case" condition. "Continue" gets to the next iteration of the "for" cycle or re-evaluates the "while" cycle.
"Return" exits the current function. If you are currently within a cycle which is in turn inside a function, it exits both the cycle and the function.

unfortunately this

*Also "return" without a value in a function/method that returns no value (void) also exits the function.
Tell all these /dpt/ faggots to eat shit and go watch Derek Banas playlists on youtube. Also google and pause as you see fit.

I think I recall that all C code is compiled to Thumb-2 instruction set on ARM. So I think there's no way around this

>This is basic math you retard
>
>>cutegang seething
explain

seems like float actually truncates my decimals.

Attached: Captura de pantalla de 2019-06-02 18-19-59.png (716x579, 53K)

10.0 you mong

but how do I simply push the number to the right, right now it simply adds my floats.

float result = stringToFloat(floatValue.toString() + intValue.toString());

You have much to learn. This might help:
leetcode.com/problems/valid-parentheses/solution/

how do I get how many decimals a number has?

An integer? log 10, floor, add 1

holy shit your calculator program should not be storing and building its numbers in IEEE floating point format
the lazy option is to just build it by appending characters to a string and then calling tofloat or whatever. if you're serious about shit you should use an arbitrary-precision math library so you don't get shitty floating point rounding errors. it'll be much slower than floats but still billions of times faster than the human interface so it doesn't really matter

I'm making a basic calculator for dumb weebs who want some weeb calculator for mobile bro, with an android banner.

as i said
the minimum option is to simply store the inputted values as strings and call your language's string-to-float function at the last moment before calculation
don't try to do bit twiddling shit to add digits to the end of a decimal number because you're just going to run into rounding error after rounding error converting back and forth between base 2 and base 10 so often

>have flash of inspiration
>think of a very elegant way to do Thing
>halfway through implementing it start worrying about edge cases since they seem pretty hard to handle
>finish to core implementation and start testing for the edge cases
>realize the implementation actually handles them all correctly without any need for ugly edge case handling conditionals

I wonder if my brain knew this all along.