[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: 325
Thread images: 37

File: 1449321833422.jpg (675KB, 940x822px) Image search: [Google]
1449321833422.jpg
675KB, 940x822px
What are you working on, /g/?

>>57727976
>>
File: snap104.png (185KB, 1069x597px) Image search: [Google]
snap104.png
185KB, 1069x597px
I'm learning Go.
But not the language, I have some self-respect.
>>
File: gold-medal.png (20KB, 246x242px) Image search: [Google]
gold-medal.png
20KB, 246x242px
>>57739303
For you my dear.
>>
Please don't use an anime picture next time.
>>
File: 9_EdFlyBebop2.png (318KB, 621x478px) Image search: [Google]
9_EdFlyBebop2.png
318KB, 621x478px
QUICK
claim your programming waifu before some faggot nodev kidnaps her
>>
>>57739367
>said on vietnamese cardboard forum
fuck you
>>
>>57739367

The Evangelion pics are a nice change desu.
>>
>>57739393
>Le olde pakistani cookie baking website argument
You fags had a different reaction before GR15. But I don't see why, after all it's just like your chinese cartoons.
>>
>>57739367
Kill yourself, fuck stain.
>>
>>57739440
like I said
>fuck you
>>
>>57739205
>What are you working on, /g/?
What a strange question to ask at the beginning of /dpt/ - General/Blog Thread
>>
File: 1451646065963.png (2MB, 1000x1000px) Image search: [Google]
1451646065963.png
2MB, 1000x1000px
Are you guys going to support our favorite comic writer?

https://store.xkcd.com

I just ordered one for Cyber Monday!
>>
>>57739514
There's literally nothing wrong with liking XKCD
>>
File: scrot.jpg (746KB, 1920x1080px) Image search: [Google]
scrot.jpg
746KB, 1920x1080px
post a screen shot of the last code you wrote
>>
>>57739205
Learning how to work in Android Studio. My engineering thesis is application for Android. Do any of you knows good tutorial for this shit? I have two weeks to make it and Google's tutorial is meh.
>>
>>57739445
Get raped and kill yourself, you retarded fucking faggot sack of nigger shit with down syndrome.
>>
>>57739514
not sure if false flag or desperate shill
>>
File: Screenshot - 281116 - 21:48:12.png (163KB, 483x682px) Image search: [Google]
Screenshot - 281116 - 21:48:12.png
163KB, 483x682px
>>57739638
what does the app need to do? tells us more

i heard this book is good
>>
>>57739671
You don't know what either of those two things are, do you?
>>
>>57739627
>the last code you wrote
I've been deleting someone else's code. Does that count?
>>
>>57739710
yes i do

if you're unironically an xkcd fanboy then kindly fuck off to reddit or the xkcd forum or someshit
>>
>>57739724
why?

is it inefficient or just shitty code?
>>
File: 1456199276098.png (31KB, 301x244px) Image search: [Google]
1456199276098.png
31KB, 301x244px
>>57739730
Sorry I disturbed your safe space >:^^))))
>>
>>57739696
It should allow to create events similar to Facebook's, but about cultural events. Photos, comments, integration with Google Maps and Google Calendar and logging system. Except that nothing more really. I need something that will introduce me easily into making GUI, show me how to use server with Android application and use these things I listed above.
>>
>>57739763
>unironically using a "4chan-esque" filename generator
you're literally randall and shilling your shitty site and merchandise, you should find something better to do
>>
I can't decide whether to create a new class or not.

I currently have a
>Slider class
>MapSetUp class

I could make the x and y scroll bars move the map in the Slider class, or i could make them move the map in the MapSetUp class

But I feel that it would make the Slider class a little messy, and I would have to update the class name of MapSetUp to MapMove, or something.

Or I could create a separate class that's solely for making the map move when the bars are scrolled.

What do? There is no clear way to do this.
>>
File: fuck you brah.png (2KB, 616x18px) Image search: [Google]
fuck you brah.png
2KB, 616x18px
>>57739833
>not having 4chanx
>not enabling randomized filenames
>not securing your file names so you don't tell other people when you made the screenshot
shiggy
>>
>>57739862
Or, I could take the camera logic out of the PlayScreen class, and put it in a class of its own, and have the scrolling logic in there, as I'm actually moving the camera, rather than the map. But I need the variables from all of the classes to achieve this.
>>
>tfw to smart too explain things to dumb people
>>
>>57739803
sounds an interesting project.

> integration with Google Maps and Google Calendar
i think this is just using the google maps and Calendar API

>logging system
this is the easiest

In android studio you can create the buttons of the application inside the IDE
>>
Is there some kind of C GUI library that works in mobile and pc alternatively C++ library that exports C api?
>>
>>57739763
You and your entire family tree deserve to be gassed.
>>
>>57739900
define the mobile OS and the pc OS
>>
>>57739914
linux, windows, android
>>
>want to be haxxor (ethical, not the cringe kind)
>have no idea how networks operate (I know of TCP/IP and HTTP, but don't know what they are
>have a basic understanding of operating systems but still don't know how they work in depth
>no idea where to begin in learning about networks and operating systems

Where do I start? I was suggested two books by Tanenbaum, but they seem very very intensive.
>>
File: B2FA9B5F.jpg (112KB, 582x703px) Image search: [Google]
B2FA9B5F.jpg
112KB, 582x703px
>>57739943
http://www.ee.ryerson.ca/~elf/hack/index.html
>>
>>57739943
here's a simple HTTP reference
https://www.jmarshall.com/easy/http/

for TCP and stuff similar to TCP google and stackoverflow are your friends

a more indepth idea of how it all works can come next if you feel like reading many IETF RFCs
>>
Can you ever go overboard with OOP?

I can't tell what I should do in my current situation.

I could create 2 more classes, or I could put my logic in a pre-existing class.

Either way it will all be similar readability and performance.

What do?
>>
>>57740063
I'll help you decide with the last two digits of my post
<50 you create 2 more classes
>=50 you put more logic
>>
>>57740095
Thanks anon
>>
File: 1480103193323.gif (4MB, 270x263px) Image search: [Google]
1480103193323.gif
4MB, 270x263px
>>57739943
>>want to be haxxor (ethical, not the cringe kind)
>>
>>57739943
>want to be haxxor (ethical, not the cringe kind)
Unless you're making money or doing something funny, it is all cringe.
>>
>>57740095
Doing it your way made me notice a bunch of inefficient code, this class is now orders or magnitude better.
You da best
>>
>muh data structures
>muh algorithms
>>
>>57740063
>Can you ever go overboard with OOP?
yes

>What do?
Do whatever is more readable and maintainable.
>>
>>57740155
*Even if you are making money or doing something "funny"
>>
>>57739739
>is it inefficient or just shitty code?
It's Java. I'm making the world a better place for unicorns and rainbows.
>>
>>57740245
Well I guess that since he used the word haxxor, just 4 words into his hacking career, he has already failed at not being cringy.
>>
>>57739739
>is it inefficient or just shitty code?

everything i write is inefficient AND shitty
>>
File: IMG_2818.jpg (18KB, 224x225px) Image search: [Google]
IMG_2818.jpg
18KB, 224x225px
What is your favorite thing for interacting with databases and why is it SQLite?
>>
Anybody know how I'd access a base class container like this:

class Derived : public std::vector<Base> {
//code here
}



I'm trying to display the objects in said container but I don't know how to approach it.
>>
>>57740354
Literally just call yourself, you're the vector.

for (auto&& e : *this) {
// Do something with each element
}
>>
>>57740354
Why the fuck are you inheriting from a standard container?
>>
>>57740452

Ikr? It's what the exercise called for though, so I need to find a way to work with it. I guess they call for it because it's technically a more concise way of handling a container of this particular class in this specific scenerio...?

>>57740412

God, thanks! Looks like I need to refresh my knowledge of how derived classe operate though, I don't comepletely understand why this statement works yet (just generally).
>>
>>57739205
>intermediate programming next semester
>syllabus not released yet, not sure what book this instructor will use (cant tell from past courses either)

Want to get ahead on learning C, I know most people say K&R, but I also hear about C99 and the book not including modern best practices when using C and programming in a secure way?

What otherway (or specific book) would you guys recommend for C?
>>
Is there any language that enforces purity, but doesn't rape you with its type system?
>>
>>57739205
Hey /dpt/

any suggestions on how I should name each leaf/entry from this structure?

Adding Nov-Date-Year seems redundant

what do you suggest?

Entries/
└── 2016
└── November
├── Entry-Nov-08-16-1917.txt
├── Entry-Nov-09-16-0800.txt
├── Entry-Nov-09-16-2123.txt
├── Entry-Nov-10-16-1208.txt
├── Entry-Nov-11-16-2153.txt
├── Entry-Nov-12-16-0831.txt
├── Entry-Nov-13-16-1816.txt
├── Entry-Nov-13-16-2312.txt
├── Entry-Nov-21-16-1209.txt
├── Entry-Nov-21-16-2109.txt
├── Entry-Nov-23-16-0030.txt
├── Entry-Nov-23-16-1252.txt
├── Entry-Nov-25-16-1433.txt
├── Entry-Nov-25-16-1650.txt
├── Entry-Nov-25-16-1851.txt
├── Entry-Nov-25-16-1928.txt
├── Entry-Nov-25-16-2013.txt
├── Entry-Nov-25-16-2036.txt
├── Entry-Nov-25-16-2129.txt
├── Entry-Nov-25-16-2149.txt
├── Entry-Nov-26-16-0803.txt
├── Entry-Nov-26-16-0845.txt
├── Entry-Nov-26-16-1829.txt
├── Entry-Nov-26-16-1839.txt
├── Entry-Nov-26-16-1842.txt
├── Entry-Nov-27-16-0700.txt
├── Entry-Nov-27-16-0901.txt
├── Entry-Nov-27-16-0948.txt
├── Entry-Nov-27-16-2017.txt
├── Entry-Nov-27-16-2022.txt
├── Entry-Nov-28-16-0418.txt
├── Entry-Nov-28-16-1655.txt
├── Entry-Nov-28-16-1744.txt
└── Entry-Nov-28-16-1802.txt
>>
>>57740917
Just name them with the date of the month?
>>
File: SOS.png (201KB, 1486x1399px) Image search: [Google]
SOS.png
201KB, 1486x1399px
I am back with more problems. when I run the program it prints m as being 15 and never changing, do you guys have any ideas?
>>
>>57740940
So.. Entry-date-HH-MM.txt
>>
>>57740947
>i+6
>>
>>57740947
And I told you to get a better color scheme
>>
>>57740063
The answer is yes but it depends.

If the functionality that you're adding is related to an existing class then add logic to whatever class is most appropriate. If it's unrelated to an existing class and the functionally you're adding would benefit from being a class then make more classes.

Something like that, I'm not sure if I'm explaining it well or if I'm missing something
>>
>>57740914
Pick one. You'll get used to it.
>>
>>57740852
>I also hear about C99
You can pick up on most C99/C11 features pretty quickly by just reading the wikipedia articles and maybe a few blog posts.
The only thing that K&R does that isn't "allowed" in later standards (but most compilers will still accept with warnings) is implicit int.
They will do things like main()
but just slap 'int' on the front and it's conforming:
int main()

>modern best practices
I'm not really sure what you mean by this. I don't believe there is any code is K&R that is broken, unless there is an example which uses gets().
>programming in a secure way
It depends how 'secure' you want.
Program should run correctly with any reasonable input?
100% certain that it will work and lives are at risk?
The way you would write for both of those are quite different.
>>
>>57740914
Haskell
>>
>>57740947
also are you calling less_than_10_blah with the games[N_OF_GAMES] element and not the actual array? (should be the actual array)

>>57740844
sounds neat
I want more details on what you're tagging

>>57740917
it's worth mentioning the 2016-12-31 date format
and do you need to sort everything into seperate month or year folders?
>>
>>57740947
>day, month and year are different variables
I strongly believe you could pack them in one variable
>>
>>57740965
Yea i forgot to insert the = it works now, thank you.
>>
>>57740947

that for loop is disgusting.
>>
>>57741160
nobody starts out perfect
>>
>>57741065
I'm thinking for long-term organization.

The year/month/entry-date schema allows me go through entries without relying on a script to organize/sort entries and its human-readable too.
>>
>>57741027
I can't pick one if I don't see one.
>>57741040
Meh. I know that Haskell is good, but it is also alien and hard.
What I want is basically JS with optional types, promoted immutability and enforced purity. JS+Flow provides a decent type system, but misses two other requirements. Haskell/PureScript are not approachable for newcomers, thus they are not perfect for collaboration.
>>
>>57741160
Which of them lol, how are they disgusting how would you write them?
>>57741070
Wouldn't I have to save it as a string instead then, right now they are 3 ints. Later on in the assignment I have to retrieve the scores in a certain year, while both day and month aren't really needed.
>>
>>57741188
I mean you get to pick one of "enforces purity" and "doesn't rape you".
>>
>>57741031
Secure as in, not easily exploited in real world applications, I think. Again, I don't know C, so I'll just remember you menioning implicit int, and gets().

So you think K&R is totally a good way to learn C? Definitely the first go to book?
>>
>>57740947
>int *number_of_rounds_with_less_than_ten_goals
Jesus christ, you don't need to use an entire sentence for a variable name.
>>
>>57741215
it's translated danish
>>
>>57741188
Haskell infers almost any regular code, you won't need to write types 99% of the time
>>
>>57741215
I'm gonna change them when I am done, it's so I remember wtf I am doing, I am to lazy to write comments, but I guess I might aswell when my variables are entire sentences.
>>57741226
You don't have to defend me dude, he is absolutely correct.
>>
>>57741207
Baww. Why can we have optional types, but can't have other functional features without BDSM-tier typechecker? ;_;
>>57741241
I know it. I know Haskell and PS. That doesn't make them easy languages. They are often counter-intuitive unless you've spent a couple of years using them.
>>
>>57741291
What's the difficulty?
>>
>>57741208
>Secure as in, not easily exploited in real world applications
Worry about that after you get a bit better with the language, but programming in C well amounts to:
- Handling pointers well
- Handling allocations properly
- Handling null-terminated strings properly
- Checking inputs
>So you think K&R is totally a good way to learn C?
Yes, it's still a very good book. There are quite a few quality of life features added in C99 that K&R won't cover, but again, it's something you can pick up on really quickly.
>Definitely the first go to book?
For someone with some experience with programming, probably yes.
For someone completely new to programming, no. K&R doesn't cover programming fundamentals, just C itself.

Other books I've heard good things about (but haven't read myself) are:
- C Programming: A Modern Approach
- C Primer Plus
>>
>>57741065
>I want more details on what you're tagging

So I started keeping a journal of flat text files to document my day and progress. After about 5 entries, I got the autistic need to have some organization. The journal text files are stored in an crypt disk, so there's no munging of the actual text files themselves.

The first line of txt file can include a tags: line with a comma separated tags. It helps categorize the entries in a sea of entries.

I created four scripts to manage to create, browse, read, and sort entries, if you care.

Just change ENTRIES_LOC to a specified folder that holds your journal entries, preferably in an encrypted disk.

new_entry
#! /bin/bash

ENTRIES_LOC="/media/secrets/journal/Entries"
YrMo="$( date +%Y)/$( date +%B )"
mkdir -p $ENTRIES_LOC/$YrMo
file=$(date +"Entry-%d-%H%M.txt")
vim $ENTRIES_LOC/$YrMo/$file


browse_entries (requires noice or ranger)
#! /bin/bash

ENTRIES_LOC="/media/secrets/journal/Entries"
noice $ENTRIES_LOC


read_entries
#! /bin/bash

ENTRIES_LOC="/media/secrets/journal/Entries"
tmpf="tmpcat.txt"
touch $tmpf
shopt -s globstar

# Specify -r to start from the first entry
if [[ -n "$1" && "$1" == "-r" ]]; then
command=`ls $ENTRIES_LOC/**/*.txt`
else
command=`ls -r $ENTRIES_LOC/**/*.txt`
fi


for i in $command; do
#for i in `ls -r $ENTRIES_LOC/**/*.txt`; do
echo -e "\n" >> $tmpf
echo -e '\E[37;44m'"\033[1mOn $(date -r $i +%c):\033[0m" >> $tmpf
# no color
#echo "On $(date -r $i +%c):" >> $tmpf
echo -e "\n" >> $tmpf
cat $i >> $tmpf
done

less -R $tmpf

rm $tmpf


sort_entries (python, too long) lets me classify entries based on tags.
>>
>>57741320
thanks sir
>>
Best editor?
>>
>>57741316
The main difficulty is:
When someone sees JS, Java or even OCaml, he can just write the code. All hee needs is an editor and documentation. Attracting contributors/hiring developers is trivial.
When someone sees Haskell/PS, he can not just open a file and write a function. He first needs to understand what does "do" mean and how it is desugared. Then he has to learn typeclass hierarchy, monad laws, cryptic operators etc.
20 years of "avoiding success at all costs" clearly shows that Haskell is not really good for most of the people.
>>
>>57741431
>>
>>57741431
ed
>>
>>57741431
The one you like.
If you have no preferences, jump the Atom bandwagon.
>>
>>57741431
Atom with Google Analytics integrated
>>
>>57741320
I had a trouble with K&R's exercises and really liked K.N. King's C Programming: A Modern Approach. Great textbook IMO.
>>
>>57741440
yep, this is the problem with meme langugaes in general. It's all well and good until you need to hire someone to work on your code base, and fuck all people know the langugae except neckbeards who can demand high salaries.
>>
>>57741440
This isn't true at all.
Do does exactly what's intuitive

x <- getLine
print x
>>
>>57741328
>>57741065

if you care,
here's my python sort_entries which lets you read entries with the specified tags

http://pastebin.com/iytb47jp

use it like
sort_entries -l # list all tags
sort_entries -t love, life, dream -r # list an entry with the specified tags and show the latest one first


its hacky, but its a personal journal app that I don't expect anyone to see (until now)
>>
>>57740412

Fuck, got it to work mostly because of this. Fucking love you so much right now anon
>>
>>57741557
You're welcome, happy to help.
>>
>>57741495
>in general
Nah, in general it's not a big trouble. Even if you're working with some rare and weird dialect of good old Algol/C/Pascal/Java/Basic/whatever else, then there is no real problem. Any decent programmer can learn new syntax and function names.
The problem arises when you're using something _alien_. That's why I want to avoid Haskell. But it taught me how useful controlled side-effects are, so I want to keep the good stuff ;_;

>>57741497
Yeah, yeah, it's all intuitive on the kindergarten level. Just like math, where apple + apple is two apples. But eventually you face differential equations and other trivial stuff that scares normal people.
Can you teach a person what's the purpose of <*>, <|>, concatMap, bind, pure and all the other stuff that's required for trivial applications within one day? I really doubt it.
>>
>>57741651
>required for trivial applications
nope
you can just avoid other monads if you really care
>>
>>57741651
>The problem arises when you're using something _alien_.
Every langugae has something weird. Even a Java programmer learning C# will take a long time getting used to the conventions of C# and learning what patterns that are good in Java are poor in C#.

It's easy to start writing pajeet their code in a new langugae by literally just learning the syntax, but learning how to write good code in the that langugae takes quite awhile.

Go is a really good example of this.
>>
>>57741677
Keep everything within IO, right?
>>
>>57741651
Out of those 5 functions you listed, only one is concrete (concatMap). The others are just names for abstract operations that you know will work for any applicative/monad/whatever. It's pretty easy to explain how they work for a particular instance, I mean concatMap is just join for list.

This also has fuck all to do with the type system, which leads me to believe you're just talking out your ass and not as an experienced Haskell programmer playing devil's advocate. I bet you've barely even tried to learn it.
>>
>>57741711
What?
I'm just saying that if you don't want to use other stuff, you don't need to
>>
College shit edition


How would I curry this function? For that matter do all functions need to strictly only take one input? In this case I need to take two inputs. Should I bother currying or just do it as he's outlined?
>>
>>57739205
>eva
Pseudo-profound shit taste desu
>>
>>57741885
You have gen take one parameter and return a closure that takes the second parameter and does the work.
>>
Wrote a cutesy script for my laptop that can't encode music in mp4 properly

would take it further to actually download or sort the files automatically but that's more work than I'm willing to put into this. Although come to think of it a web plugin would be helpful too so you can just click on it

import os
import clipboard

while(True):
raw_input("Begin?")
try:
if "youtube.com" in str(clipboard.paste()):
os.startfile("http://www.youtubeinmp3.com/download/?video=" + str(clipboard.paste()))
print("Succeeded!")
else:
print("Not a Youtube Link")
except:
print("Failed")

raw_input()
>>
File: ElmLogo.png (13KB, 720x290px) Image search: [Google]
ElmLogo.png
13KB, 720x290px
Writing some basic stuff in Elm like a calculator app. I'm really impressed by how well functional programming works for GUI's. It captures the MVC pattern really really well, much better than OOP with mutable state does.
>>
>>57741896
Eva is awesome. Eat shit
>>
hello, new to python here and trying to get a function to execute itself several times with a bunch of urls I got in a list. does this make any sense?

if allinks != []
for i in allinks
downzip(i = url)


the function downzip has a variable called url, and I want it to be each element of the list. is this the right way to do it or am I missing something??
>>
>>57741973
Elaborate? I don't see how functional does better for MVC
>>
Oh god damn it. My emacs froze, and the memory footprint is going up, it's at 2 GB right now. It's clearly leaking memory.

How did I mess up my ELISP program so bad /g/?
>>
>>57741960
check out youtube-dl to download videos/audio from youtube and many many other video/audio hosting services

wrap a call to in python and you're fine

there might also be a python API for it
>>
>MVC
do the needful
>>
>>57742004
https://www.tutorialspoint.com/python/python_functions.htm
Scroll down to named arguments.
Your line
downzip(i=url) 

Is wrong. You should swap url and i
>>
>>57742038
thanks, once I fix that it should work as intended right?
>>
>>57742055
I don't know python enough to say that (I probably know less than you) but yeah it looks like it.
>>
>>57741885
use haskell
>>
File: 4chan_scrot.png (284KB, 1920x1080px) Image search: [Google]
4chan_scrot.png
284KB, 1920x1080px
>>57739627
I'm farming all of the data from the pizzagate/EWO threads on /pol/ and searching them for leads
>>
>>57742113
pizzagate isn't real my man.
>>
>>57742118
yeah I thought that until I read those weird ass emails
>>
>>57741885
I don't know python but this is C# or java or something

x => y => gen(x,y)
>>
>>57742149
The emails are just that. Weird.
>>
>>57742014
thanks that's helpful
>>
>>57741431
GNU Emacs
>>
>>57742118
I don't know a single person who can convince me it isn't real, and since making a farmer is pretty easy, I figured it is worth my time
>>
>>57742009
Basically, you define your own type for the model and your own type for all actions that the user can make.

Then you write a pure function called update which takes one message and one model argument, and returns a new model. Similarly, you can write your view as a pure function which takes the model and generates a viewable object which can eventually be translated into HTML components and the like by your runtime.

Any buttons or other GUI components you make send the runtime a message (of the type you defined), and the runtime calls your update function with that message and the old model as arguments to update the view.

The end result is that your entire program consists only of pure functions that can easily be refactored and/or be put together like tinker toys. It is completely declarative. The main loop and all the actual wiring is handled by that one higher order function in the library which finally generates the UI for you. The functional analog of the MVC pattern turns the modularity aspect up to eleven.

The other nice thing is the strength of the type system and the ridiculously useful compiler error messages. The compiler will basically redline the things that are wrong and tell you what you should do to fix the logic errors in your program, in plain English. Thanks to the fact that edge cases in the standard library are tagged with Maybe or Either, the compiler can detect all edge cases in your program for you at compile time eliminating the need for runtime exceptions.
>>
>>57742164

That's not an argument.
>>
int independence; // declaration of independence
>>
>>57742339
>int dependence;
>>
>>57742339
You just copypasted that from reddlt, didn't you?
>>
>>57742339
saw this on reddit too
>>
>>57742339
you forgot to initialise it
int independence = 0;
>>
>>57742345
>>57742339
>>57742348
Fuck off. We don't need cross posts if that were the case.
We're perfectly fine without sourcing content from others.

Let our small self-sustainable programming general be!
>>
>>57742359
int independence = 1776;
>>
>>57742366
Stealing content from another site should be a b&able offense before all the newfriends turn the site into 9fag
>>
>>57742390
>>57742366
I can smell newfaggotry

it's pretty putrid
>>
>>57742390
Sadly we can't catch the cases we want to catch with that rule. As we have search engines you can easily find your claim on other pages for instance.
>>
int 
main
(int,char**)
{return 2016;}

>this is valid C
>>
File: Soon on 4chan.png (28KB, 757x170px) Image search: [Google]
Soon on 4chan.png
28KB, 757x170px
>>57742413
Why don't you fuck off back to wherever you crawled from?
>>
>>57742425
>this should be invalid C
>>
>>57742379
immutable uint independence = 1776;
>>
>>57742470
That's not how you spell
constexpr static auto independence = 2016-240;
>>
>>57741935

Well Scala crapped out on me and IntelliJ crashed so I might just do this in Lisp or Haskell desu but I'm guessing it should be;

def frac(x: Double): Double = x


def gen(f: Double => Double, int n)


 // Thus
gen(frac(0.3), 70000)


Scala is such a nightmare christ
>>
>>57742497
Why not const?
>>
>>57742538
Not at all.
def gen(f: Double): Int => Int = (x: Int) => { }
>>
>>57742565
const doesn't mean immutable. If you see a const variable, it might really just be a readonly view of a mutable object for example.

constexpr means compile-time constant.
>>
>>57742497
That's not how you spell
int const independence = YEAR_OF_OUR_LORD + 1776;
>>
>>57742497
enum independence = 1776;
>>
>>57742616
class independence { operator int() {return 1776;} };
>>
So I've decided to make some malware in python (for educational purposes, not for shithead reasons) here's what I plan on doing, feel free to add to the list
>ransomware (encrypts documents, pictures, downloads, desktop and sends the decryption key to me)
>botnet
>keylogger
>File wiper (deletes files randomly and runs at startup)
>adware
>script to download and execute other scripts
as I said before if you think of anything I could add please tell me

the problem is before even writing any code I've thought of a few problems
1) if I make the ransomware email me the randomly generated key whats to stop the user opening it with notepad, seeing the email credentials, logging in and looking in the sentbox for the key? the only thing I could think of doing is compiling the python file into an exe
2) if I rent 12 VPSs and have one as a CNC server, 10 as zombies and one as the target - would this get me in trouble? I mean I'm renting the hardware so I should be able to do this right? also would 10 zombies be enough to take down 1 VPS or 1 home connection (got a friend who would be willing)
>>
>>57742654
>sends to me
Don't do that.
Have it stored encrypted under a public private encryption scheme where you hold the private key. No transfer needed. You're completely safe until you decide to be nice and give them their files back.
>>
>>57742654
encrypt the email
and use your own mailserver
>>
>>57742689
>I want the feds on my tail because it's exciting
Not for everyone but ok I guess.
>>
>>57742672
you see I considered that but I'd imagine it'd be super difficult for a beginner, or would it be the type of thing that's worth the challenge
>>
>>57742654
Make it spam pictures of bunnies on folders at an alarming rate, note: each bunny is a retarded large filesize.
>>
>>57742654
>ransomware (encrypts documents, pictures, downloads, desktop and sends the decryption key to me)
>adware
>file wiper

That's the definition of being a shithead. If you're going to write a bot make it do something fun, not just destroying shit for the pleasure of ruining people's lives.

As a programmer you have a responsability to not abuse your "magical powers".

>1) if I make the ransomware email me the randomly generated key
That's retarded. If you're going to do that then just have the C&C generate a keypair and your bot downloads the public key.

>if I rent 12 VPSs and have one as a CNC server, 10 as zombies and one as the target - would this get me in trouble?
If you're stupid enough to rent a C&C in your name and you run a ransomware on it, I will personally do my best to get your piece of shit ass v&
>>
>>57742704
added bunny spammer to my list of things to make
>>57742710
I think you misunderstood I don't plan on spreading any of the malware or using it against people, I just want to make them for fun and hopefully to learn a thing or two the only things they'll be used on is VPSs I rent which will then be wiped after I'm done with them, I wouldn't have thought this is still illegal or even morally wrong
>>
>>57742654
Encrypt everything in rot26
>>
>>57742756
good thinking, they'll never crack it
>>
>>57742702
>super difficult
No its not. It's literally that you offline generate a public private key pair. Put the public key in your software. Write the private key on a note.
It's just a layer on top of your normal system. But instead of having the flaw you mentioned where you have to send the key. You just encrypt it with the public key. Since you hold the private key you can just send that and it works.

The core problem here is that you need a large number of pairs generated where when they send you the ransom they pass you some identifying information that lets you know which key to send.
So for instance you can have the software check the date. Every week is a new key.

Maybe you don't get public private encryption schemes. If you do you'd find it a natural solution I think. Look it up. Its the best way I can sell you on the idea.
>>
>>57742750
> I don't plan on spreading any of the malware or using it against people
Then why do you care about the user opening it in notepad? The only user is you.
> if I make the ransomware email me the randomly generated key whats to stop the user opening it with notepad, seeing the email credentials, logging in and looking in the sentbox for the key? the only thing I could think of doing is compiling the python file into an exe
>>
>>57742580

So you're defining a function that takes a double which returns a function that equals an anonymous function that takes argument x as an int and returns the result of a code block?
>>
>>57742780
Currying is taking a function (A, B) => C and turning it into A => (B => C) so yes.
>>
>>57742766
I'm starting to grasp it, I'll read up seems like the best option
>>57742767
I get how that sounds suspicious - I just want to make it to the best of my ability if that makes sense
>>
>>57742750
>I think you misunderstood I don't plan on spreading any of the malware or using it against people
Then I'm just going to ask that you're extremely careful nobody gets their hand on the source.

>I just want to make them for fun and hopefully to learn a thing or two
Yeah but there's not much to learn by making a ransomware specifically. The hard part is infecting computers, the encryption part is actually pretty easy and something you can learn without doing malware (though somehow almost every malware writer always fucks up their encryption completely...).

>the only things they'll be used on is VPSs I rent which will then be wiped after I'm done with them, I wouldn't have thought this is still illegal or even morally wrong
It's only morally wrong to me if you accidentally lose the source.
Just note that this is probably against the VPS's terms of service even if just testing.
>>
>>57742789

Will something calling function A be able to specify B though?
>>
>>57742780
haskell:

curry :: ((a,b) -> c) -> (a -> b -> c)
uncurry :: (a -> b -> c) -> ((a,b) -> c)

--uncurry f = \(x,y) -> f x y
uncurry f (x, y) = f x y

curry f x y = f x y
curry f = \x y -> f x y
curry f = \x -> \y -> f x y
>>
>>57742766
>The core problem here is that you need a large number of pairs generated where when they send you the ransom they pass you some identifying information that lets you know which key to send.
>So for instance you can have the software check the date. Every week is a new key.
What the fuck, no. That's braindead.

Just generate a keypair per client, give the public key to the client, and when paying the ransom find the private key that corresponds to whatever public key the client holds...
>>
>>57742805
You asked for currying.
>>
>>57742805
You have to. When you call the function on A, it returns a second function which expects B as an argument.
>>
>>57742800
>Then I'm just going to ask that you're extremely careful nobody gets their hand on the source.
yeah even though my code will be shit I'll be very careful with it
>Yeah but there's not much to learn by making a ransomware specifically. The hard part is infecting computers, the encryption part is actually pretty easy and something you can learn without doing malware (though somehow almost every malware writer always fucks up their encryption completely...).
I guess instead of ransomware I could make something that auto encrypts or decrypts certain files/folders using config files
>Just note that this is probably against the VPS's terms of service even if just testing.
I'll email a few VPSs asking them before I do anything, thanks
>>
File: aaa.png (266KB, 765x1045px) Image search: [Google]
aaa.png
266KB, 765x1045px
ELI5: What is the difference between functional and non-functional programming?
>>
File: xkcd.png (44KB, 740x633px) Image search: [Google]
xkcd.png
44KB, 740x633px
>>57739514
>xkcd
>>
>>57742832
>ELI5
What?
>>
>>57742805
>>57742820
Oh, nevermind, I misread. Yes, you could call it like this gen(x)(y) instead of gen(x, y). gen(x) itself returns a function that when given y will finish the computation.
>>
>>57742832
Functional programming is pure like my waifu
Non-functional programming is 3dpd
>>
>>57742823
>I guess instead of ransomware I could make something that auto encrypts or decrypts certain files/folders using config files
You could make a secure backup software for example that encrypt everything securely, or something like Truecrypt.
>>
>>57742846
good thinking thanks
>>
>>57742832
Functional Programming is the 2d to Non-functional's 3d
>>
File: 1478926194663.jpg (442KB, 1000x750px) Image search: [Google]
1478926194663.jpg
442KB, 1000x750px
>guy in my group project couldn't figure out how to use the class i've been working on for a month
>instead of asking me, he deleted it, copy and pasted large chunks of the code, and then reuploaded it to github (by file upload)
>>
>>57742819
We're ensuring no identifying communication happens between the client and us until the ransom is paid. If you want you could just have them make a /b/ post with an encrypted message which you snag. That way they don't even need an address to you.

Sure you could have them send the public key. But the reason that's dumb is because it exposes implementation details to the client. And the drawback of having a timed system is small.
>>
>>57742832
Functional programming is, loosely, when you think about programs or parts of programs as transformations of state which are reified and can be passed around and such. Non-functional programming is not doing that.
>>
>>57742857
>>57742845
So, functional programming is beautiful but ultimately only admired by autists and not uselful anywhere in the real world. It's an apt metaphor.
>>
>>57742832
Functional means you have functions which you pass variables to. Like you would in math. Clearly defined inputs and outputs.
Imperative programming means a function can change things other than what's passed to it. Like global variables and such.
>>
File: 1469932878160.jpg (37KB, 263x395px) Image search: [Google]
1469932878160.jpg
37KB, 263x395px
is their any language that is as fast and powerful as Crystal but doesn't look as ugly?
>>
>>57742866
Seems entirely appropriate.

Clearly a bad api if you can't even figure it out for a small group project.
Also even worse you used the word class here.
Meaning it's likely just awful OOP.

Give your buddy a pat on the back from me for making the world a better place.
>>
>>57742891
Fuck the RealWorld
>>
>>57742874
>We're ensuring no identifying communication happens between the client and us until the ransom is paid.
I don't see the point, either way you need to have a safe communication channel because the code that contacts the C&C will be in your binary anyways, so reverse engineers will find out.

>Sure you could have them send the public key. But the reason that's dumb is because it exposes implementation details to the client.
On the contrary! If you generate the public key client side, then you expose part of the implementation and it's likely that people will be able to derive the algorithm that generates the private keys from it.

All the key generation must be done securely and non-deteministically server-side, and the results is a black box handed out to the client.

>And the drawback of having a timed system is small.
It means only one person needs to pay per time interval, the others can share the key...
>>
How should I go about learning to program microcontrollers/processors and what are some good kits that I could use to practice with? I have no real programming experience to speak of.
>>
>>57742960
Learn the C programming language, just pick up a tutorial or a book for beginners and start learning.

C runs on any hardware, especially small microcontrollers and exotic chips?
>>
File: blond.png (139KB, 302x297px) Image search: [Google]
blond.png
139KB, 302x297px
>>57742821
Okay cool, thank you! Sorry I'm just new to Scala and the syntax for defining functions/procedures as arguments is a bit strange.
>>
>>57742986
>defining functions/procedures as arguments
That's not what you're doing. Currying is turning a two-argument function into a one-argument function that returns a one-argument function.
>>
Functional programming just means there are no side effects? And imperative programming means there are side effects?

I-Is this right?
>>
>>57743019
There's more to it than that.

Pure functional doesn't even have variables, everything's a function.
Pure imperative doesn't allow manipulating functions as first class objects, just calling them to work on variables.
>>
File: 1459926416792.jpg (25KB, 263x263px) Image search: [Google]
1459926416792.jpg
25KB, 263x263px
>>57743019
AHAHA, NO, BAKA
>>
>>57743019
Not at all. Pure programming is when you have no observable side effects, functional programming is >>57742884. When you do both you get pure functional programming.
>>
>>57742980
Yeah I'm learning C at the moment and have first year experience with assembly.
My main problem though is that I lack the knowledge of what I should/can learn.
I can manipulate arrays, implement loops, basic i/o, etc in c/assembly but that's it.
Where do I go beyond this?
>>
>>57742833

Randall Munroe was a big fat mistake.
>>
>>57742940
>on the contrary
What.
I'm saying we don't generate per client. If we do it per client I don't see how we can do it on the server side. Please enlighten me on this.
>time interval
As I said, small drawback. It can be a very small time interval. If your software will be such a plauge it has a problem with a small time interval you're in deep shit if you don't have a system that allows you to have no contact if you so choose.
>the code that contacts the C&C
We shouldn't have a C&C is the point. Ideally we even destroy the parts of the binary we sent to encrypt so only the actual algorithm for decryption (and whatever UI the user needs) remains. And potentially tons of waste code to make the reverse engineering process harder.
>>
>>57743104
That's about it. Get comfortable with pointers and recurrence, and you can call yourself an average C programmer.

Then the rest just comes with experience, do some real projects.
>>
File: dd.png (899KB, 1600x901px) Image search: [Google]
dd.png
899KB, 1600x901px
>>57743036
>>57743042
>>57743065
I think i'll just not care about the paradigm I'm using from now on.

If the code works it doesn't really matter.
>>
>Need to use CSVs in an assignment involving Java
>Just reading the data into memory requires heap size to be raised from 2 GB to 3 GB
>Memory stays at 3 GB after the functions execute
>Despite the CSVs only being about a hundred megs
>Let's see if I can fix this...
>System.gc()
>Memory usage drops to 404 MB instantaneously after the functions involving apache CSV library are used

MUUUUUCH better.
>>
>>57743036
>imperative doesn't allow manipulating functions as first class objects.
Really now? Sure it's uncommon for languages that aren't functional to have those features but imperative doesn't say anything against it.
>>
File: 1467623015348.gif (550KB, 728x720px) Image search: [Google]
1467623015348.gif
550KB, 728x720px
>>57743127
have you tried haskell senpai
>>
>>57743142
That sounds awful.
>>
File: koo.png (191KB, 1920x1040px) Image search: [Google]
koo.png
191KB, 1920x1040px
>>57739205
I made a simple 4chan viewer.

http://korbo.ga/{board}/thread/{thread}
i.e. http://korbo.ga/a/thread/150311285

(Doesn't work well on big threads)
>>
File: FUCK DPT IS DUMB BRO WTFLMAO.png (76KB, 660x680px) Image search: [Google]
FUCK DPT IS DUMB BRO WTFLMAO.png
76KB, 660x680px
>>57743110
black women was a big fat mistake

>>57743142
>apache
sounds bad
>>
>>57743142

I dealt with the same issue, but we were using huge unsorted files, so it's not like analysis could be applied piece-wise.

The solution was to run the program on a system with enough memory. :^)
>>
>>57743180
>black women was a big fat mistake

They might be big and fat, but they're definitely not a mistake.
>>
>>57743122
>I'm saying we don't generate per client. If we do it per client I don't see how we can do it on the server side. Please enlighten me on this.
Sure. Whenever a new implant goes live on a client, it requests a new public key (PK) from the server.
The server generates a random keypair that it saves in a database, and hands the PK to the client.

It's all very simple, really.

>As I said, small drawback. It can be a very small time interval. If your software will be such a plauge it has a problem with a small time interval you're in deep shit if you don't have a system that allows you to have no contact if you so choose.
I'm sure it could be made to work, but this is just very bad design. You run the risk of people figuring out how you generate the private keys if you're not extremely careful with your implementation.

>We shouldn't have a C&C is the point. Ideally we even destroy the parts of the binary we sent to encrypt so only the actual algorithm for decryption (and whatever UI the user needs) remains. And potentially tons of waste code to make the reverse engineering process harder.
You're not making any sense, anon.
I'm thoroughly convinced that you have no idea what you're talking about, but I guess I'm happy to discuss it if you want help.

Please note that if you don't want the client to be able to decrypt files by itself, you *NEED* to have a C&C, you need to have a database that stores the private keys and a communication channel to send it to the client after the random is paid.
This is fundamentally unavoidable, otherwise your design can not be sound.
>>
>>57743177
doesn't work?
that's the only thread it shows
>>
>>57743127
I agree, there's no real reason to do anything but that. Talking about paradigms and patterns and whatnot is only really relevant for analyzing code that has already been written.
>>
>>57743019
Yes, you are basically correct. Functional languages can perform side effects, but that's usually limited to I/O and programs written in functional languages usually only use a small amount of it in one place. Imperative programs encourage expressing logic with side effects, like changing the state in an object or using a loop to modify a variable in an outer scope.

>>57743036
No. Haskell is functional, but it doesn't represent numbers with church numerals. Functional programming doesn't mean everything is functions.

>Pure imperative doesn't allow manipulating functions as first class objects, just calling them to work on variables.
There's no such thing as pure imperative programming. This terminology is about as silly as "scripting languages" and "programming languages".

>>57743065
There's no such thing as pure programming. This terminology is about as silly as "scripting languages" and "programming languages".
>>
>>57743198
>analysis couldn't be run piecewise
So it couldn't be run at all?
>>
>>57739600
>There's literally nothing wrong with liking XKCD
How about the part where you think references are humor?
>>
>>57742701
yea he sould use private-pub key encryption
>>
>>57743226
Oh right, I fixed it
>>
>>57743252
ITT: Throwing big boy words around without a clue what they mean
>>
>>57743232
>I take categorization of code very seriously
>>
>>57743225
>requests from server
Ok so we're caught at the first sentence.
Anon I'm sorry I don't have time to read but I think there may be a misunderstanding.
>>
File: 1475143072125.jpg (15KB, 448x283px) Image search: [Google]
1475143072125.jpg
15KB, 448x283px
>>57743257
very nice anon
>>
>>57743252
I'm sick of you south Americans coming here and acting all high and mighty.
>>
>>57743269
>I think there may be a misunderstanding.
Yes, there is! You seem to think you can avoid having a server, but that's impossible.

Somehow, all malware writers almost always write terrible broken crypto. I don't know why they never learn.
>>
>>57743265
At least I don't give shitty explanations.
>>
>>57743265
>being as loose about categories as your mom
>>
>>57743289
How is it a shitty explanation? Purity is one thing, functional is another. Just because nobody says "pure programming" by itself (because only people who program functionally care about purity) doesn't change that.
>>
>>57743284
The Chinese government has been secretly kidnapping programmers from all over the world and tortures them if they don't program malware. Broken crypto is how the programmers get back at their kidnappers.
>>
>>57743277
Thanks, the physics barely handles threads with more than ~60 posts so I dont think its usable as is.

Still fun though
>>
>>57743324
People say "functional programming" because functions have referential transparency. They're mappings between one set and another set. Functional implies no side effects. When people call a language, like Haskell, "purely functional", what they mean is that the entire language is functional. There's no taint. That's what pure means.
>>
>>57743000
Sorry I meant defining them as returns.
The
Int => Int = (x: Int)


That took a while to process just because I would've thought Int => Int would be enough to specify the return type, but obviously you have to specify the argument for the second function too.
>>
>>57743245

You know what I meant, you penis-head. No analysis could be done on subsets of the data set because it first had to be parsed, and then sorted. This required having the full data set available.
>>
File: feels_great1.jpg (29KB, 500x435px) Image search: [Google]
feels_great1.jpg
29KB, 500x435px
>>57743269
>oh no my computer's been ransom ware!!
>*put in live CD*
>*run 'strings'*
>oh noes, it's encrypted!
>oh, there's the key
>*unencrypts*
>*run 'strings'*
>problamo solved :^)
>>
>>57743352
What if the set (type) includes side effects?
>>
>>57743166

Yeah. When the class was starting, we had a choice of C, C++, Java, and Python to do our assignments. Whatever the class voted on, everyone had to use. I voted for C++, but apparently, Java won over.

>>57743198

I have enough memory. The problem is that I would like to not be having 2.6 GB of memory sitting around allocated but unused. Particularly for an extended period of time.
>>
>>57743378
>he doesn't know how to do a file based mergesort
>>
>>57743396
Please be more specific.
>>
>>57743418

It's not that simple. I wish I could provide more details, but I am legally bound from doing so.
>>
>>57743352
>>57743396
Or if you model I/O as a function from the world to a modified world? You're not actually specifying a mapping, that's just the type. Internally you're doing side effects.

It's still pure though, if the world is linear, because you're never breaking the rule that same inputs => same outputs.
>>
Migrated my group of friends I code with over to slack, enjoying it so far - liking the idea bot useful for making a backlist of projects. anyone here use it? what are your opinions? what are some bots or plugins I should get?
>>
>>57743396
>>57743433
Then we can lie and call the language "purely functional" anyway, since it's as pure as possible.
>>
>>57743396
Do you mean if you're describing side effects and building up an abstract computation?
>>
>>57743428
Scratch that, it would be more like returning a computation (i.e. what Haskell does) than running it. Like what >>57743481 said.

>>57743454
But now you don't have referential transparency and yet you maintain purity.
>>
>>57743384
But he said you only had the public key as the client. All the keys were generated offline and the clients (presumably) get all the public keys. Program picks which one to use based on date.
The other guy said you generated per client by contacting a server.
And in fact the guy only said you'd use the private public scheme for encrypting the decryption key that's for what's been encrypted on the drive.

So you don't have any direct method for decrypting anything without brute force or intelligent crypto attacks.
>>
>>57743396
That's basically what monads are for.
>>
>>57743429
>I need more memory
>I don't think the disk counts as memory
Well. Anon there is simply no process that can depend on where you've saved the same set of data. Other than performance implications.
Maybe it needed to happen within a timeframe? That'd be something that might require main memory.
>>
>>57743527

To be honest, I don't recall exactly what details of the project I'm allowed to discuss, anyway. Probably better that the discussion ends here.
>>
>>57743487
>But now you don't have referential transparency and yet you maintain purity.
No, that's not how it works. The "pure" in "pure functional programming" has a literal meaning. It means the language is completely functional.
>>
To be fair, though, the project was modular enough that if the input already was sorted, and had been split out into files based on those criteria, passing it in and merging the resulting CSVs would produce the same result as if you passed in the monolith of unsorted data. It could even be replaced with a DB (which is what I suggested, but alas, that's not what (((they))) wanted to do).
>>
>>57743487
It is sort of contextual.
Within the context, you are doing side effects.

E.g. within the list monad
do x <- xs
replicate x () -- branching side effect
pure x


But overall, it isn't really _doing_ side effects, it's describing them
>>
>>57743568
Well that is an interesting development

>>57743632
Those aren't side effects.
>>
>>57743637
>Those aren't side effects.

They're as much side effects as anything else that isn't explicitly IO, and arguably as much as IO
>>
Is there a recommended books list? I'm looking for books on algorithms and design patterns in java.
>>
Are there any books on C which are very detailed?
I feel as if there's so much going on behind the scenes for example just being told to use scanf without any alternatives or explanation makes me anxious. Will I just pick these things up later on? C is my first proper language.
>>
>>57743674
Side effects are reserved for things like memory management, I/O, FFI, etc.
It's just effects.
>>
File: 1480094252053.jpg (438KB, 900x2134px) Image search: [Google]
1480094252053.jpg
438KB, 900x2134px
>>57743689
>>
>>57743702
So in the case:

runMem :: Mem a -> IO a

data Mem a where
allocBlock :: Mem (Ptr a)
freeBlock :: Ptr a -> Mem ()

pureMem :: a -> Mem a
bindMem :: (a -> Mem b) -> Mem a -> Mem b


allocBlock is not a side effect?
>>
File: wf8.png (73KB, 1165x1024px) Image search: [Google]
wf8.png
73KB, 1165x1024px
Basic string support added for my Forth compiler (though the main thing was adding PARSE so you can grab a string up to a delimiter).
Not sure how I want to handle the data storage for compiled strings, for now I just dump them into regular data section. But that might not be ideal for when you wanna FORGET/MARKER the words since you should free that memory, but that wont really work since all data after the string would need to be shifted up and all their references (since everything is RIP-relative) need to be adjusted.
Maybe should have a dedicated string section separate from the regular data.
>>
>>57743858

This is a neat project, but what is the actual use-case for Forth? What have people done with it?
>>
File: kitten huffing.jpg (17KB, 288x352px) Image search: [Google]
kitten huffing.jpg
17KB, 288x352px
Friendly reminder that CPUs are a complex series of transistors forming a state machine and rely on side-effects by design.
>>
>>57743834
No. runMem has side effects as well as observable effects that are not side effects due to IO.

>>57743928
Side effects can be modelled so that they are effects.
>>
>>57743981
Is it not reasonable to think of allocBlock as a side effect in the context of the mem computation being run, which is presumably the intention?

What if Haskell exposed the IO implementation and you interpreted it on a pure VM?
>>
>>57743908
It's a general purpose language, so anything really.
Although it's main strength is embedded systems with really tight memory/cpu constraints (in particular truly custom chips designed for Forth) for example satellites, automation and control systems.
>>
>>57743928
Friendly reminder that sequential logic is just recursive combinational logic with delays.
>>
can someone spot what i'm doing wrong (it's an infinite list of 0's right now), and also how can i remove the repetition of the wheres?
-- returns the sum of two lists represented as  a linked list of digits in reverse order.
-- i.e. [7, 1, 6] + [5,9,2] is 617 + 295
sumLists :: [Int] -> [Int] -> [Int]

sumLists l1 l2 = sumLists' 0 l1 l2

sumLists' carry (x:xs) (y:ys) = currentIndex : (sumLists' nextCarry xs ys)
where
currentSum = x + y + carry
currentIndex = currentSum `mod` 10
nextCarry = currentSum - currentIndex
sumLists' carry [] (y:ys) = currentIndex : (sumLists' nextCarry [] ys)
where
currentSum = y + carry
currentIndex = currentSum `mod` 10
nextCarry = currentSum - currentIndex
sumLists' carry (x:xs) [] = currentIndex : (sumLists' nextCarry xs [])
where
currentSum = x + carry
currentIndex = currentSum `mod` 10
nextCarry = currentSum - currentIndex
sumLists' carry [] []
| nextCarry /= 0 = currentIndex : (sumLists' nextCarry [] [])
| otherwise = []
where
currentSum = carry
currentIndex = currentSum `mod` 10
nextCarry = currentSum - currentIndex
>>
>>57744090
Is there a reason you're not just using zip or zipWith?
>>
>>57744008
>Is it not reasonable to think of allocBlock as a side effect in the context of the mem computation being run, which is presumably the intention?
It's just an AST term. You might call it an effect but I wouldn't ever say it had side effects (unless you considered the language allocating memory for it and heating up the CPU a side effect).

I think of an effect as something that is modelled constructively and a side effect as something that is not, but that's probably just me.
>>
>>57744090
>>57744126
e.g.
f a b = foldl (\s x -> s * 10 + x) 0 $ zipWith (+) a b

zipWith (+) [7,1,6] [5,9,2] = [12,10,8]
foldl (\s x -> s*10 + x) 0 [12,10,8] = 1308
>>
>>57744126
>>57744201
i'm doing it as a practice problem
>>
>>57744201
>>57744126
>>57744221
also it's supposed to return in the same format of a digit in each spot in the list, not as an integer
>>
>>57744237
you could just split it up into digits and reverse afterwards?
>>
>>57744008
>>57744177
Actually that's not even how I think of it. Side effects may be modelled constructively but they are not constructive themselves, e.g. they're from FFI or compiler memory allocation or something. Effects are things like the Maybe or List monads that are treated like they're part of the computation and not the result yet they're fully constructive. But that's just the meanings I personally assign to the terms and I don't actually think about what is an effect or not when programming.
>>
If anybody here knows linux systems programming shit (basically just C and the available syscalls), I need some ideas.

I need to map to the same memory over and over, but such that the process "thinks" it's at a specific address every time it maps. Basically, I have the problem of
[memory pages with stuff that's the same][memory pages with stuff that's different]
being loaded thousands of times into memory, where the "stuff that's the same" is the same across multiple loads, but needs to be the same offset from the respective "stuff that's different" every time. Right now it just makes an entirely new mapping every time, but that's a massive waste of memory because the overwhelming majority is identical pages. The two solutions I've found are

1. Kernel same-page merging (i.e. KSM). This is nice, since the OS takes care of it in a way that is kindof sortof transparent to the program. It doesn't work right now though, since KSM only works on pages marked as mergeable, and the pages have to be private and anonymous, while currently, the pages are private and file-backed. The way I thought of working around this is making the pages anonymous and private, then just literally reading the file into the anonymous map. It just seems so fucking stupid to have to do that though.
2. Switching the pages that are the same from private mappings to shared mappings. This would be grand, if shared file-backed mappings didn't also modify the file whenever they were written to, and there's a tiny bit of writing that happens to these pages upon load. If that weren't already a deal-breaker, we're loading things we don't have write permissions to, so we can't just say "oh well". The workaround I thought of for that is copying the file to the /tmp directory so we can fuck with it before mmaping it into the appropriate position. But this seems even hackier than option 1.

So, is there some other, simpler way of doing this I'm not seeing?

>>57743689
K&R C 2nd edition, no question.
>>
>>57744090
Look at
sumLists' carry [] []

What happens when carry = 10? Manually step through it.
>>
>>57744090
figured it out, needed to divide the next carry by 10 since the next index is worth 10 times more
>>
>>57744340
i realized it pretty much right before you posted this. lol
>>
>>57743689
>scanf
Well its fairly rare to get much info on what's going on in the standard library. You can look at it if you want but usually it's not very constructive.
The way to think about it is that you're given an interface where they agree to have some consistent rules for how things work. Then the platform determines what actually happens. So Windows is different from Linux etc.

K&R is a book many recommend. It doesn't cover everything but it's a good source.
>>
>>57743264
>rsa encryption
>big boy

Are you 12?
>>
Is it poor form to use the result of an = assignment operator as an expression?
eg.
long parent_id;
if (!(parent_id = some_func(a, b))
goto fail;
>>
>>57744090
To remove the repetitive wheres, one solution would be to define a function that takes the current x, y, and carry and returns a tuple (currentIndex, nextCarry)
>>
>>57744505
C++ adds the following syntax

if (long parent_id = some_func(a, b), !parent_id)
>>
>>57744576
whoops
;
>>
>>57744576
C++ allows you to include statements within if conditionals?

Does that mean I can include a for loop within an if statement?
>>
>>57744619
no
you can't do
for (for(;;){}; a; b)
>>
>>57744090
divMod is your friend
You probably can rewrite the where clause as (nextCarry, currentIndex) = (x + y + carry) `divMod` 10 or something like that.
>>
>>57744619
You can't include arbitrary statements. It has to an expression statement or a declaration.
>>
const fetch = require("node-fetch");

const board = 'g';
const catalog = fetch(`https://a.4cdn.org/${board}/catalog.json`).then((x) => x.json());

const latestPostNum = catalog.then((catalog => {
return catalog.reduce((val, page) => {
page.threads.forEach((thread) => {
if(thread.last_replies) {
thread.last_replies.forEach((reply) => {
if(reply.no > val) {
val = reply.no;
}

});
} else if(thread.no > val) {
val = thread.no;
}
});

return val;
}, 0);
}));

latestPostNum.then((postNum) => {
console.log(postNum);
});


How do I make this look comfy? It feels a bit uncomfy looking at it.
>>
>>57744711
apt-get remove --purge -y nodejs
>>
>>57744711
Use intermediate values.
>>
>>57744711
Remove the unnecessary braces.
>>
>>57744711
What language is this?
Why the fuck do you have brackets for single-statement if conditionals?
>>
File: pepephone.jpg (64KB, 657x527px) Image search: [Google]
pepephone.jpg
64KB, 657x527px
Still working on my lab thing, so far I have..

import scala.util.Random

def frac(x: Double) = x
def gen(f: => Double, N: Int) = {
val p = List.range(0, N)
Random.shuffle(p)
val outvec = p
for(i <- 0 to N) {
(f * N) :: outvec
}
Random.shuffle(outvec)
}

var muhlist = gen(frac(0.3), 70000)


To the anon that curry'd it for me, I couldn't get it to take a second input that way. Sorry

http://cs.nyu.edu/courses/fall10/G22.2434-001/hw2_sol.pdf
>>
>>57744762
> {
s
}

for what purpose
>>
>>57744762
stupid frogposter cant believe i tried to help you
>>
I needed to open multiple video streams with mpv, so instead of opening multiple tabs of my terminal emulator I developed this program to repeatedly accept links to videos and play them

#!/bin/bash

while true ; do # loops forever
read url # wait for input
mpv --really-quiet "$url" & # plays what u input
done # done
>>
>>57739943

kid, take it from me. buy a book on network protocols. memorize the RFCs. get a tattoo.
>>
>>57744619
Iirc it's just expressions that evaluate to a value.
So no control flow or lambda expressions I take it.
>>
>>57740063

child, use interfaces. OOP is not about inheritance and its also not so much about encapsulation. its all in the interfaces and polymorphism.

ive seen your code and you are overboard with the inheritance. we dont do that in harlem
>>
>>57744930
OOP polymorphism is the shitty brother of good polymorphism
>>
File: wf9.png (77KB, 1030x999px) Image search: [Google]
wf9.png
77KB, 1030x999px
>>57743858
And now you can fizzbuzz.
It compiles to this: http://pastebin.com/R4JHEc1D
(72 instructions, 121 bytes)

Completely naive code gen of course, lots of room for improvement. Biggest win is gonna come from peephole optimizing DUP to combine and eliminate unnecessary stack juggling.
I'm not gonna go for an intermediate format, I'm just gonna pattern match the x86 op codes directly.
One of the design goals of this compiler is completely predictable assembly output, so I'm not gonna do any big transformations of the code. To tune specific user code you can write your own compiler tokens and guide the compiler to better code if needed.
>>
>>57741188

why do you care so much for types
>>
>>57744793

/g/ doesn't like brackets now?
>>
>>57745004
/g/ has never liked unnecessary braces, or newline braces

they just make your code harder to raed
>>
>>57744984
Don't you usually write a barebones compiler and then rewrite the compile in forth?
>>
>>57745033

Only for bootstrapping. There's no require that a language's compiler must be written in that language. Many compilers are written in something like Ocaml
>>
File: frogger.jpg (108KB, 677x529px) Image search: [Google]
frogger.jpg
108KB, 677x529px
>>57744822

anon don't be mad, in the next life I will make sure that allah insists your heaven is surrounded in parentheses

:^)
>>
>>57745078

no requirement**
>>
>>57745033
That's the plan.
The Forth is Turing complete now so I could do it, but it would be a Turing tarpit because I don't quite have all the abstractions I want (big thing missing is an inline assembler - I could copy machine code with Forth string literals for implementing all primitives, but that is hardly nicer than assembly)
>>
NEW THREAD!

>>57745118
>>57745118
>>
>>57745122
dumbass
>>
>>57744969

define good polymorphism. go on we are all waiting
>>
>>57745136
shut up and get in my new thread
>>
>>57744984
I wrote a primitive forth->x86 compiler not too long ago, but what I did was xchg the stack pointer with another register holding the data stack and do all the stack manipulation using normal push/pop instructions. It was especially nice since in x86-64 the first argument is %rdi so you can call C routines VERY easily.
typedef long cell;
cell* fth_mul (cell* stack) {
stack[1] *= stack[0];
return stack + 1;
}
cell* fth_out (cell* stack) {
printf("%d", stack[0]);
return stack + 1;
}
...
ok 5 4 .
fth_main:
xchg %rdi, %rsp
push 5
push 4
xchg %rdi, %rsp
call fth_mul
mov %rax, %rdi
call fth_out
ret
...


>>57745078
>writing forth compiler in OCaml
Completely unnecessary. Forth happens to be good at bootstrapping itself, based on its unique syntax model. You should try actually looking into it

>>57745109
>copy machine code with Forth string literals for implementing all primitives
How else would you do it in any other language?
Also, you could add a forth word for inline assembly :)
>>
>>57745168
Haskell or Idris
>>
>>57745184
the forth program supposed to be
4 5 * .
>>
>>57745207
Fuck, 5 4 you get the picture
>>
>>57745191

see >>57744990
>>
>>57744990
They are extremely useful
>>
>>57745184
>Also, you could add a forth word for inline assembly :)
Yeah that's what I'm gonna work on next.
But writing an x64 assembler (and disassembler because I want to implement SEE as well) is gonna take way more time and effort then the Forth compiler itself...
Initially I could write a machine code assembler and implement primitives something like this:
code DUP
48 8D 5B F8 \ lea rbx, [rbx-8]
48 89 03 \ mov [rbx], rax
end-code

which just compiles bytes into [code_here]

But to be truly bootstrapping I would have to generate an executable as well, so I need a PE64 writer too.
>>
>>57745258
Well, I was just producing assembler files and sending them to gcc, besides "implementing the linker" is rarely goal of bootstrapping most languages...
Although SERIOUS forth implementations could very well need to implement an assembler, however that's a lot easier for some embedded architectures that aren't x86
>>
>>57745300
The goal is a completely self-sufficient implementation, also planning to write an IDE, editor and debugger around it.
>>
>>57745386
Okay then this definitely sounds like a *serious* implementation.
Is the editor going to allow emacs-esque evaluation of forth commands?
>>
>>57745414
That's essentially already there.
Every line you enter is interpreted or compiled on the fly.
>>
>>57745168
Not they but.
The advantages of polymorphism can be read on Wikipedia if you'd like.
It's true we might not really care for polymorphism most of the time but it is situationally convenient.
>>
>>57745248
you're a big guy
Thread posts: 325
Thread images: 37


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