[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: 322
Thread images: 35

File: dpt_cpp.png (198KB, 1000x1071px) Image search: [Google]
dpt_cpp.png
198KB, 1000x1071px
Old thread: >>58380134
What are you working on, /g/?
>>
FP > OOP
>>
File: 1483714927513.gif (408KB, 400x264px) Image search: [Google]
1483714927513.gif
408KB, 400x264px
>go to make first post
>it's already made
>it's exactly what I wanted to post
>>
>>58388181
>make love, not war
Use OCaml, do both.
>>
>>58388181
procedural with FCF > FP > OOP
>>
>>58388221
If you write OOP in OCaml then you're using OCaml wrong
>>
File: 1483730818833.png (160KB, 373x345px) Image search: [Google]
1483730818833.png
160KB, 373x345px
>>58388260
I don't write OCaml at all.
>>
>>58388299
I bet you don't even program
>>
>>58388299
Good. Write Javascript.
>>
File: 1482055600767.png (818KB, 1280x719px) Image search: [Google]
1482055600767.png
818KB, 1280x719px
Functional programming.
Last /fpt/: >>58332039

Resources:
>Erlang
http://learnyousomeerlang.com/content
>>Elixir
http://chimera.labs.oreilly.com/books/1234000001642/index.html
http://elixir-lang.org/learning.html
>F#
http://fsharp.org/learn
>Haskell
https://en.wikibooks.org/wiki/Haskell
https://0x0.st/pbp.pdf
>Lisps
>>Common Lisp
http://gigamonkeys.com/book
http://www.cs.cmu.edu/~dst/LispBook/book.pdf
Paul Graham's ANSI Common Lisp
On Lisp
Common Lisp Recipes
Land of Lisp
>>Clojure
http://www.braveclojure.com/foreword/
The joy of Clojure
>>Scheme
Little Schemer
The Seasoned Schemer
The Scheme Programming Language by Kent Dybvig
Realm of Racket
Lisp in Small Pieces
>OCaml
https://realworldocaml.org/
http://ocaml.org/learn/tutorials/
>Scala
Functional Programming in Scala (Chiusano and Bjarnason)
Atomic Scala (Eckel and Marsh)
Programming Scala (Wampler and Payne)
Programming in Scala (Odersky, Spoon and Venners)
>Web languages
>>Elm
https://guide.elm-lang.org/
>>PureScript
http://www.purescript.org/learn/

>Theory
SICP
Essentials of Programming Languages
Practical Foundations for Programming Languages: http://www.cs.cmu.edu/~rwh/pfpl.html
How to Design Programs: http://www.ccs.neu.edu/home/matthias/HtDP2e/
Art of the Propagator
An Introduction to Functional Programming Through Lambda Calculus
>>
File: fuck.png (7KB, 609x96px) Image search: [Google]
fuck.png
7KB, 609x96px
>>
>>58388341
why?
>>
I don't understand the for loop in Python dict.

Given the following code:

gegeven = {"Type": "PC", "Prijs": 550, "Merk": "Acer"}
for key in gegeven:
print (key, gegeven[key])


For each loop iteration, Python will automatically assign the first variable as the key and the second variable as the value for that key. That makes sense right?

For some odd reason, 'for x in gegeven' works for one value but 'for x, y in gegeven' does not work for two. In that case you'd need to do "for x, y in gegeven.items()" but whatever.

Since in this code the first word prints the first value, print (key) would print:

Merk
Type
Prijs


print (key, gegeven) would print everything because key prints only the first value, and gegeven prints everything. Code becomes

Prijs {'Prijs': 550, 'Type': 'PC', 'Merk': 'Acer'}
Type {'Prijs': 550, 'Type': 'PC', 'Merk': 'Acer'}
Merk {'Prijs': 550, 'Type': 'PC', 'Merk': 'Acer'}


but then why does print (key, gegeven[key]) also print the values? "key" was assigned to print only the keys.
I thought adding another word would print the values because Python always does "x, y", so giving it a random name would work but it doesn't.

Printing print(key, gegeven[key]) prints:

Type PC
Prijs 550
Merk Acer


where in the heck do the values come from? it didn't get assigned to anything.
>>
>>58388313
Au contraire...

>>58388322
If you insist, but I'd rather write OCaml.
> var x = 3;
> '5' + x - x
50
> '5' - x + x
5
>>
>>58388392
JavaScript isn't a programming language.
>>
File: what have i done.jpg (510KB, 2100x2100px) Image search: [Google]
what have i done.jpg
510KB, 2100x2100px
i made something
>>
>>58388368
i dunno if i get what you mean, but

when you loop a dict you loop over the keys, you can also do
for x in y.keys():


and when you do dict[key] you access or assign the value of key in dict

also, when you declared keys in your dict, you have to give it a value, if you wish to assign empty values you do
gegeven[key] = None

or

gegeven = {key: None, key2: None, key3: None}
>>
>>58388392
>
> var x = 3;
> '5' + x - x
50
> '5' - x + x
5

This will be fixed with the upcomming use "use static".

Or so I'd wish. In reality JS will remain plebscript and all the decent web devs will compile to WASM.

>>58388424
It is a perfect example of what happens, if you design a programming language in 10 days.
>>
>>58388429
What happens when he writes a program in his Notepad?
>>
>>58388424
I never said it was.

But it is. Just a shit one.
>>
>>58388392
>
The real reason Lua has .. for concatenating strings
>>
>>58388448
It gets [spoiler]executed[/spoiler]
>>
>>58388475
Fuck i'd sworn spoilers worked on /g/ before.
>>
>>58388486
spoilers haven't worked on /g/ since 1993
>>
>>58388368
I didn't read your post, but try:

for key, value in gegeven.items():
print(key)
print(value)
>>
>>58388429
>>58388448
>>58388448
>declarative programing
>>
>>58388471
'..' is inferior to '<>'.
>>
File: 1482659453744.jpg (9KB, 234x216px) Image search: [Google]
1482659453744.jpg
9KB, 234x216px
>>58388497
>>
>>58388448

Hey, given that the death note can make a person do anything that person is physically capable of doing before dying... does that make the death note turing complete?
>>
>>58388515
No
>>
>>58388515
Not unless it can run Python 2.
>>
>>58388486
Here are your spoilers.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Take them.
>>
>>58388504
...Any particular reason?
>>
>>58388535
Yes.
>>
>>58388435
>>58388492
Sorry you didn't understand, let me re-explain it.

The first variable in Python is assigned as a key. The second variable as a value for that key.

for x in dictionary:
print (x)

will only print the key.

for x, y in dictionary.items():
print (x, y)

prints as well the key as the value.

but so does:

for x in dictionary:
print (x, dictionary[x])


now it's obvious the key is assigned to x. but [x] prints the values, while I didn't assign the values to anything.
how does that work?
>>
>>58388542
And that reason being...?
>>
>>58388529

Well it could make Zed Shaw write a Python 2 program on his computer, run it, and then immediately go into cardiac arrest afterwards. So it must be turing complete!
>>
File: what have i done3.jpg (458KB, 2100x2100px) Image search: [Google]
what have i done3.jpg
458KB, 2100x2100px
>>58388497
Here.
>>
Fuck, I dont know who I want to be anymore. Few months ago I have decided to be an computer scientist and started to read SICP, some math books, bought Arduino. And about a week ago I realised that I really want is to make games, I started to learn how to draw, play around in GameMaker. And now I have no idea in which way to proceed, cs or gamedev.
>>
I feel like my school isn't challenging me enough. What are some good lectures/ocw to watch?
>>
>>58388645
Both, make a new dwarf fortress.
>>
>>58388645
GameMaker =/= gamedev
>>
>>58388569
Everything's a fucking monoid. When you get some (slightly less hyperbolic) insight into the structure you'll understand why '+' gets abused to much in weakly-typed languages.

>>58388576
You could make him flip bits with a magnetised needle until he dies.

>>58388645
Just get hacking and decide on your speciality later.
And don't become a game dev; it sucks.

>>58388648
Read 'Essentials of Programming Languages':
https://karczmarczuk.users.greyc.fr/TEACH/Doc/EssProgLan.pdf
>>
I want to display card images in JLabels. I'm putting the images into the labels like this
 JLabel example = new JLabel();
example.setIcon(ic);

This means I can only have a limited number of cards displayed (as many as the number of labels I declare). Is there any way I can "generate" a label when I pull a card so that I don't have to set the number of cards that I want to display beforehand?
>>
>>58388687
>understand why '+' gets abused to much in weakly-typed languages.
We were talking about '..' vs <> for concatenating strings..?
>>
>>58388323
make a real thread mate
>>
>>58388687

Interesting and creative ways the death note has not been used yet: death by starvation. Make a person carry out a task to the detriment of all other actions. Does not sleep, does not eat, does not drink, just does that one thing with every ounce of energy they have in their body.
>>
>>58388724
Yup. The two things are not related.

You're just assuming they're related because they're similar. This is often called 'conflation'.

Although I could be very mean and point out that this all started with someone asking me to write some JavaScript, and my pointing out the potential horrors of weak typing, including using the '+' operator.

But that would be dishonest, since my statement about '+' was actually just offhand.

Now go learn about monoids, whose usefulness is the (essentially circular) reason that '<>' is better than '..'.
>>
>>58388768
Also, you could make someone eat themselves to death like in 'Seven'.
>>
>>58388694
use javaFX instead of swing
>>
>>58388760
Last threads died early.
It is simpler now to keep posting the old OP instead of creating and failing to keep the thread alive again.
Maybe if people show enough interest to FP inside /dpt/, /fpt/ will be created again.
But then again, /fpt/ wasn't fast and usually outlived several /dpt/ threads.
>>
>>58388825
>But then again, /fpt/ wasn't fast and usually outlived several /dpt/ threads.
is this supposed to be a downside?
>>
>>58388868
Not in my book, but remember that the guy you're talking to is a turboautist.
>>
>>58388694
make a method that returns a JLabel object and call it upon press or whatever you want to generate a card
>>
File: gopher.gif (181KB, 500x500px) Image search: [Google]
gopher.gif
181KB, 500x500px
Currently learning Go and GraphQL, fucking love them so far.
What are your opinions on them and what do you think of MongoDB?
>>
>>58388797
It's a uni assignment, I have to build the GUI using Swing, unfortunately. Is there any way to do it without using javaFX?
>>
>>58388886
Wow, somehow this didn't cross my mind. I'll try now and see if it works, thanks anon.
>>
File: pic.png (312KB, 506x662px) Image search: [Google]
pic.png
312KB, 506x662px
I'm having problems with the qt example called calculator builder,
Everything else is the same (the code, the .ui file), except I'm using clion instead of qtCreator.
I'm always getting an error in this line
Q_INIT_RESOURCE(calculatorbuilder);
undefined reference to `qInitResources_calculatorbuilder()'

My cmake file has this
cmake_minimum_required(VERSION 3.6)
project(calculator)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5UiTools REQUIRED)

qt5_add_resources(${RESOURCES} forms/calculatorbuilder.qrc)

set(SOURCE_FILES main.cpp CalculatorForm.cpp CalculatorForm.h)
add_executable(calculator ${SOURCE_FILES})

qt5_use_modules(calculator Core Widgets Gui UiTools)

Any help would be appreciated
Picture unrelated
>>
>>58388323
Only languages worth anything of those are Erlang, F# and Scala. Others are just meme languages.
>>
>>58388908
let me know what you come up with, i can help
>>
>>58388429
>>58388598
Where is 'what have i done2.jpg'?!

WHERE IS IT?!
>>
>>58388892
>Go
- GC.
- No generics.
- Outdated type system.
- No ADT.
- No pattern matching.
- Not enough functional stuff.
- No RAII/IDisposible/Context managers.
- Ugly syntax.
- The most retarded and unsafe error handling story after C.
- Structurally typed interfaces instead of proper interfaces/type classes/traits.
- NIH infrastructure with authors spending years reinventing stuff instead of using LLVM.
- Community comprised of mostly python-kiddies.
Overall the language was designed to be as simple as possible and then even more simple so Google can train code-monkeys on an industrial scale, the only good thing about it being coroutines.
>MongoDB
https://www.bleepingcomputer.com/news/security/mongodb-apocalypse-is-here-as-ransom-attacks-hit-10-000-servers/
>>
>>58388892
Go is good for servers. Anyone advocating MongoDB for production should be fired on the spot.
>>
>>58388960
The MongoDB thing is more of people being too stupid to configure the server safely, isn't it?
>>
i'm the sort guy from a couple of days ago

plain bubble sort uses a lot more iterations than insertion sort so i didn't even bother to time it

i made my own cocktail shaker sort variation which i thought was pretty clever but it uses around twice the number of inner loop iterations and it takes about twice as long as insertion sort

but this is mostly just taking 1-3 microseconds per sort for 64 uint32_t so this is largely inconsequential, lel

sometimes the timing spikes to around 0.1ms for a sort but i'm guessing it's a timing error or some other app that's using resources at the time
>>
>>58388960
>hackers have now hit around 10,500 MongoDB servers. That's about 25% of all MongoDB databases accessible via the Internet.
>The attacks don't target all MongoDB databases, but only those left accessible via the Internet and without a password on the administrator account.

GE 25% of internet-accessible MongoDBs don't have a password on the admin account? Jesus fucking Christ.
>>
>>58388960
t. Rust gender fluid sucker
>>58388985
No. It is notoriously inconsistent and packed with data races. /dev/null is a faster option for sending your data into the void.
>>
File: 1111.png (392B, 384x234px) Image search: [Google]
1111.png
392B, 384x234px
whats the difference between measuring and benchmarking?
>>
>>58389010
ok, thanks.

Anyone ever heard of dgraph? Concept looks interesting.

What database should I go for my very small web app?
>>
>>58389014
they're more or less synonyms but benchmarking implies a more thorough/scientific methodology and a measurement can be just putting timers in your program
>>
File: what have i done2.jpg (514KB, 2100x2100px) Image search: [Google]
what have i done2.jpg
514KB, 2100x2100px
>>58388953
I showed the first one to a friend and he told me to make this.
>>
>>58389025
sqlite3
>>
>>58389029
who is that mongolian carpet boy
>>
>>58389025
What is your data?
>>
>>58389029
I don't like it. Make more /g/ related ones.
>>
>>58388429
This one is best one.
>>
File: 1330717855245.jpg (365KB, 687x2600px) Image search: [Google]
1330717855245.jpg
365KB, 687x2600px
>>58389043
Japan's olympic swimmer trainer.
>>
>>58389043
>>58389025

My Data is basically just some (very few, maybe Guest and Admin) users, a bunch of Anime and how far I've watched it, but I want to keep it easily expandable, so I can integrate Torrents and other things and am not limited to Anime.
>>
>>58388687
>Read 'Essentials of Programming Languages':
looking more for a classroom setting than a book
>>
>>58389009
Is the incompetence of the average web dev and Mongo user really surprise you?
>>
File: 1483835239568.jpg (113KB, 473x496px) Image search: [Google]
1483835239568.jpg
113KB, 473x496px
>>58389084
If you can't make it through that book, you don't deserve to be in a classroom setting.
>>
>>58389049
more with the same template? that'd get boring fast.
I'll get to making more memery in the future.
>>58389043
it's the god of the new world
>>
>>58388645
Don't let your dreams be memes. Make the game you've always wanted to, but also learn some useful skills in case you need to get a job.
>>
File: 1421030859594.jpg (36KB, 300x360px) Image search: [Google]
1421030859594.jpg
36KB, 300x360px
>tfw NEETing out this weekend instead of practicing programming
>>
I'm designing a game engine because my language doesn't have a good one. What are some essential features of a component based engine?
>>
Text editor poll continues
>>
>>58389228
What your game needs. If you don't have a game you don't have any hope of making something that anybody will use if even you aren't going to use it.
>>
>>58389233
http://www.strawpoll.me/12023125
>>
Is Modern C by Jens Gustedt a good book?
>>
>>58389102
Is the incompetence definitely surprise me, but mayhaps I should no surprise.
>>
>>58389103
No, I can read a book. I read books all the time. I just want a classroom setting. I want to pretend like I'm actually at a decent college
>>
>>58389283
Yes
>>
>>58389163
NEETing?
>>
File: madoka programma.jpg (215KB, 800x1162px) Image search: [Google]
madoka programma.jpg
215KB, 800x1162px
>>
>>58388941
I just tried it and it works, now I just have to set up the panel layout. Thanks again!
>>
>>58389383
show me the code
>>
>>58389320
being a NEET
>>
>>58388251
what is 'fcf'
>>
>>58389404
First-class functions.
>>
>>58388251
I sincerely hope you're using Lisp and aren't trying to justify using Python
>>
>>58389434
Anything even slower than Java need not exist.
>>
>>58389386
public JLabel createLabel(Icon ic){
JLabel label=new JLabel();
label.setPreferredSize(new Dimension(100,100));
label.setIcon(ic);
label.setVisible(true);
return label;
}

Here it is
>>
>>58389502
nice, good job sport
>>
how the fuck do i into programming?


i started out learning the syntax and basic shit, got bored with that and moved onto basic challenges

now i'm just building little math programs

is doing this actually helping or should i move onto something bigger? if so, what?
>>
>>58388557
bedoel je waar de waarden 550, acer en PC vandaan komen? je hebt toch je woordenboekje gedeclareerd? ik snap niet echt wat je probleem is
>>
>>58389578
Do you have goal in mind?
Do you want to build something or just 'learn programming to get a job as a programmer'?
>>
>>58389578
you either come up with something new to make or you remake a program that you can do by yourself but you make it however you want it to be
>>
>>58389578
>>58389633
Or you can find a project you are passionate about and learn by forking/contributing.
>>
>>58389625
>>58389633

i want to build something but dont know what python is capable of

also dont know if i have the skills to do a big project

what are some example projects i could do?

i dont want to make video games

dont want a job, i prefer the NEET life
>>
>>58389666
i definitely dont have the skills to actually help real programmers yet
>>
>>58389681
I don't really know any projects, you could make a physics simulator or something, try to find something you need to do a lot and that you could automate by making a program that does it for you. keep it simply, my negroid
>>
>>58389309
>I want to pretend like I'm actually at a decent college
If you were at a decent college you'd be able to read that book.
>>
>>58389348
I enjoyed this.
>>
>>58388221
OCaml is shit.
>>
>>58389761
See >>58388299
>>
Is NoSQL a meme?
>>
>>58389769
It's not enough that you don't use it. I want nobody to use it. I want people to stop thinking going halfway is good enough.
>>
I'm writing my own PL.
>>
>>58389800
Does it have higher-kinded types?
>>
>>58389800
tell us more about it buddy
>>
>Rust
>Elm
>F#

Why would you make a crippled language?
>>
>>58389821
What's crippled about Rust? Elm is webshit and F# is NETshit so I can understand that.
>>
>>58389792
Halfway to what?

If you're about the say something like 'halfway from FP to OOP', you're asking for someone to point out that the two are not mutually exclusive... and then use OCaml as proof.

However, I fully endorse any attempt made by you to sabotage OCaml and its users, as I find the language absolutely disgusting.
>>
>>58389830
No HKTs.
>>
>>58389839
Good point but that makes almost every language crippled. I suppose I don't disagree, now that you make me think of it.
>>
>>58389833
Halfway to FP. It limits you to what can be considered the first step of FP.
>>
>>58389810
WTF is this?
>>58389812
Replacement for C with generics, module system, explicit nullability of pointers, and foreachable 'collections'. No runtime or libc deps.
>>
>>58389830
>Elm
Webshit
>F#
Netshit

This compels me to continue:
>Rust
SJshit
>Lisp
Parentheshits
>OCaml
Camelshit
>Perl
Also camelshit
>Java
Monkeyshit
>Haskell
Pureshit

Anyone else want to add to this?

>>58389853
I fucking knew it. And as I predicted, someone will now point out that FP and OOP are not mutually exclusive, OCaml being proof of this.
>>
>>58389864
>with generics
Then there's no reason to not support HKTs.
>>
>>58389864
sounds fucking sweet

>>58389871
Are you just going to be bitter or do you have an alternative in mind?
>>
>>58389871
FP and OOP are not mutually exclusive in the same way that milk and liquid shit are not mutually exclusive.
>>
>>58389885
There is one good reason: I don't know what the fuck it that in practice. What pain would it alleviate? At what cost?
>>
File: hansenvspredatorep2.jpg (363KB, 1238x680px) Image search: [Google]
hansenvspredatorep2.jpg
363KB, 1238x680px
which 3 languages would a sadist teach a beginner?
>>
>>58389915
It allows code reuse.
>>
>>58389931
perl apl and assembly
>>
>>58389901
This I agree with.

>>58389900
Bitter about what?
"Things that I am bitter about" really doesn't help me narrow down the context much.

>>58389931
Machine code, MASM and GASM.
>>
>>58389931
PHP, Visual Basic, JavaScript
>>
>>58389915
>I don't know what the fuck it that in practice.
Maybe you should before you embark on designing a language.
>>
>>58389864
That sounds incredibly dull.
>>
>>58389932
>It allows code reuse.
Well, the only thing that really allows for code reuse are libraries.
>>
/dpt/, what music do you listen to while programming? link me some
>>
>>58389915
Normally generics only abstract over types. HKTs mean you can abstract over type constructors (i.e. generic types themselves).

Say for example that you have a type of reference counted pointers and a type of atomic reference counted pointers, both generic over the type of whatever they point to. They have the exact same API. HKTs mean you can write something that is generic over the pointer type but can use it on different content types.

The same could be said for array lists vs. linked lists and so on.
>>
>>58389999
https://www.youtube.com/watch?v=aHk42kDwesM
>>
>>58389996
You've never defined a function and used it from more than one place within the same codebase before?
>>
>>58389915
>>58390004
I also didn't want to bring in any FP "buzzwords" but HKTs are integral to making functors and monads useful, among other things.
>>
>>58390018
"""Code reuse""" is a meme, generics and HKT's are still great.
>>
>>58390043
>code reuse is a meme
>I don't use loops or recursion in any of my code
>>
File: 1451346645505.gif (1MB, 268x274px) Image search: [Google]
1451346645505.gif
1MB, 268x274px
>>58390043
>"""Code reuse""" is a meme
>>
>>58390058
>>58390064
Being able to design (standard) libraries within a language is important, and generics make this more comfortable to do.
Copying functions between projects is not nearly as important or common.
>>
>>58390118
>Copying functions between projects
Nobody specified this.
>>
>>58389993
Good. It means language could actually be useful.
>>58390004
So, like traits/type classes? Maybe in some distant future.
>>
>>58390133
>Good. It means language could actually be useful.
I bet you have a job or attend a university or something, too, you filthy fucking casual.
>>
>>58390133
>design a language no more expressive than existing languages
>implying this doesn't make it useless
>>
>>58390133
HKTs work very well with traits but they aren't intrinsically related. They're a very basic extension of standard generics.

I mean, without traits, *generics* aren't all that useful but because you have no traits I assume you mean they're actually templates.
>>
>>58390133
>So, like traits/type classes? Maybe in some distant future.
No. You can have traits/typeclasses without HKTs, and you can have HKTs without traits/typeclasses.
>>
>>58389681
PROJECT EULER
>>
File: 1482504727384.png (85KB, 480x377px) Image search: [Google]
1482504727384.png
85KB, 480x377px
>>58390043
>"""Code reuse""" is a meme
>>
>>58390018
What kind of derp it this? Of course I did. I meant *meaningful* code reuse.
>>
>>58390204
>functions do not allow for meaningful code reuse
u wot m8
>>
File: 1483423464145.jpg (96KB, 576x720px) Image search: [Google]
1483423464145.jpg
96KB, 576x720px
>>58390204
>code reuse is a meme
>oh, except for that kind of code reuse
>and that kind
>oh and that kind, too, I didn't mean that
>>
>>58390166
>>58390174
Thanks. I'll educate myself on the topic.
>>
>>58390261
Ever seen template templates in C++? That's HKTs.
>>
>>58389999
nice dubs
>>
>>58390043
>"""Code reuse""" is a meme
what did he mean by this?
>>
>greentext
>but muh junior html-dev level code reuse!
Keep at it, boys.
>>
>>58388167
Reading some stuff.
https://www.ecse.rpi.edu/~agung/course/vanderschaft.pdf
>>
>>58390043
>"""Code reuse""" is a meme
Really makes you think, huh.
>>
File: sml.png (28KB, 194x166px) Image search: [Google]
sml.png
28KB, 194x166px
fun pascalNextLine 1::nil = 1::nil
| pascalNextLine (1::x::xr) = 1::(1+x)::pascalNextLine(x::xr)
| pascalNextLine (x::y::xr) = (x+y)::pascalNextLine(y::xr)

> pascalNextLine [1,3,3,1]
> | Uncaught exception
> | Match

Could this be more unprecise please?
>>
File: 1481852295525.jpg (16KB, 480x236px) Image search: [Google]
1481852295525.jpg
16KB, 480x236px
>>58390315
>code reuse is a meme
>>
>>58390280
No, I was lucky enough to dodge all that C++ madness.
>>
http://yarchive.net/comp/linux/signed_unsigned_casts.html

how safe is it to cast from unsigned to signed? if it's linus-approved, it should be fine, right?
>>
>>58390261
normal generics (fake syntax):
typeclass Eq(t)
== : t -> t -> Bool

instance Eq(Int) ...

forall(t) where Eq(t)
fn find (x : t, list : Listof(t)) -> Bool
...

find(3, [1,2,3,4,5]) = true
find(3, [| 1,2,3,4,5 |]) = ERROR: expected List(Int), got Vector(Int)


generics with HKT's:
typeclass ListLike(lst)
null? : forall(a). lst(a)
first : forall(a). lst(a) -> a
rest : forall(a). lst(a) -> lst(a)

instance ListLike(Listof)
...

instance Listlike(Vector)
...

forall(lst,t) where Eq(t), ListLike(lst)
fn generic_find (x : t, list : lst(t))
...

generic_find(3, [1,2,3,4]) = true
generic_find(3, [| 5,6,7 |]) = false
>>
>>58390419
ap (ap . (liftM2 ap .) . liftM2 (.) (.) . (.) . (.)) ((. flip) . (.) . (.))
>>
>>58390498
I don't see how my pseudo functional code is confusing at all, I'm not using point-free style at all
>>
>>58390534
He probably just can't distinguish between the two.
>>
last_login: 1482653256


What does this mean? It's supposed to be a date but how do I decode it
>>
Please do type masturbation in /fpt/ thanks.
>>
>>58390419
I see. Thanks.
If I understood it correctly, HKT are indeed just one small step forward from generics. But I doubt I'll put them in the language: I still want it to be 'disassembliable' at a glance like C. One level of type indirection (generics) are 'unentangleable', but two... I don't know. Have to think about it.
Thanks again.
>>
>>58390558
>masturbation not welcome in /dpt/
Since when?
>>
>>58390553
Unix time aka seconds from start of 1970-01-01?

>open browser console
>new Date(1482653256000)
>Date 2016-12-25T08:07:36.000Z
extra zeroes because browsers want milliseconds, not seconds
>>
>>58390558
/fpt/ is part of /dpt/, programlet
>>
>>58390558
masturbation in /fpt/ thanks.


There, I typed it.
>>
>>58390358
>>58390261
higher kinded type polymorphism means polymorphism over higher kinded types
a higher kinded type is like a type function, e.g. a template in C++ such as vector or list.

Both vector and list have kind
Type -> Type
, i.e. given a type they return a type.
Map has type
(Type, Type) -> Type
(where the first type can be < compared)

Array has type
(Type, size_t) -> Type
>>
>>58390592
>I still want it to be 'disassembliable' at a glance like C.
I don't really see how HKTs work against this. Maybe they make the problem of seeing what would happen given template specialization worse, but I hope you don't have that in the first place.

It's like saying functions make things harder to understand than just values.
>>
>>58390612
Ah ok, thanks fammy.
>>
>>58390592
It's a matter of opinion. Second-order generics feel natural to me, whereas go programmers struggle with even first-order generics.
>>
what's the appeal of functional programming anyway? did you fall for the anti-java meme so hard that you had to go to the other extreme end of the spectrum?
>>
Ya know now that I think about it, why the fuck doesn't Rust have HKT's... how the fuck are you supposed to e.g. write generic code that uses iterators without them, it's impossible to type a function such as
fn find_in_iterator<Iterator,T> (needle : T, haystack : Iterator<???>)


>>58390592
One tricky thing about HKT's is that they require an additional level of type checking, basically you need to rewrite all of your type checking rules in a simpler form for HKT's, it kinda sucks to implement.

>>58390620
HKT's are one thing but type-level values are a different beast. Rust has good reason not to implement them because doing so requires a lot of VERY complex theorem-proving logic at the type level that is likely either undecidable, broken, or just very complex
>>
>>58390657
what's the appeal of object-oriented programming anyway? were you worried that your keyboard wouldn't get enough use otherwise?
>>
>>58390657
This might be hard for you to believe, but FP has been around for as long as imperative programming (although not formalised as such), and much longer than OOP.
FP is not just a rebellion against OOP.
>>
>>58390657
Makes you feel smart
>>
>>58390663
>why the fuck doesn't Rust have HKT's
Good question, friend. Good question.
>>
>>58390657
It's a natural improvement on procedural programming whereas OOP just throws everything away but has to become some ugly hybrid of the two to actually be useful.

>>58390663
>why the fuck doesn't Rust have HKT's
I don't know. They're incredibly useful for lifetime stuff, too.
trait Platform {
type Window<'a>;
fn create_window(&'a self, ...) -> Window<'a>;
}

It even has higher rank polymorphism for lifetimes so they clearly understand the need for this kind of thing.
>>
>>58390663
>HKT's are one thing but type-level values are a different beast. Rust has good reason not to implement them because doing so requires a lot of VERY complex theorem-proving logic at the type level that is likely either undecidable, broken, or just very complex
That's the kind they have, restricted to follow parametricity

>>58390620
Meant Kind
>>
>>58390675
but procedural and OOP are clearly superior to FP
>>
>>58390630
>but I hope you don't have that in the first place
Em, I don't see how I could pull off language without runtime (meaning no GC too) without compile time specialization.
>>
File: mfw your opinions.gif (3MB, 240x234px) Image search: [Google]
mfw your opinions.gif
3MB, 240x234px
>>58390699
>>
>>58390709
Runtime generics can be implemented using pointers. If the instance is known at compile time, it can be specialised (if desired).
>>
>>58390663
>type-level values are a different beast
Only dependent types. Without regard to anything else, types can be used to implement any type-level value (see the fuckery people have managed in Haskell) and you don't run into trouble but Rust desperately needs type-level numbers to work with array lengths.

>>58390709
Monomorphization is different from template specialization, and even then, C doesn't have either.
>>
>>58390738
>Only dependent types.
No, (arbitrary) type level values of any kind requires being able to compare f(x) and g(x) for arbitrary f and g which is undecidable. The only reason C++ gets away with it is because it is purely based on template instantiation, which is completely unchecked.

>Rust desperately needs type-level numbers to work with array lengths.
This is true, but it would awkward to implement. Rust is already going down the rabbit whole of FP-features-it-probably-shouldn't-attempt-to-implement and if it fucks up any more I'm dropping it completely.
>>
who /assembly/ here
>>
>>58390734
Ugh, that would be slow. I'll just 'pack' all code/structs that have same size into one. I doubt that compile time specialization would inflate resulting binary that much to resort to runtime support.
>>
>>58390821
>requires being able to compare f(x) and g(x) for arbitrary f and g which is undecidable
Depends how complete you want the theory to be. If you leave those functions uninterpreted then it's decidable.

>This is true, but it would awkward to implement.
Not really. You don't even need to allow operations on the type-level numbers for them to be quite useful. Though I suppose they would need to augment the syntax so that you provide kinds for generics and not just distinguishing between types and lifetime by the naming convention.

>>58390882
Please see >>58390738. When I said you shouldn't have template specialization I meant what C++ allows, which is using a different template entirely depending on the argument. Implementing generics using monomorphization is no problem at all for reasoning because it's just straight substitution.
>>
>>58390882
well then you just have to instantiate everything
>>
>>58390923
>If you leave those functions uninterpreted then it's decidable.
And it's worth noting that this is what Rust (and Haskell) already does with type constructors.
>>
>>58390821
Good thing I'm uneducated on that academic matters. Because I will have those tasty array<element-type, size> and ptr<element-type, terminating-element-value> types no matter what.
>>
>>58390923
>>58390956
As a non-academic way to put it:
How will <language with type level values> know that Array<T, n+1> is the same as Array<T, 1+n> ?
Should comparing the two cause a type error (which would upset a lot of people), or should we hardcode every algebraic rule to make them unify correctly?
>>
File: 1483730088437.png (465KB, 619x481px) Image search: [Google]
1483730088437.png
465KB, 619x481px
>>58390976
Hardcoding is fastest, let's do that.
>>
>>58390976
>How will <language with type level values> know that Array<T, n+1> is the same as Array<T, 1+n>?
That's decidable with Presburger arithmetic. 2-EXPTIME, but decidable.

>Should comparing the two cause a type error
Depends if you want to have a Presburger decision algorithm as part of your unification or not, or if you want to allow some checking to be delayed until instantiation (which would be even more powerful than Presburger arithmetic but admittedly not as nice).

>which would upset a lot of people
It wouldn't be unprecedented.
>>
>>58390976
Hardcode. And support only for Arrays. That would not solve 100% of a problem, but should be helpful enough. Low hanging fruits and all that.
>>
>>58390976
>>58391020
And like >>58391038 says, sure, you can only completely solve the problem by making the programmer write proofs, and then you might as well use dependent types, and so on down the rabbit hole.

But if there is a good partial solution to the problem that is better than what we have, why not? HM types are only a partial solution to the problem of polymorphic types but they're pretty damn useful nonetheless.
>>
>>58391020
>That's decidable with Presburger arithmetic. 2-EXPTIME, but decidable.
And when people come crying for type level floats and type level arrays, what will you do? Grind compilation to a halt with an even bigger computer-algebra solver in the type checker?

>some checking to be delayed until instantiation
>>58391038
>support only for Arrays.
>>58391081
>good partial solution to the problem
Perhaps. But much of these solutions are basically based around opinions of what is a "good enough" solution to a difficult to solve problem. And much of what Rust is trying to do is *actually solve* problems like memory safety rather than provide "good enough" solutions like C++ does.

>[upsetting academics] wouldn't be unprecedented.
Well...
>>
>>58390663
>why the fuck doesn't Rust have HKT

The Rust team seems to be working that way, but they haven't implemented it yet.
>>
>>58391081
>HM types are only a partial solution to the problem of polymorphic types but they're pretty damn useful nonetheless.
This. Sometimes a good hack is all you need.
>>
>>58391125
I think the type system and standard library is already too fucked to add HKT's this late in the game.
>>
>>58391100
>type level floats
The theory of real numbers with addition is decidable and its decision algorithm is actually part of the decision algorithm for Presburger arithmetic (basically, decide the formula for real numbers and check that the results aren't fractional).

>type level arrays
Again, can be done with the theory of uninterpreted functions.

>Grind compilation to a halt with an even bigger computer-algebra solver in the type checker?
You could just say wontfix.

>And much of what Rust is trying to do is *actually solve* problems like memory safety rather than provide "good enough" solutions like C++ does.
Rust doesn't mind doing runtime checks where static checks would make the language that much more complicated. This wouldn't be going against that. Rust could add type level naturals with no algebraic theory or operations whatsoever and it would be a massive improvement.

>>58391133
AFAIK the problem is mostly about picking a satisfying syntax and also that they have priorities set on other things.
>>
PROGRAMMING CHALLENGE:

Given a list of state changes of a continuous Markov process return a function that maps a time value to the corresponding state.

Ex. Passing the following into the function
[(0.00, 1), // Process starts at time t = 0 with state 1
(0.23, 2), // At time t = 0.23, the process switches into state 2
(0.56, 1), // At time t = 0.56, the process switches back into state 1
(0.75, 1)] // The process terminates at t = 0.75


Would return a function f with the following properties
f(0.1) == 1
f(0.4) == 2
f(0.6) == 1
>>
>>58391133
Even if that were true the stdlib can be fixed. They aren't as dead set on backwards compatibility as in C++. I'm sure there will be a Rust 2.0 at some point (although not for a few years at least).

But
>>58391146
>AFAIK the problem is mostly about picking a satisfying syntax and also that they have priorities set on other things.

is correct from what I can tell. There's also more than one way they could implement it and there is no clear answer which way to go with until they sort out all the pros and cons.
>>
>>58391146
>priorities set on other things
You mean the SJW shit? Because, yeah, that's totes more important than having a slightly usable type system.
>>
>>58391217
(You)
>>
File: KJuNCmW.jpg (199KB, 600x324px) Image search: [Google]
KJuNCmW.jpg
199KB, 600x324px
>>58391217
>totes
>>
>>58391224
>>58391248
>triggered
>>
>>58391217
>umm if i mention those darn sjw's ill probably get chan cred!
>alright, 5 years of reddit have prepared for me, lets press post! here I go hehe
>>
File: 20e.png (52KB, 600x556px) Image search: [Google]
20e.png
52KB, 600x556px
>>58391260
You sure showed us.
>>
Get input from HTML, POST it to python, process it and get the output back in the web page.

What's the most elegant way to do this?
>>
>>58391148
fun xs t = fromJust (snd <$> find ((t >=) . fst) (reverse xs))
>>
>>58391372
find is in Data.List and fromJust is in Data.Maybe
>>
>>58391200
>picking a satisfying syntax

fn foo<T :: *>(x: T) { ... }

fn bar<T :: * -> * : Functor>(x: T<i32>) -> T<i64> { ... }

fn baz<T>(x: T) { ... } // Syntactic sugar for fn foo<T :: *>(x: T) { ... }

fn quux<T :: (* -> *) -> * -> * : MonadTrans, ...>(...) { ... }


Done. Now they can stop inventing problems and get implementing it.
>>
>>58391380
>only infers kind *
drake.jpng
>>
File: browser_.webm (3MB, 1920x1080px) Image search: [Google]
browser_.webm
3MB, 1920x1080px
another day, another tweak.

how many lines of code do you write a day?
>>
>>58391380
You didn't read:

> There's also more than one way they could implement it and there is no clear answer which way to go with until they sort out all the pros and cons.

It has more to do with how it interacts with the language. But they also like to keep the grammar as context free as possible.

> -> * -> *

Curry nigger.
>>
>>58391405
It's Rust, do you really think they can implement kind inference?
>>
>>58391248
>>58391224
LE LEBBIT HAHAHAHAH!
THAT WILL SHOW HIM XDDDDD
TEE HEE MUH SEKRIT CLUB LE 4CHIN LE ANONYMOOSEEEE XDDDDD EBIN ANIMAY
MAYMAYS LE EPIC TIPS FEDORA NOTHIN PERSONNEL KID XDDDD
LE ME LE ANSWER LE LEDITER XD
TIS A LEBITPOSTER!!!11!ONEONE!!
OMG MODS == GODS XDDDD
>>
>>58391430
This shit looks horrendous.
Why do you even bother?
>>
>>58391436
Kind inference is fucking simple in something like that
>>
>>58391462
No job.
>>
File: autism.jpg (96KB, 900x720px) Image search: [Google]
autism.jpg
96KB, 900x720px
>>58391449
>>
>>58391405
>>58391436
Kind inference is easy, though. What they presumably don't want is for inference to depend on the body of the function (although it only really matters for trait methods).
>>
>>58391479
Why is that kid so happy?
>>
>>58391492
he's finally getting a hug
>>
>>58391148
s/CHALLENGE/HOMEWORK/
;; (markov-time-func [states : (listof (cons/c real? state?))]) -> (real? . -> . state?)
(define (markov-time-func states)
(lambda (t)
(or (for/last ([s (in-list states)]
#:when (> t (car s)))
(cdr s))
(cdar states))))

(let* ([S '((0.00 . A)
(0.23 . B)
(0.56 . C)
(0.75 . D))]
[f (markov-time-func S)])
(map f (range 0 1 0.2)))
; result: '(A A B C D)


no idea if this actually works or not
>>
>>58391479
>american parenting
>>
>his language doesn't have bidirectional type rules
>>
>>58391405
>>58391474
>>58391481
I'll take non-kind-inferred HKTs over no HKTs.
>>
>rewrite code to use ContT
>guaranteed job security
>>
>>58391554
callCC $ \employee -> fire employee
>>
>>58391530
Still, it's trivial for the kind F : * -> * to be inferred for e.g. F : Functor or a type signature that mentions F<T>.
>>
>>58391475
Do you have a repo with this or something?
What is it written in anyway.
>>
>>58391583
It's a mix of C, Python and JavaScript.
>>
>>58391100
>And much of what Rust is trying to do is *actually solve* problems like memory safety rather than provide "good enough" solutions like C++ does.
Rust tries is to solve memory safety problem while not employing a GC. And while it tries, we need something, even if it only on "good enough" level.
>>
>>58391603
>python on Windows
>JavaScript ever
Jesus fuck.
>>
>>58391583
Missed your other question. No repo, I just copy the code folder every day.
>>
>>58391603
How much did it take you to get this far?
Why not just get employed as a programmer?
>>
>>58391569
That's the great thing, it's not in Haskell but in Scala so the code is horrendous.
>>
>>58391603
>>58391629
Are you trying to trigger me?
>>
>>58391148
Behaves kind of strangely on the edge cases.

cm[data_][t_] := Cases[{data}, {___, {_, s_}, {_?(GreaterThan[t]), _}, ___} :> s]
>>
>>58391657
No, I use JavaScript for parsing, Python for rendering and network code and C to send data between the two.

I don't bother with a real VCS because I don't need commit messages yet.

>>58391647
I've spent about four months on it so far.

I get claustrophobic working with other people.
>>
>>58391530
>>58391580
In fact, I can't think of a single compelling case where neither holds. If some F<T> isn't in the type signature, you're using it internally. But if F doesn't implement a trait, how are you going to use any F<T> in the first place?

They don't need a syntax for kinds. For distinguishing between types of varying arities and lifetimes, the name is enough, and for determining the arity of the type the constraints and signature are enough.
>>
>>58391712
I'm a beginner.
Can you show me some sample code or whatever?
I can't imagine how to literally make something with 3 separate languages.
>>
File: Untitled.webm (1MB, 960x1040px) Image search: [Google]
Untitled.webm
1MB, 960x1040px
>>58391475
>>58391603
>>58391629
>>58391712
I'm slightly amused. please, continue.
>>
>>58391712
>I've spent about four months on it so far.
>browser #113
So... the numbering is how many days and versions in you are?
>>
>>58391677
Here we go. Take it or leave it.
>>
>>58391712
>No, I use JavaScript for parsing, Python for rendering and network code and C to send data between the two.
>I don't bother with a real VCS because I don't need commit messages yet.
You should just use Haskell
>>
File: yous2.png (139KB, 375x1079px) Image search: [Google]
yous2.png
139KB, 375x1079px
>>
>>58391803
(and 'lisp)
>>
File: samefag.png (14KB, 1206x76px) Image search: [Google]
samefag.png
14KB, 1206x76px
>>58391827
*teleports behind you*
nice try, >>kiddo (You)
>>
File: Untitled.png (4KB, 361x104px) Image search: [Google]
Untitled.png
4KB, 361x104px
Anybody knows why is the month fucked?
>>
>>58391953
SimpleDateFormat is not threadsafe.
>>
>>58391953
probably because it's mm as in minute
>>
>>58391953
You want MM, mm is minutes.
>>
>>58391953
Aint 'mm' for minutes? Try MM
>>
I've implemented a very basic cout in Rust:
#![allow(non_camel_case_types)]

use std::fmt::{self, Display};
use std::ops::Shl;

struct cout;
struct endl;

impl<T: Display> Shl<T> for cout {
type Output = Self;

fn shl(self, rhs: T) -> Self::Output {
print!("{}", rhs);

self
}
}

impl Display for endl {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\n")
}
}

fn main() {
let x = 12;
let b = "foo";
let y = 134.123;

cout << x << " " << y << ' ' << b << endl;
}


Output:
12 134.123 foo
>>
>>58391953
java.util.Date does not represent a date.
>>
>>58388167

if I have some 2d points on a 2d plane

how do I transform them so that they are in 3d space with a given vector as the 3rd axis
>>
>>58392003
printf("%d %f %s\n", x, y, b);
>>
>>58391983
>>58391990
>>58391992
Thanks a lot anons.
>>
>>58392028
That's not ROBUST TURN KEY ENTERPRISE READY code.
>>
>>58392028
Yes, i could have just used
println!("{} {} {}", x, y, b);
, but that would be boring.
>>
>>58392066
Won't the multiple method calls in the code you posted have a performance cost?
>>
>>58392003
Why? cout was a bad idea.
>>
>>58392094
Dunno, i just did this for fun. I would use that code seriously.
>>
>>58392144
*I would NOT use that code, is what i meant to say.
>>
>>58392160
Ah ok. Learning Rust?
>>
>>58392166
Nah, i know Rust already. Just bored.
>>
>>58391733
Rust refusing to implement HKTs feels like Python refusing to implement TCO
"Were going to half-assed this functional feature, but wimp out when actually tasked with implementing something to make it work well, and when people complain we'll just pretend that some intrinsic aesthetic quality of our language is whats preventing this feature"
>>
>>58392215
>aesthetic
>Python
>>
>>58392215
That's not what's happening. HKTs are a wanted feature, people are trying how to implement it without ending up with a c++-like mess.
>>
>>58392215
Eh, with Python not having TCO is completely irrational and just Guido being a faggot. With Rust they want to make sure that they do it right the first time. While I think they focus too much on that and thus don't get enough done (and you don't need to be as fluid as Haskell to implement new features either), at least it's somewhat understandable.
>>
>>58392242
Sounds an awful lot like they're stalling and making excuses tbqhf.
>>
>>58392242
*trying to figure out
>>
>>58392236
>pretend
>>
>>58392250
This behaviour isn't specific to HKTs, they behave the same about basically any language/stdlib feature.
>>
>>58392250
You realize Rust is open source? If you have a brilliant idea how to do HKTs ergonomically, nothing is stopping you from going on github or internals.rust-lang.org and give your 2 cents.
>>
>>58392236
>its """""pythonic"""""
>>
I want to force the user to input another number if their entered number is higher than 23.

How do I accomplish this?

>What is the height of the pyramid?
"24"
>The pyramid cannot be higher than 23 feet!
*user forced to input again here until they type 23 or lower*


#include <stdio.h>
#include <cs50.h>

int main(void)
{
int height;
printf("What is the height of the pyramid?\n");
height = get_int();

if (height > 23)
printf("The pyramid cannot be more than 23 feet high!\n");
else
printf("The pyramid is %d feet high!\n", height);

}
>>
>>58392361
Use a loop
>cs50
Is this a common header uni courses use?
>>
File: 1472776308497.gif (59KB, 1000x1192px) Image search: [Google]
1472776308497.gif
59KB, 1000x1192px
Quick question: If I'm years out of programming practice and want to write a python application that constantly plays inaudible sound (for the purpose of keeping my DAC on and out of standby mode), and I want this to appear in the windows 7 system tray instead of an active window, how badly will I want to kill myself?

My DAC turns itself off after 1 sec of no audio, then takes 1.7 seconds to boot back up. This effectively mutes the first 1.7 seconds of any sound effect, music track, etc. This is my proposed workaround, after getting tired of keeping long youtube videos playing in the background at 1% volume. This too keeps my DAC on and solves the issue, I want something more elegant without buying another DAC.
>>
>>58392295
But HKTs are 90% typechecking
>>
>>58392361
Do something like:

 while (height >= 24) {
printf("What is the height of the pyramid?\n");
height = get_int();
}

Though I would not use get_int, and you really don't need that cs50.h header, though I'm assuming this is for a class or something.Use something like fgets for input.
>>
I'm searching for materials about Ruby and Ruby on Rails. I want to learn them them. Lots of stuff on the net.
>>
>>58388892
go and graphql is cool

don't use mongo, use leveldb or rocksdb or cassandra or anything other than mongo

and use a nosql db only if you _need_ to use it, else stick with postgres
>>
>>58392466
Brain damage.
>>
>>58392383
if (height > 23){
printf("The pyramid cannot be more than 23 feet high!\n");
return main();
} else {
printf("The pyramid is %d feet high!\n", height);
}
>>
>>58392498
fuck
>>58392361
>>
>>58392383
Sure it's the DAC itself powering off, and not some system power management setting triggering it?
>>
>>58392421
do 
printf("What is the height...\n");
height = get_int();
while(height >= 24);
>>
>>58392498
>>58392421

i managed to get it to work like this

#include <stdio.h>
#include <cs50.h>

int main(void)
{
int height;
printf("What is the height of the pyramid?\n");
height = get_int();

while (height >= 24) {
printf("The pyramid cannot be higher than 23 feet!\n");
printf("Try again!\n");
printf("What is the height of the pyramid?\n");
height = get_int();
}

if (height <= 23) {
printf("The pyramid is %d feet high!\n", height);
}
}


so if I return main(); it runs the program from the beginning?
>>
Want to write a script that:
>Monitors nyaa for a list of shows
>Torrents new episodes
>Converts files to mp4 with ffmpeg
>Transfers converted files to webserver

What's the absolute minimum amount of effort that will make this work
>>
>>58392489
?
>>
>>58392597

just an update, cleaned it up.

#include <stdio.h>
#include <cs50.h>

int main(void)
{
int height;
printf("What is the height of the pyramid?\n");
height = get_int();


do {
printf("The pyramid cannot be higher than 23 feet!\n");
printf("Try again!\n");
printf("What is the height of the pyramid?\n");
height = get_int(); }
while (height >= 24);

if (height <= 23)
printf("The height of the pyramid is %d feet high!\n", height);
}


The do/while is confusing me. How come you don't need to put an end curly bracket after
while (height >= 24);[/spoiler]?
>>
>>58392780
That's the condition, it doesn't have a body.
>>
>>58392821
makes sense.

I have one more question.

If I put

     if (height <= 23)
printf("The height of the pyramid is %d feet high!\n", height);


above

do {
printf("The pyramid cannot be higher than 23 feet!\n");
printf("Try again!\n");
printf("What is the height of the pyramid?\n");
height = get_int(); }
while (height >= 24);


Why does it still display everything else as if the input number was 24 or higher?

>What is the height of the pyramid?
"23"
>The height of the pyramid is 23 feet high!
>The pyramid cannot be higher than 23 feet!
>Try again!
>What is the height of the pyramid?
>>
how do I do a triangle fill?
>>
>>58392780
>so if I return main(); it runs the program from the beginning?
Yes. Your last variation is better though.
>The do/while is confusing me. How come you don't need to put an end curly bracket after
Why do you thing you need one?
>>
>>58392889
do { instructions } while (condition);
will execute instructions first and then evaluates condition (and if it is true will start executing instructions again).
while (condition) { instructions }
will evaluate condition first and then execute instruction (if condition is true)
>>
>>58392892
you just do lines
>>
>>58392215
>single-expression lambdas
Not usually a problem, but:
>single-expression/statement lambdas
>in an imperative language
>>
>>58392938

I understand that it will continue to do the instructions if the number is greater than 24, but why does it still do the instructions if I type 23 or lower?

Is it just formatting?
>>
>>58392632
Done literally the same thing several times in several different languages.

Python was the best experience*.

*Actually, it was Julia, but I'm not going to suggest that to you.
>>
>>58393002
It shouldn't. Post whole code, please.
>>
>>58393092
>>58393092
>>58393092

New thread.
>>
>>58393069
ill post code in new thead give me a few
Thread posts: 322
Thread images: 35


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