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

File: Homura_DPT_rust.jpg (128KB, 563x712px) Image search: [Google]
Homura_DPT_rust.jpg
128KB, 563x712px
Old thread: >>60832529

What are you working on, /g/?
>>
File: 1493919558167.jpg (40KB, 576x472px) Image search: [Google]
1493919558167.jpg
40KB, 576x472px
>>60837216
OpenGL Game/Game Engine in C
>>
File: inference meme.png (339KB, 404x567px) Image search: [Google]
inference meme.png
339KB, 404x567px
>>
File: 1496815852634.jpg (484KB, 1800x1196px) Image search: [Google]
1496815852634.jpg
484KB, 1800x1196px
How do I integrate a wxwidgets GUI into my c program?
Wxwidgets is a c++ library
>>
>>60837258
This is actually true.
t. idris-fag
>>
File: parametric.png (616KB, 680x954px) Image search: [Google]
parametric.png
616KB, 680x954px
>>60837298
>>
>>60837262
http://wxc.sourceforge.net/
>>
>>60837314
`template` and `void *` should be switched tho.
>>
>>60837323
No.
>>
File: 1495910470505.jpg (98KB, 1299x801px) Image search: [Google]
1495910470505.jpg
98KB, 1299x801px
>girls can't progr-
>>
File: Idris_ava.png (9KB, 200x200px) Image search: [Google]
Idris_ava.png
9KB, 200x200px
I'm writing content for a basic introduction to Idris series on youtube

https://www.youtube.com/channel/UCcrSMnEYhIPX_p127jI23qw

Also just sitting in a coffee and doing some Python scripting for fun. Here's something for replacing strings:

import os

DEFAULT_SPEC = dict(dir_path=os.path.dirname(__file__)
, extension='.py'
, replace=True
, keys=[("in001", "out001")
, ("in002", "out002")
]
)

# Test zone:
# in001
# in002

def replace_content(spec=DEFAULT_SPEC):
"""
In spec['dir_path'] and its sub-folders,
in files with extension spec['extension'],
replace strings according to the list spec['keys']
If spec['replace']==False, merely search and don't replace
"""
for root, dirs, files in os.walk(spec['dir_path']):
print("\n..." + root[-25:])
os.chdir(root)
for filename in files:
if filename.endswith(spec['extension']):
for old, new in spec['keys']:
with open(filename) as infile:
content = infile.read()
if old in content:
print(4*" " + "* " + filename)
msg = 8*" " + '"{old}"'
if spec['replace']:
with open(filename, 'w') as outfile:
outfile.write(content.replace(old, new))
msg = msg + ' ---> "{new}"'
print(msg.format(**locals()))


if __name__ == "__main__":
replace_content()


I'm thinking if I should write a minimal qt guy with input/browse fields and a button that can run scripts like that. Any takers?

PS: I'm running Python 2.7 on this laptop, did I miss anything that doesn't convert to Python 3 in the above script.
>>
>>60837345
What the fuck is that thing??
>>
>>60837345
So the men kicked all the women out of tech now the men want to BE the women. Fucking $currentYear
>>
Is the core of Haskell total?

Studying monads currently and was wondering if I got it right, that is, that the purpose of monads is to provide an extra layer for partial functions, so that the core of the language may be total and extra static analysis may be performed?

Tried Googling but couldn't find anything, please respond
>>
>>60837365
I wish I were a cute loli with cute nails
>>
>>60837372
>>
>>60837398
Dress up like a cute loli then cut off your penis so you bleed out and die. You're 110% guaranteed to be reincarnated as a cute girl in the anime of your choice.
>>
>>60837413
>>
>>60837422
heh, /dpt/ shit doesn't need multiple modules
>>
>>60837372
monads are what they are

a monad enforces linear ordering of dynamic effects - you can think of this either in terms of >>= or join

they allow you to combine data and effects so that you can have monadic or effectful values, e.g. IO Int or (Writer Text) Double

the dynamic bit means that you can have a computation that takes one effect, and chooses another effect depending on that result, while static effects (applicatives) cannot depend on the results
>>
>>60837438
Thats my point.
>>
>>60837453
F5 builds and runs your file. If you need inputs you can define them too.

It does lack an integrated terminal like VS Code
>>
do the whites and chinese make computers hard to use on purpose so people in the community can't get good jobs?
>>
>>60837465
However, Coedit has better completion/suggestion than that of VScode
>>
File: coffee.png (1KB, 131x121px) Image search: [Google]
coffee.png
1KB, 131x121px
>>60837354
>sitting in a coffee
>>
>>60837441
inb4 gatekeeper >reddit spacing
>>
>>60837441
>reddit spacing
>>>/r/ibbit
I don't want your reddit stink nearby.
>>
>>60837484
t. gatekeeper
>>
>>60837465
ctrl-alt-n then my compile and run bind is faster that making a new file and running dub/rdmd on it
>>60837471
VS code has trash defaults, but has much better customization overall.
>>
>>60837441
>Reddit spacing
>Overall lack of capitalisation and punctuation
Fuck off.
>>
>>60837410
>>60837441
Thanks guys, I think I get it now
>>
File: drowning in coffee.jpg (149KB, 1080x720px) Image search: [Google]
drowning in coffee.jpg
149KB, 1080x720px
>>60837474
oops, lol, thanks for the 3h in paint

>>60837506
Idris (>>60837354) has a totality checker btw., it's one of the features the creator heavily emphasizes

https://en.wikipedia.org/wiki/Total_functional_programming
>>
Do a fizzbuzz in functional programming, using no loops and if/else
>>
>>60837561
fizzBuzz x = 
case (x `mod` 3, x `mod` 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
(_, _) -> show x

main = mapM_ (putStrLn . fizzBuzz) [1..100]
>>
>>60837583
>pattern matching
isn't that basically a switch?
Can't you just use map, filter etc?
>>
Any R users here?
Can I do some type of try/catch or try/except mechanisms in R?
I want to try and do something like this:
try (my_function())
if successful, continue
if not successful, do something else

Sorry for the shitty pseudocode, I'm obviously not big on these things.
>>
>>60837594
Switch is a limited pattern match or WOULD BE if you understood that switch is designed to compile to jumps and that not all generalisations of that can be.
Similarly for If.

This is perfectly functional. Maybe I should be asking you why you would use a switch or an if/else rather than label and goto?
>>
File: fizzbuzz.png (240KB, 696x1854px) Image search: [Google]
fizzbuzz.png
240KB, 696x1854px
>>60837561
Reposting my masterpiece.
>>
>>60837561
I'm just exploring the functional paradigm of D today but I don't know how to filter 3 types of ranges

For example I can filter out the 15's products. Now I need to acquire the rest of the numbers and the range is 3 and 5's products. Any tips?
import std.stdio;

void main()
{
import std.algorithm, std.range, std.format;
each!writeln(iota(1,101).filter!(a => a%15==0).map!(x => format("Fizzbuzz")));
}
>>
>>60837658
>partial main
>>
>>60837658
enterprise quality code m'lord.
>>
>>60837672
range of*
>>
File: ;D.png (57KB, 800x334px) Image search: [Google]
;D.png
57KB, 800x334px
>>60837672
>>
>>60837258
>meme
>>>/v/
>>
>>60837673
getArgs isn't total, my friend.
>>60837674
It's not a filler tho, this is a formal proof my implementation is correct.
>>
>>60837695
>predSwitch
Based Andrei

Thank you very much, anon
>>
>>60837372
>Is the core of Haskell total?
No.
>>
>>60837695
stop using int main you mongoloid.
>>
File: 1495639904160.png (664KB, 1300x1500px) Image search: [Google]
1495639904160.png
664KB, 1300x1500px
>>60837699
>getArgs isn't total
Which means it shouldn't be used.
>>
>https://dlang.org/phobos/std_algorithm_comparison.html#.predSwitch
Fuck this shit is autistic
>>
>>60837726
this. use nat main.
>>
>>60837743
>passing code in strings
What is this, tcl?
>>
>>60837298
>idris-fag
>is-fag
>>
>>60837783
mixins are love
>>
>>60837791
No, they're fucking stupid.
>>
>>60837785
Who's Idr?
>>
>>60837743
>let's emulate pattern matching with shitty hacks
Wew, Andrei.
>>
>>60837798
youre fucking stupid, theres nothing wrong with them.
>>
>>60837806
I see nothing wrong with this
int factorial(int n)
{
return n.predSwitch!"a <= b"(
-1, {throw new Exception("Can not calculate n! for n < 0");}(),
0, 1, // 0! = 1
n * factorial(n - 1) // n! = n * (n - 1)! for n >= 0
);
}
>>
>>60837623
met a business grad at a party last night learning R
>>
>>60837818
That's hideous
>>
>>60837818
>>/trash/
>>
>>60837262
you make your c program a dynamic lib and provide a wrapper header

then you write gui program and call your shit from there
>>
File: vomit.jpg (90KB, 650x650px) Image search: [Google]
vomit.jpg
90KB, 650x650px
>>60837818
>Code inside strings
>Exceptions
>No syntactic relation between predicates and their values; they're just separated as function arguments
>Non-tail call recursion
>>
>>60837818
It's a useless hack and it's impossible to read, m8, even when it's heavy commented, mostly because verything is comma-separated and code is being passed as a string. Compare to equivalent
fn fact(n : isize) -> Result<isize, ()> {
match n {
_ if n < 0 => Err(()),
0 | 1 => Ok(1),
n => Ok(n * fact(n-1)?),
}
}

or even
fn ufact(n : usize) -> usize {
match n {
0 | 1 => 1,
n => n * ufact(n-1),
}
}

since you don't actually need error handling here.
>>
>>60837818
>factorial
>int
What did she mean by this?
>>
>>60837466
We've been found out. Burn the evidence.
>>
>>60837911
It's a factorial function
>>60837903
These are valid points
>>60837904
Well comments were there to explain the operations
>>
>>60837948
Factorial isn't defined on all integers.
>>
>>60837959
this is why there was an exception
>>
>>60837974
>this is your brain on D
>>
>>60837974
Why not just use a more appropriate type instead of doing retarded things?
>>
>>60837986
you mean uint? yeah that's a better way I suppose, if you pass negative integer the program will still throw exception
>>
Are they called functions or methods? Are the names interchangeable?
>>
>>60838040
>Are the names interchangeable?
No in most cases. Structs and classes have methods, functions are more generalized
>>
>>60837640
>Switch is a limited pattern match or WOULD BE if you understood that switch is designed to compile to jumps
wrong
>>
Reminder that dependent types are a meme.
https://github.com/davidfstr/idris-insertion-sort/blob/master/InsertionSort.idr
>>
>>60838342
t. hasklet
>>
>>60838342
>(x:e) -> (y:e) -> Type
ffs
>>
>>60837216
Finishing up on my Business Rule Generator for a school project.

Fuck Oracle's APEX for being what it is (especially its lack of documentation) and fuck Salesforce's Apex for fucking up my searches when I want info about Oracle's APEX

The Java backend is OK though.

I'm thinking of rewriting the backend in Kotlin this summer as a side-project. Any thoughts on Kotlin?
>>
>>60837354
Seems ok, though the stuff that has been added on the youtube channel so far feels really trivial and mostly covers the really basic syntax. I might check up on it later though, I am interested in learning a dependently typed language at some point.
>>
Im using VS with c forms and have a dictionary list of custom class objects thats saved on one form and i need them loaded on another. Trying to use application settings class to do this. No problem with generic data types, just that dictionary list.

I tried serializing them with JSON, but the objects need to be fed right into a combobox and aint working
>>
File: Capture1.png (161KB, 1274x1371px) Image search: [Google]
Capture1.png
161KB, 1274x1371px
>>60838518
The login screen
>>
File: Capture2.png (177KB, 1873x1856px) Image search: [Google]
Capture2.png
177KB, 1873x1856px
>>60838518
Creating a business rule
>>
>>60838565
also, wat do /g/?
>>
Any Microsoft fags here? I am trying to build a Plugin for Visual Studio 2015 that "links" the Editor Classifier with a Command Window and I have no idea what I'm doing
>>
>>60838342
>meme
>>>/v/
>>
>>60838745
More spicy memes for you.
https://gist.github.com/timjb/9043255
>>
>>60838779
>memes
>>>/v/
>>
>>60838802
>>60838745
>le >meme >>>/v/ meme
>>>/v/
>>
>>60838802
More m3m3s for you, my dear friend.
https://rosettacode.org/wiki/Proof#Idris
>>
>>60837818
>doesnt calculate for the entire domain of x!
>>
>>60838855
>m3m3s
>>>/v/
>>
anyone has a good msbuild cheat sheet?
>>
>>60838879
> >>>
>>>/trash/
>>
>>60838879
I will disappear if you keep bullying me!
Be careful.
>>
File: meme.png (114KB, 693x981px) Image search: [Google]
meme.png
114KB, 693x981px
>/g/ in $currentYear
>this place used to contain an actual content
>>
>>60838962
>>60838904 really completes the picture, desu
>>
>>60838962
That's why we have to bring back /prog/.
>>
void(*(*(*)(void))(void))(void))
>>
>>60838342
Compare this with a formally verified insertion sort in ATS: https://www.cs.bu.edu/~hwxi/academic/papers/arsec13.pdf

Formal verification isn't a meme. Idris is.
>>
>>60839011
>meme
Use >>>/v/
>>
Here is a quick challenge. Write a function that prints even, odd or prime under 100.
For example the answer would be..
Prime
Even
Prime
Even
Prime
Even
Prime
Even
Odd
Even
.
.
.

Restrictions: You can't use any for/foreach/while/if/switch/pattern matching and ternary operations.
>>
>>60838962
please don't bully newfriends
>>
>>60839030
>no pattern matching
what do you want us to use then, or is that the """"joke""""?
>>
>>60838541
Of course, it's basic. I start from zero knowledge. If you already know Haskell and thus the basic syntax, drop by in a month.
>>
>>60839030
Why the restriction? Does your wee wee get hard when you see a lazy list?
>>
>>60839022
I'm sure /v/ will be very interested by the use of Martin-Löf type systems to write formally verified sorting algorithms in a low-level non-GCed language.
>>
>>60839030
Neither 0 nor 1 are prime
>>
>>60839060
What other integers can fully divide 1 with 0 remainder?
>>
>>60839047
pattern matching is for plebs
>>
Instagram sluts downloader

import sys, datetime, urllib2, json, os, argparse, pprint

uname = "olivefirthy"
path = "" + uname
if os.path.exists(uname):
print "Folder exists, moving on"
else:
os.makedirs(uname)

instahoeURL = "http://instagram.com/" + uname + "/media"


def hoeitup(jsonItemList):
for item in jsonItemList:
hoERL = item['images']['standard_resolution']['url']
test = item['created_time']
saveThisShit = path + "/" + hoERL.split('/')[-1]
x = datetime.datetime.fromtimestamp(
int(test)).strftime('%Y-%m-%d %H-%M-%S')
newname = uname + "\\" + x + ".jpg"
file = open(saveThisShit, 'wb')
file.write(urllib2.urlopen(hoERL).read(),)
file.close()
try:
os.rename(saveThisShit, newname)
print "Downloaded: " + x + ".jpg"
except WindowsError:
os.remove(saveThisShit)
print "Duplicate: " + x + ".jpg"

round = 0
while round != -1:
if round == 0:
URL = instahoeURL
round += 1
else:
URL = instahoeURL + "?max_id=" + jsonData['items'][-1]['id']

rawContent = urllib2.urlopen(URL).read()
jsonData = json.loads(rawContent)
hoeitup(jsonData['items'])

if jsonData['more_available'] == False:
round = -1
>>
>>60839030
I could do this really easily in smalltalk, by using dynamic dispatch and class hierarchies only.
>>
>>60839078
The definition of a prime number, according to wikipedia, is: "A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.".
>>
>>60839082
t. brainlet who cant into lambdas
>>
>>60837818
Why would you use D-chan like this? It works, but it's so ugly.

Meanwhile a simple solution is so much more obvious
int factorial(int n) {
int m = 1;
while (n > 0) m *= n--;
return m;
}

(this is also valid C-senpai)
>>
>>60839078
A prime has 2 factors
>>
>>60839099
That valid code in a lot of C-like languages.
>>
>>60839030
https://pastebin.com/43dHN9EA
Untested
>>
>>60839078
1 is not prime. 1 is a unit instead.
>>
>>60839011
I did not claim that formal verification was a meme.
Other solutions that choose different trade-offs are way nicer to use than dependent types while more limited, though I don't think that those will be viable in practice any time soon. The case is obviously different for academia.
For a concept to be useful (stop being a meme) people need to be able to understand formal verification and its limitations intuitively without too much effort.
>>
>>60839114
I think I fucked part of it up
Anyway you get the idea
>>
>>60839099
we /functional/ now
>>
>dependent types are bad because my favorite language doesn't have them
love this m.
>>
>>60839059
They will be interested in the word I quoted. You should join them if you plan on using it.
>>
>>60839120
>meme
>"""meme""" as a negative property
Use >>>/v/

>>60839132
>m
Try using >>>/v/
>>
>>60839040
I will. They need to lurk more before shit-shitposting.
It's not even shitposting at this point. It's just shitty shitposting that clutters anything else, is not funny or witty in any way, and is just monkey-repeating one phrase over and over.
>>
>>60839120
>For a concept to be useful people need to be able to understand...
Opinion discarded. You are clearly retarded.
>>
>>60837234
Same thing here. Writing UI stuff stuff at the moment.
>>
How fucking hard can it be to just create a plugin in Visual Studio 2015?
I simply want to create a "credits tool", you putyour name as a comment over the code you written and it gets displayed on a toolwindow.

For that, I am using a classifier and a Command window, but i cannot get the data from the classifier to save my goddam life.

Is there any better way to do this or should I just kill myself right now?
>>
File: 1474949204825.gif (337KB, 640x360px) Image search: [Google]
1474949204825.gif
337KB, 640x360px
>>60839169
VERY NOT NICE
>>
>>60839146
>assuming m is short for meme
Youre slipping gate-keeper, clearly meant model of thinking .
>>
>>60839188
>meme
Try >>>/v/
>>
>>60839195
but you say it all the time, think i need to be the gate-keeper for our gate-keeper.
>>
>>60839195
> >>>
Go to >>>/trash/ where you belong
>>
Why do some languages lack TCO?
>>
>>60839216
>languages
>>
>>60839174
I'm talking specifically about formal verification of software in practical day-to-day development.
As I mentioned, it's a different case for academia.
I just don't see this gaining traction outside of academia if it just seems like a giant complex abstract ivory tower circle jerk to your average dev with cs education.
>>
>>60839130
yeah but even hardcore FP fetishists will use an imperative solution in the rare case that it's much more elegant than the corresponding functional solution!

right? :'(
>>
>>60839224
The usefulness of a concept is an inherent property independent of people understanding it.
>>
>>60839243
Yea but yall lissn if no one understand it hoo all it useful to
>>
>>60839243
you've seem to forgotten what the word useful means
>>
>>60839221
Compilers.
For example, Java doesn't have TCO. Why?
>>
File: 1496878827287.jpg (68KB, 720x960px) Image search: [Google]
1496878827287.jpg
68KB, 720x960px
>>60839259
fuck racist hicks
>>
>Haskell is the only FP language that will ever become moderately popular outside of academia
Where do you mongs come from, fuck off.
>>
>>60839270
>Compilers
>>
>>60839278
Who are you quoting?
>>
>>60839261
You specifically said "concept". How does more people knowing about something change the inherent nature of that thing?
>>
>>60839241
Well it's not like D supports FP in a whole sense like Idris does, you still can use stuff like these and stay comfy:

each, map, fold, byLine, zip, group, joiner, splitter, iota, repeat, stride and predSwitch.
>>
>>60839303
you chose a pretty dumb hill to die on trying to say things are useful regardless of how usable they are
>>
>>60839278
ocaml is pretty popular, not main stream but it has alive community.
Common lisp, racket, chicken scheme and clojure(not lisp) have decent sized communities too.
>>
>>60839216
Because it fucks up stack unwinding and RAII. For example, in C++
int counter = 0;

class DumbClass {
public:
DumbClass() { std::cout << counter++ << std::endl; };
~DumbClass() { std::count << counter-- << std::endl; };
}

unsigned f(unsigned n) {
DumbClass dumbObject;
return n <=1 ? 1 : f(n-1);
}

factorial(5);

you want to get 0, 1, 2, 3, 4, 3, 2, 1, and not 0, 1(, 0, 1)* you get if you turn the function into a loop. They don't have destructors in Lisp/Haskell, so it's easy to implement TCO there.
>>
>>60839303
"people are able to understand some thing" is not equivalent to "many people understand some thing".
>>
>>60839272
Agree, nigs have funny accents I like to make fun of -- and I'll call them that because it sounds funny, violent history of the word be damned -- but I'm very much not cool with anyone who hates nigs they don't even know because of their experiences with other nigs and thinks all nigs are an inferior species and should be rounded up and shot. I'm not the thought police, I'm just a person with opinions, and it's just as much my right to hate people like that as it is their right to hate the people I hate them for hating.
>>
>>60839321
Exceptions and RAII were fucking mistakes.
>>
>>60839321
OK, but what about languages that don't have RAII?
>>
>>60839314
How can a concept be "usable"?
>>60839342
People's current understanding or even willingness to understand something doesn't somehow change the nature of that thing.
>>
>>60839309
What is a ``FP" though?
>>
File: ezgif-2-b809cfb7da.gif (172KB, 650x650px) Image search: [Google]
ezgif-2-b809cfb7da.gif
172KB, 650x650px
>>60839393
>o look it are le stanky whomst art thou quoting maymay part deux
>>
>>60839393
if your language supports lambdas then it's literally Lisp in <x's syntax> just like javascript.
And everybody know's lisps has something to do with FP.
>>
>>60839412
>le
>maymay
Your kind is not welcome here.
>>>/v/
>>
>>60839365
Actually, TCO just not worth it.
>>60839368
Most languages have some kind of RAII, like `using` in C#, `with` in python, etc. Then again, TCO just isn't that useful when you have a full-fledged imperative language and can just write loops.
>>
File: g2tSfA.gif (172KB, 650x650px) Image search: [Google]
g2tSfA.gif
172KB, 650x650px
>>60839424
>o look it are le stanky gatekeeper maymay part a billion
>>
>>60839420
>if your language supports lambdas then it's literally Lisp
So every language is Turing-complete?
>And everybody know's lisps has something to do with FP.
Who is this ``everybody"? And you haven't answered what a ``FP" is.
>>
>>60837234
>>60839185
Tell me about what are u using?
>glfw
>glut
>sdl
>>
File: 1492229189880.jpg (77KB, 600x600px) Image search: [Google]
1492229189880.jpg
77KB, 600x600px
>>60839352
>Agree, nigs have funny accents I like to make fun of -- and I'll call them that because it sounds funny, violent history of the word be damned -- but I'm very much not cool with anyone who hates nigs they don't even know because of their experiences with other nigs and thinks all nigs are an inferior species and should be rounded up and shot. I'm not the thought police, I'm just a person with opinions, and it's just as much my right to hate people like that as it is their right to hate the people I hate them for hating.
>>
File: prog.jpg (105KB, 473x496px) Image search: [Google]
prog.jpg
105KB, 473x496px
>>60839446
>what a ``FP" is
Abstract bullshit that you will never understand without reading SICP!
>>
>>60837583
>M_
ABSOLUTELY
DISGUSTING
>>
>>60839375
>How can a concept be "usable"?
by not pretending that hardware doesn't exist, that your computer is a math machine, or that formal verification is useful on a non-trivial program
>>
>>60839461
Tattoos are self mutilation.
>>
>>60839458
I'm using SDL2 for inputs and window creation. How about you?
>>
>>60839393
Programming without explicit loops and if/else
>>
>>60839420
So what you're saying is, C is lisp?
It supports lambdas, they just have to be strongly typed and declared at top level with a name.
Declaring them as static makes your intention clearer, since top level static symbols aren't exported in the object code.
#include "my_higher_order_function.h"
static void my_lambda(void* params, void* result_buffer) {
/* stanky lambda code here */
}
int main() {
my_higher_order_function(my_lambda);
}

It's really no different from achieving a lambda by defining an ad-hoc locally scoped function. The function's scope is the whole file instead of the piece of code, but it's still basically the same thing, because C projects usually involve a lot of files.
>>
>>60839461
Explain relevance pls.
>>
>>60839532
All languages are Lisps in disguise.
>>
>>60839545
it's you
>>
>>60839555
So all languages are Turing-complete?
>>
I need to do something in Lua as an assignment. I was trying to do some Factorio modding, but got heavily discouraged after I managed to cause a seg fault through my mod (although I fixed it). Now I think that writing some LISP interpreter could be more fun. Is there much of a difference between dialects? I've done some basic exercises in Racket, have no idea about other ones.
>>
>>60839532
>It supports lambdas, they just have to be declared at top level with a name.
What did she mean by this?
>>
>>60839474
What's wrong with it? It indicates that it's the monadic, value ignoring version
>>
>>60839555
All languages wish to be a Lisp.
>>
>>60839569
This is not necessary.
>>
anyone still using C for fun needs put in a home
>>
>>60839596
https://www.youtube.com/user/carolineASMR
Uses C for fun. Fuck you cattle nigger.
>>
>>60839605
>ASMR
>>>/trash/
>>
>>60839592
How is a language which only has empty while loops "a lisp in disguise"?
>>
>>60839605
>>>/r9k/
>>
>>60839498
GLFW and directx12 in windows.
Making same engine for linux/mac and windows.
>>
>>60839623
What is a language?
>>
>>60839393
Programming paradigm where you treat functions as first class values. That is, every function is a value in the same sense 1 is a value. So you can hold functions in variables and have functions that take functions as arguments and/or return functions.
>>
>>60839567
No it's not, I don't have tattoos.
That being said, let's pretend that is indeed me. What exactly would be the point of saying as much? I don't get it.
>>
>>60839626
Oh, does GLFW work with D3D? I do most of my work on Linux so I use OpenGL on all platforms. Doing this project in 2D so only using version 2.0 to allow some compatibility with old devices.
>>
>>60839630
can you explain how {foo} is a lisp in disguise so that people understand what you mean with "lisp in disguise"?
>>
>>60839596
Using C because there's no good alternative.
ATS and Ocaml have really ugly syntax.
Common lisp is really verbose unless you abuse reader macros and it's not really statically typed.
Chapel cannot use libraries compiled with it.
Swift looked decent but I don't think they really care about supporting other platforms than apple's.
So you are really only left with Nim or D if you ignore all the shitty languages that shouldn't even exists.
>>
>>60839656
Why? I am not the person you replied to and I am not obliged to explain how
>>
File: whitehouse.png (294KB, 495x419px) Image search: [Google]
whitehouse.png
294KB, 495x419px
What did I do?
>>
>>60839670
Shitpost
>>
>>60839661
What about Kotlin?
>>
>>60839661
Ruby.
>inb4 "that's one of the aforementioned shitty languages that shouldn't even exist"
No it's not.
>>
>>60839641
So basically every language?
>>
>>60839693
requires jvm.
>>60839701
It's shit, though.
>>
>>60839708
Almost. Not Java.
And more importantly, even if every language, not every paradigm.
>>
>>60839722
>It's shit, though.
puts 'ey fak yoo gobnuh'
>>
>>60839722
>requires jvm.
What's wrong with that? Java sucks, but the JVM is a work of art.
>>
>>60839708
No.
>>
I want to learn Clojure. What is a good guide for it?
>>
>>60839787
I've read this book: http://www.braveclojure.com/. It's decent.
>>
>>60839670
so THIS is the power of .net... woahhh..
>>
>>60839762
name language without first class function
>>
>>60839838
C
>>
>>60839730
>Not Java.
import java.util.concurrent.Callable;
>>
>>60839855
>C
int (*heresAFirstClassFunctionTho)();
>>
>>60839799
Looks interesting. Thanks.
>>
>>60839088
>path = "" + uname
:thinking:
>>
>>60839882
You don't know what first class functions mean, do you? You can't define functions within functions in C unless you use GNU C which is not standard.
>>
File: fhtagn.png (67KB, 387x420px) Image search: [Google]
fhtagn.png
67KB, 387x420px
>>60839580
>implying someone must be female because they said something you think is stupid
>o look it are le stanky sexism maymay
>>
>>60839894
lul
>>
>>60839882
That's a function pointer, not a function. Just like
int* a = array + 5;

isn't an integer.
>>
>>60839905
not him but do you?
"In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures." ~Wikipedia
>>
>>60839941
Later in the article..
>The C family allowed both passing functions as arguments and returning them as results, but avoided any problems by not supporting nested functions. (The gcc compiler allows them as an extension.) As the usefulness of returning functions primarily lies in the ability to return nested functions that have captured non-local variables, instead of top-level functions, these languages are generally not considered to have first-class functions.
>>
>>60839905
>You can't define functions within functions in C unless you use GNU C which is not standard.
You don't know what first class functions mean, do you?
First class functions are functions as data. This means they can be stored in variables, passed as parameters, and returned. It does not necessarily entail that they can be dynamically defined at runtime and close around the scope of their definition. Although this is a desirable feature of a functional language, it is not a part of what defines a first class function.
>>
>>60839972
See >>60839969
>>
>>60839985
>As the usefulness of returning functions primarily lies in the ability to return nested functions that have captured non-local variables, instead of top-level functions, these languages are generally not considered to have first-class functions.
>As the usefulness
>generally not considered
That article isn't saying C doesn't have first class functions, it's saying C isn't *considered in practice* to have first class functions because the capacity in which it ***does indeed have first class functions*** is not useful.
>>
>>60840015
>>60839985
To me it seems like an inconsistency within the article. C fits the definition of first class functions perfectly, but is said to "generally not considered to have a first class functions"
Really makes you think.
>>
>>60840054
An inconsistency perhaps, but not a contradiction. A language can have first class functions and also generally not be considered to have first class functions. That seems perfectly reasonable. In general, the way things are considered to be tends not to be exactly what they actually are, but instead the most useful analogue to that.
>>
>>60840093
>the way things are considered to be tends not to be exactly what they actually are, but instead the most useful analogue to that
Wh--What.
Please.
Stop using C.
It's fucking you up.
>>
>implement advanced signal processing algorithm
>want to make a SIMD version
>benchmark the non-SIMD version
>it's already fast as shit, in the tens of microseconds
i could make a SIMD version pretty easily but it would take a day+ probably and the speedup probably wouldn't even matter :/

should i do it just for practice?
>>
>>60839907
>sexism
>>>/lgbt/
>>
File: eggy.jpg (59KB, 500x526px) Image search: [Google]
eggy.jpg
59KB, 500x526px
>>60840113
> >
> >>>/
>>>/trash/
>>
>>60839907
>>60840123
>le
>sexism
>maymay
>fhtagn.png
>eggy.jpg
Everything in your posts reeks of reddit.
Seriously: piss off. Your kind is not welcome here.
>>
>>60839581
It looks ugly as fuck.
>>
>>60840131
I am in fact welcome here. I know this because I provided the welcome myself.
Also:
>reddit
>>>/trash/
>>
>>60840160
Go be retarded somewhere else, like at reddit.
>>
>>60840054
>>60840093
How would you refer to >>60839920 ? Dereferencing a function pointer in C gives you a function pointer again. You can't get the value of a function.
>>
>>60840093
Well.. no, it is a contradiction.
"Language has FCF if it can pass, and store functions as data [implicitly: it doesn't need to have closure functionality]"
"C is not considered to have FCF because it doesn't have closures"
Those statements are contradictory.
>>
File: ygge.jpg (60KB, 500x526px) Image search: [Google]
ygge.jpg
60KB, 500x526px
>>60840167
>reddit
>>>/trash/
>>
>>60840160
>I know this because I provided the welcome myself
What did she mean by this?
>>
>>60840175
No they aren't.
Key word: considered
>>
>>60840198
Reddit is fucking shit. The users are fucking shit. Keep your filth away from here.
>>
>>60840202
I'm a guy.
What I meant, though, is that I don't need a welcome from anyone else to post here.
>>
>>60840132
Only if you've been doing OOP all your life
>>
>>60840220
Why the fuck are you even here? If you're going to act like a fucking redditor, go to fucking reddit.
>>
i dont get why C has such rabid cultists who regularly deny reality to defend C.
>>
>>60837216
I need to build a 4chan notification app for Android to know when a certain Chinese drawing thread appears. As far as I can find, I can only do this using Firebase? Do I really need to suck Google's dick for push notifications?
>>
>>60840238
If all you have is a hammer
>>
>>60840239
>app for Android
>Do I really need to suck Google's dick
hmm
>>
File: ggegygye.jpg (108KB, 500x1051px) Image search: [Google]
ggegygye.jpg
108KB, 500x1051px
>>60840213
>Reddit
>>>/trash/
Seriously when will this gatekeeper fuck learn that everyone is already so acutely aware his shitty little vote site is garbage that no one even wants to talk about it except for him.
>>
>>60840269
>ggegygye.jpg
>>>/r/ibbit/
>>
>>60840236
>redditor
>reddit
>>60840278
>/r/ibbit

You should stop advertising your website so hard.
>>
>>60840265
I use chink Android no Google Android.
>>
>>60840172
>You can't get the value of a function.
What?
What even is a value of a function?
The whole point of passing functions around is to eventually call them.

>>60840209
Yeah, well everything is "considered" to be something. Every term is just a definition that someone came up with to refer to something. So if C is not considered to have FCF, just like, for example, it is considered to be an imperative language, because it fits that definition, we can just say it is that.
>>
>>60840113
>>60840123
>>60840131
>>60840160
>>60840198
>>60840269
>>60840278
>>60840290
1. I thought this website was 18+. If you're underage please leave now.
2. Your posts are offtopic. They are not in any way related to programming. Please cease.
>>
>>60840269
>>60840290
How does it feel talking to a bot?
>>
>>60840338
feels like someone's asking to be banned
>>
>>60840292
>What even is a value of a function?
Really, if you think about it, the value of a function is a pointer to it.

Because think about arrays. The value of an array is not considered to be an integer long enough to hold the entire array. If there were an integer type that big, passing it around would be very inefficient -- and besides, it wouldn't be desirable. What does an array decay to? A pointer to its first element. So the "value" of an array is not the whole array, but the address of the array.

And what's a function, really? In memory, I mean? A character array. It's not a character array you can actually GET to -- not without violating the standard, anyway -- but it's a character array.

So if the value of an array is its address, and a function is an array, shouldn't the value of a function also be its address? I.e. a function pointer?
>>
>>60840317
>Please cease.
No him tho.
>>
>>60840292
Yeah, and they are dereferenced when you call them to get the actual executable code. The thing is, you don't see the callable functions (except toplevel) anywhere as the programmer. You only pass pointers around and then say "call the function under this pointer". There is only one place where you define actual function's values, that is toplevel function definitions. Note how when defining functions you write "foo bar()" and when passing them as arguments around you write "foo (*bar)()". The difference is very subtle, but the point is in C you never have a variable to which you can directly apply an argument. Think that if somebody somehow modified the original function's code, your variable would still hold the reference to the same place in memory which now holds a different function. So you didn't actually hold the function's value, it's just a reference.
>>
What's the first day at programming job like? I landed a junior programmer job but I don't have any programming projects behind me except from scripts to make my uni homeworks faster or thesis work.
Will I get kick within first month?
>>
>>60840106
please someone give me an excuse to mess around with SIMD
>>
>>60840440
Yeah but you don't "actually hold the function's value" in basically any language. Frankly, depending on the size of the function, there are quite possibly not enough registers in the processor to do so.
Even in lisp, lambdas are function pointers.
>>
>>60840456
Don't. Use existing math library you fool.
>>
>>60840475
>existing math library
ahahahahaha i'm not doing this basic shit

you won't find my shit in any library
>>
>>60840440
Yeah, but what's your point? That's how function pointers/references work in most languages that I know of. C is no different.
>>
File: pls send halp.png (15KB, 1178x16px) Image search: [Google]
pls send halp.png
15KB, 1178x16px
How to search for everylink in a dl, dt tag


 myList =  bs0bj.dl.dd.findAll("a", {"class_":"href"} )


Getting a recursion limit error.
>>
>>60840570
test post also ignore
            *           *    *          
* * * *
** * **
* * * *
* * ** * ** *
* * * * * * *
* *
* * * *
* * * * *
* * * *


tfw no gf
>>
>>60840570
That's not how you make a triforce.
>>
>>60839648
No I am using D3D only for windows and glfw for linux and mac.
>>
>>60840223
So basically what you're saying is that OOP is prettier than FP.
>>
When is C++17 supposed to be coming out, and when will GCC support it fully?
>>
Write a star using your FP skills
*    *    *
* * *
*
* *
* *
>>
>>60840646
That's the joke.
>>
>>60840646
Seriously, stop being cucked by C++
>>
>>60840634
the opposite
>>
>>60840672
immutable str = "a star";
>>
>>60840672
main = putChar '*'
>>
>>60840685
Says the Rust user being cucked by the borrow checker.
What's funnier is that Rust users actually need the borrow checker to make sure they're writing correct code.
>>
>>60838518
>>60838567
>>60838576
>Business Rule Generator
Can you explain more, what it does, how do you use that?
>>
>>60840746
Isn't that a good thing? I wonder why C/C++ enables retards to compile their shit
>>
>>60840746
No non-trivial sepples code is ``correct" for any meaningful definition of the term.
>>
>>60840746
A good programmer will be comfortable with both borrow checker and pointers. It's the ultimate litmus test
>>
>>60840793
>Isn't that a good thing?
No, Rust assumes youre a retard by default.
You can only be """"allowed"""" responsibility with unsafe.
>>
>>60840746
If you use Rust for a month, C++ will feel as easy as python. Take it from me
>>
>>60840817
>He thinks holding a mutable and immutable pointer at the same time is an error.
>>
>>60840827
>Rust assumes youre a retard by default.
Which it should. 9/10 existing C++ codebase is made by utter idiots
>>
Bad programmers think which language you use doesn't matter
>>
>>60840829
what
>>
>>60840746
The borrow checker along with Rust's type system allows for more optimization than is possible in C++
>>
>>60840853
And yet Rust is still slower than C++ in many, many places :^)
>>
>>60840861
Same can be said with Rust and C++ interchanged
>>
>>60840470
But the question is whether they act as if they were values.

>>60840408
If something has value X, it means that under all circumstances it will act as if it was X itself. Defining an array as a pointer is tricky, because that carries no information about the contents of the array. If you know a value of something, you should be able to say what output you will get if you apply it to a function. Overall it's hard to talk about semantics of imperative languages, since everything depends on the program's state.

>>60840538
The point was to show that C doesn't have first-class functions. For that I wanted to say that function's pointer isn't its value. If you want to have first-class functions, you most likely have to hide the implementation from the programmer so he can't tell that he's looking at a pointer. But now you could say that I should just ignore those (*) in function pointers since it is possible for a language to manage that for me and the only point that I could make now is that in C you can actually modify the executable code of a function, thus show it behaves like a reference and not like an actual value. But that point is pretty bad since it would mean that every language that can go deep into memory isn't functional. So I think I'll take that point back and say that C lacks constructing arbitrary functions in arbitrary places (scopes), but that also isn't a good point since it doesn't refer to the definition of first-class values.
>>
>>60840836
Your language should not try to be an all protective bubble environment. Thats why Rust is going to fail, among many other reasons.
>>
>>60840906
>Your language should not try to be an all protective bubble environment
Why? GC'd language provide these safety by default. Rust actually allows those niceties without GC overhead. One of the reasons while Rust will end up killing C++ in the future.
>>
>>60840877
If anything in C++ is fast, its a miracle, when your new and """"""""""""""""modern""""""""""""""""""""""" language loses ~50% of the time to decades of shit on shit, its not an achievement, its just sad.

Not to mention Rusts BC makes the average syntax sometimes even worse than the worst thing in sepples.
>>
>>60840906
>2017
>people still complaining that type systems exist
>>
>>60840939
Im not talking about type systems, im talking about Rusts stranglehold and overzealous BC.
>>
>>60840932
You are getting upset, aren't you?
>>
File: 5.jpg (10KB, 300x100px) Image search: [Google]
5.jpg
10KB, 300x100px
Working on my imageboard, 4kev.org
>>
>>60840932
Well, it already has a thing called "modules". Too bad you pre-historic relics will never understand the fundamental overhead header files introduce to the whole development cycle
>>
@60840957
>anything more than a sentence response implies a rage-fueled rant
dumb phone-poster
>>
>>60840932
C++ is only fast when written in an idiomatic C style. So to actually use that performance, you have to give up using C++ features and might as well just use C. Rust allows you to use high-level abstractions AND generate fast code, while C++ forces you to choose one or the other.
>>
Go back to twitter, dipshit.
>>
>>60840952
that's a type system
>>
>>60840939
Type systems unnecessarily restrict the programmer. If I want to use a different type with a function I should be able to
>>
>>60840976
>shitting on Rust means I use C
Try again m80
>>
>>60840977
Who said this?
>>
What is the best place to learn fortran?
>>
>>60841001
C++ needs C preprocessors and has no modules.

C++ is a failure when compared to C. Try and cry harder
>>
>>60841011
Pajeet singh's youtube tutorial playlist
>>
>>60841019
But i use a language with modules.
>>
>>60841032
Good for you then
>>
>>60841026
Is this a serious answer?
>>
So, is anyone going to answer my original question >>60840646?
>>
In rust it's just
 rustup update 
:^)
>>
>>60841072
>:^)
>>>/v/
>>
>>60841072
more like rustup and-uninstall
>>
>>60840929
>Rust will end up killing C++ in the future
this is what special snowflakes actually believe
>>
New thread: >>60841126
>>
I'm learning javascript and have a simple problem. I am trying to make a game where the user rolls two dice and the scores of both the dice are added up for the users points. If the user rolls the same number on both dice, then he loses all his points.

if (dice !== 1 && dice2 !== 1) {
//add score
roundScore = dice + dice2;
document.querySelector('#current-' + activePlayer).textContent = roundScore;
} else {
//next player
}


For some reason when just one of the dice is zero it doesn't add points, I want it to only not add points if both of them are zero. This example is just for the number one, I want to do this for 1-6.

Thanks for the help
>>
>>60841164
I meant to say that if one of the dice is 1, then it doesn't add points, I want it to add the dice unless the dice combo is 1 and 1.
>>
>>60840891
>function's pointer isn't its value. If you want to have first-class functions, you most likely have to hide the implementation from the programmer so he can't tell that he's looking at a pointer.
But anon, functions are represented as pointers in every other language as well. How else would you refer to function if not by a pointer.
In python for example
def foo():
pass
bar = foo

bar, as well as foo, are pointers (references. same thing) to the function body somewhere in the memory. Then you can do
bar()
foo()

which is the entire point of passing functions around - calling them in different parts of a program.
Your point about values vs references doesn't make sense.

Your other point seems to be about scopes.
I would argue that the only real benefit of being able to define a function in an arbitrary scope is the closure functionality (which you don't mention at all).
>in C you can actually modify the executable code of a function
Well, you can always do that in every language, and every scope!
What's the difference (other than closures) in
A
def foo():
pass
def bar():
return foo

vs
B
def bar():
def foo():
pass
return foo

Yeah, foo is "encapsulated" in the bar code, but if you can modify the file that those functions are in, then what stops you from modifying foo body in A vs B?
There is no semantical difference (other than closures) between the two, and therefore between C and Python(or anything alse considered to have FCF)
>>
>>60841239
My point was to hide the implementation from the programmer like in all purely functional languages where there simply is no concept of a pointer (and in non-pure you usually have references, but functions are still entirely different type), but as I said I realized that point didn't lead anywhere.

As for the closures I meant to mention them implicitly. Another point would be cluttering the scopes. And I didn't mean to imply that defining functions in arbitrary scopes would somehow stop you from modifying functions, that was supposed to be entirely different point. I mean, functions as first-class values are so much less useful without closures.
>>
>>60841473
I replied in the next thread:
>>60841597
>>
>>60837356
Looks like Henrietta from the Evil Dead 2.
Thread posts: 323
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.