/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: lrg.jpg (500x656, 64K)

Other urls found in this thread:

en.wikipedia.org/wiki/Javascript
yt-dl.org/bug
en.wikipedia.org/wiki/Homoiconicity
github.com/tuckerpo/real-time-cv-filters
github.com/WebAssembly/spec/tree/master/interpreter/#s-expression-syntax
en.wikipedia.org/wiki/Mmap
download.plt-scheme.org/doc/4.0.2/html/reference/time.html#(mod-path._scheme/date)
youtube.com/watch?v=Q1cuuepVNoY
twitter.com/NSFWRedditImage

why haskell syntax gotta be whitespace sensitive

Attached: javascript.png (675x477, 275K)

Is JavaScript really functional?

Whitespace is superior to brackets.
There is a small learning curve but once you get used to it it looks much cleaner

Yeah.

nigger

Would programmers get better at writing C with the death penalty hanging over their heads if they let bugs get into production?

Attached: -22.jpg (1280x720, 104K)

no, it has procedure but not function.

No.

>every page is blank

Every language repeats the mistakes of not using s-expressions until it switches to using s-expressions.

Javascript is to FP what Java and C++ are to OOP.

is youtube-dl broken for pornhub? getting error in pic related (yes, I have the latest version)

Attached: err.png (644x53, 4K)

s-expressions are only useful if variadic functions exist, otherwise it's a shitton of parens for no benefit

Why are you asking here? Do you expect a random Jow Forums user to run off to Github and report the issue for you?

You might want to use the words "coder" and "programmer" to differentiate this kind of people.
Yeah, but it's not strictly functional.
en.wikipedia.org/wiki/Javascript
No. Just used it. Are you in the last version?

I never realized how much programmers take heap allocation for granted until I started doing embedded work. Even something as trivial as a std::string is a no-go in hard real-time systems. Fuck the heap.

>(setf (car cars) car)

Attached: 1492635783693.jpg (1000x1000, 260K)

Fuck, I posted it in the wrong thread, wanted to post it in /sqt/. I was hoping if someone else could check to see if it wasnt just me. Sorry /dpt/.

>fapping to 3D

Attached: 1521375558070.jpg (247x404, 26K)

NEAT implementation for snake

...in js

Attached: Capturasnake.png (534x436, 10K)

oh okay if you're doing that kind of stuff you might get more use of calculus. Also check out Linear Algebra.

version is 2018.09.10, and anyway I ran youtube-dl -U just before trying to download
heres the full log anyway, but like I said in I didnt want to post it here.

Traceback (most recent call last):
File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp0icdbhzn\build\youtube_dl\YoutubeDL.py", line 792, in extract_info
File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp0icdbhzn\build\youtube_dl\extractor\common.py", line 502, in extract
File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp0icdbhzn\build\youtube_dl\extractor\pornhub.py", line 164, in _real_extract
File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmp0icdbhzn\build\youtube_dl\extractor\common.py", line 972, in _search_regex
youtube_dl.utils.RegexNotFoundError: Unable to extract title; please report this issue on yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

en.wikipedia.org/wiki/Homoiconicity

Does somebody know about library/framework similar to Selenium which would be able to run independently more that 100 active browsers and wouldn't eat more than +-32gb of ram?

Attached: maxresdefault.jpg (1920x1079, 175K)

>Actually they're just bright enough to know how to use it.
What does that mean? That their code isn't awful?
Complexity precedes simplicity, and C++ is one of the most complex languages I know.
Sure, if you're very smart you might be able to do cool stuff with it. But why when you can just spend the same brain power on a language that's actually good?

>Programming in and of itself isn't difficult. The interesting problems you solve with it are where the challenge is from.
This feels like talking about definitions.

I'm not really sure, I know CS students here, do integrals 24/7 during the first year.

And it's only my imagination of what a person who calls themselves fluent in programming should be capable of doing. It might be an overkill I guess?

do you need the browser to physically open? can you give a description of what you're trying to do

I have done a shitload if integrals at uni and I can't for the life of me connect it to programming.
If you're doing games it might very well be different, I don't know, but honestly, schools overestimate Calculus and underestimate Linear Algebra.

Point taken, Lisp Hitler, but even having written a number of Lisp dialects and made great use of macros, I have to contend that macros are a pain in the ass to write without some kind of template system, and you honestly don't need S-exprs for that as long as the language supports it somehow
Different user by the way

Real analysis is more useful. Solving limits, derivatives and integrals is menial, but proving theorems is hard and really exercises your abstraction and logic skills.

What the fuck is the point of conversion constructor? Wouldn't all these implicit conversion cause even more subtle mistakes?

You don't need homoiconicity for strong metaprogramming, all you need is a simple AST.

Homoiconicity is overrated.

Yes they would.

You should make your constructors explicit in most cases.

You need three chevrons for it to create a link

The languages with the best tooling are unironically Lisps, Idris, and Agda.

No I'm running browsers headlessly. I need to scroll through thousand of wed pages and if I find specific link I need click on It and perform some action. I'm currently using selenium with PhantomJS and the problem is that It is painfully slow and it take shit-ton of memory.

Attached: 1508166375350.png (998x936, 538K)

What tooling do you use for Idris?

Should I learn Emacs or is it just a meme?

Emacs and the "lab assistant" features of the compiler.

Yes.

Daily shilling

github.com/tuckerpo/real-time-cv-filters

Come do computer vision stuff

but s-expression is the simplest ast, this is why it has been chose by W3C as the intermediate representation for webassembly.

github.com/WebAssembly/spec/tree/master/interpreter/#s-expression-syntax

I'm saying it's overkill. There are plenty of other choices of AST which are easily manipulable without having the costs of sexprs.

You'll have to pry paredit from my cold, dead hands.

I'm confused.
Does C not have the "short" type variable? I was using it even though the text editor was not recognizing it, and the code was still working somehow, but apparently I'm supposed to use unsigned char to store a 0~255 integer value.
Is this correct?

I believe a short is a 2-byte value regardless, so 0-255 would be a byte, char.

what cost are you talking about? s-expression is just a visual representation of a tree data structure (nested lists) as text which is perfect for representing an abstract syntax tree

short in C is at least 16 bits wide.

uint8_t

>Does C not have the "short" type variable?
I fucked up, meant "byte" type.

It's a nuisance to write and an eyesore. Basic shit like application of a curried function is obscured under a mountain of parens.

...

unsigned char is the byte type. In C, a char is defined to be 1 byte.

honestly C should have just used stdint for the built-in types instead of type modifiers

>Even something as trivial as a std::string is a no-go in hard real-time systems

explain

Attached: m.jpg (633x640, 47K)

What web pages? You can do most web scraping/automation by simply sending the needed requests manually, you don’t need a whole browser engine running unless it’s some atrocious javascript heavy website

std::string might call malloc (or some other allocator function)
it's super difficult to put an upper bound on the time taken by malloc
that disqualifies it for use in a hard real time system

std::string contains a pointer to the char array of dynamic size located on the heap. Embedded system programmers want to avoid heap allocation due to fragmentation issues or because their system may not have a heap at all to begin with.

Heap allocation is generally a no-no for hard real-time code

>javascript
>functional
ERROR
DOES NOT COMPUTE
DOES NOT COMPUTE

Today /dpt/ was good

Yep! We're not *all* larping here! Some of us actually have degrees and jobs.

If(a > b)
func(...)
else func(...)

i literally did this to evade branching, but this seems haram as fuck. But damn the speed up.

In what language? That's a pretty trivial compiler level optimization. Not trying to knock you, but it would probably be done anyway by a majority of modern build tools

why is the comparison even needed in this case?

You're confusing "functional" and "functioning", user.

just use your own mallloc or overload the new operator
a guy who develops hrt stuff for the nasa testified on hackernews that hrt was nothing else than a buzzword and base linux is fast enough for 99% of the stuff requiring hrt. linux implement a heap through the mmap system call.

do we have to overload operators for every different class in c++?

What is a python replacement?
Idk it was recommended to learn it since its useful but it seems like a reddit language. What is Jow Forumss python?

GNU/Linux*

only if you want to

no, i am talking about the kernel.

PowerShell

it's C++
the func has a lot of code duplication with a few small changes depending on an if statement, thought i would just template them. It's a stupid little thing but seems to work.

btw ops the lower func in the else clause should be 0 ofc

>why is the comparison even needed in this case?

Because the compiler doesn't like throwing local variables as templates for some reason (im just a beginner). So
int c = a > b
func(...)


Semantically the same but the compiler doesnt like it. Maybe i should use an overloaded function or something. Anything to evade branch prediction.

malloc() is glibc, so GNU

i said nothing about linux and malloc, i referred to mmap which is a system call implemented by the kernel.

en.wikipedia.org/wiki/Mmap

In SICP he writes about build-in method (runtime). Actually i read that its not build-in to Scheme and i should use inexact-milliseconds but it still wont work "unbound variable (inexact milisecond)". What should i use for calculating running time of program?
(define (square x)
(* x x))

(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor n (next test-divisor)))))
(define (next test-divisor)
(cond
((= test-divisor 2) 3)
(else (+ test-divisor 2))))

(define (divides? a b)
(= (remainder b a) 0))


(define (smallest-divisor n)
(find-divisor n 2))

(define (prime? n)
(= n (smallest-divisor n)))

(define (timed-prime-test n)
(newline)
(display n)
(start-prime-test n (current-inexact-milliseconds)))

(define (start-prime-test n start-time)
(cond ((prime? n)
(report-prime (- (current-inexact-milliseconds) start-time)))))


(define (report-prime elapsed-time)
(display "***")
(display elapsed-time)
)


download.plt-scheme.org/doc/4.0.2/html/reference/time.html#(mod-path._scheme/date)

don't know if this is the best place or not but does anyone have some good resources for C? I have to learn if for college but my prof is kinda useless.

If you have some programming experience already, K&R will teach you most of what you need to know.

Time measuring isn't a standard feature in Scheme -- or, rather, it wasn't until R7RS (which still isn't widely supported). If you're using PLT Scheme, you can just wrap (time ...) around call to your function. In your case, you might just do (time (prime? n)).

That's pretty interesting, so what does that imply? Writing your hrt code inside kernel land, or what?

Additionally, could you link to the hackerrank testimony? Interested in reading it but I can't find it myself.

I dont have any experience but I do have that book

I rewrote this in haskell
sort :: (a -> a -> Bool) -> [a] -> [a]
sort _ [] = []
sort _ (x : []) = [x]
sort cmp (x : y : xs) = let accumulate_fn = \x (acc_max : acc_rest) -> if cmp x acc_max then x : acc_max : acc_rest else acc_max : x : acc_rest
in case (foldr accumulate_fn [x] $ y : xs) of
max : rest -> max : (sort cmp rest)
I'm not very good at this how do I make it cleaner

CV has been an interest of mine for a while, what's your motivation for learning it?

I took a grad course and ended up getting an A in it, just found it really intuitive and interesting. Lots of linear algebra applications and it's a growing/bleeding edge field, as much as I hate that term.

>it's another episode of chasing down the .dlls that the .dlls you just drag & dropped depend on just to run this .exe you compiled episode
i hope whoever invented shared linking gets raped

-- in lens terms this would be a prism
onTail :: ([a] -> [a]) -> [a] -> [a]
onTail _ [] = []
onTail f (x : xs) = x : f xs

sort :: (a -> a -> Bool) -> [a] -> [a]
sort _ [] = []
sort _ [x] = [x]
sort cmp (x : y : xs) =
let accumulate_fn x (acMax : acs)
| x `cmp` acMax = x : acMax : acs
| otherwise = acMax : x : acs
in sort cmp `onTail` foldr accumulate_fn [x] (y : xs)

or a setter, actually, not a prism.

>PLT Scheme
i use MIT scheme interpreter

another change could be to remove the first two cases to sort, and add a final case
sort _ xs = xs

>I just want to be able to code stuff without googling too much
That will never happen.

>Calculus isn't too useful
Calculus is incredibly useful if your intent is to be able to understand the asymptotic complexities of an algorithm.
>making a moving object, animating [...]
you want Linear Algebra.
>generating a hill with a mathematical function
Depends on how you want to go about it. You're just sampling the function for a hill of some resolution, but it could be very simple or very hard depending on whether you want this hill to be 2D or 3D.

I suggest taking a look at the new DirectX Raytracing API and rendering that hill.
Use a combination of colors to represent distance from the camera, elevation, and such things.
It could be very interesting. youtube.com/watch?v=Q1cuuepVNoY

Calculus is not really that useful for complexity. Most of the time you just count how many loops you have nested.

Is there a RE for two strings, less than a certain number of lines apart?

Really new to this, how do i post code?

Doesn't really sound like a regex problem unless im misunderstanding

I want a pattern that matches any section of text less than n lines that contains two specific strings (in both orders).

It may be simpler and easier to understand to just parse the string with some if statements.
'u r a f g t \n \n u r a f g t'

(.*\n){n,m} would do the trick for the line range counting.

In Scheme, you'd be better off using an insert sort versus a selection sort.

(define (insert-via pred? x sorted-l)
(cond
((null? sorted-l) (list x))
((pred? x (car sorted-l)) (cons x sorted-l))
(else (cons (car sorted-l)
(insert-via pred? x (cdr sorted-l))))))

(define (anonsort pred? l)
(cond
((null? l) l)
(else (insert-via pred? (car l) (anonsort pred? (cdr l))))))

What does /dpt/ think of forth?