[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 30
File: anime computer.jpg (154 KB, 1280x720) Image search: [Google]
anime computer.jpg
154 KB, 1280x720
Old thread: >>51500924

What are working on, /g/?
>>
JEWS
>>
>tfw ugly
>>
File: Logo_lisp.gif (11 KB, 700x385) Image search: [Google]
Logo_lisp.gif
11 KB, 700x385
>>51512898
Building a Lisp, implemented in the following way with the help of Objective-C, YaCC, Lex, and itself:

This Lisp is called Valutron. It is architected as an integrated compiler-VM; essentially, this means that code, when entered at the REPL, is first converted into Cons trees, and then mapped down to primitive operations at the stage of evaluation. These primitive operations control a register VM, which operates on Cons cells and Objective-C objects representing Lisp values, and which is implemented as threaded code for maximum performance.

This form was chosen to make it possible to implement continuations easily and to promote good performance. At this point I have described how it implements a basic Scheme-esque Lisp. The VM, as I explained, operates natively on Cons cells. Implemented in Valutron itself are more extensible versions of some primitives like eval; these functions are registered with the VM and, from there on, replace the primitives with themselves.

Here is where Valutron offers a feature called V-expressions. V-expressions are an alternative to S-expression notation for code. They are low in the number of brackets characteristic of S-expressions, and are instead primarily algebraic-style infix. These are implemented by using reader macros. I am going to look into integrating a shift/reduce GLR parser that may have productions and rules dynamically altered at runtime, which will allow the extension and modification of V-expression syntax as well as even creating new DSLs with unique syntax.

The pièce de résistance is an object model inspired by the CL Object System, the first ever standardised object-oriented system, which was designed as part of Common Lisp. This is implemented in terms of the Objective-C runtime and hence the full dynamism of Smalltalk, Objective-C, and CLOS are available. The Objective-C runtime used was extended in order to support double dispatch, making available CLOS' characteristic multi-methods.
>>
I'm having difficulty wrapping my head around linked lists.
What is this example doing, and why is it assigning NULL to the first node's *next pointer?
node *curr, *head;
head = NULL;

int i;
for (i = 1; i <= 100000; i++)
{
curr = (node *) malloc(sizeof(node));
curr->data = i;
curr->next = head;
head = curr;
}
>>
>>51512915
>YaCC, Lex
For a lisp? Seriously?
>>
>>51512936
>casting from void*
>sizeof (node) instead of sizeof *curr

It creates 100k nodes in a linked list. It assigns null there because it's where the list ends.
>>
7th for C
>>
hey gais what language is smash bros coded in?
>>
>>51513049
SML
>>
>>51513049
nintendo SDKs use C/C++, and support was recently added for Unity3D
>>
>>51512936
imagine a chain. These nodes are all linked to create a chain. The last one in the list will be linking to nothing because it is the end of the list. When you make a doubly linked list it will link to the first element in the list.
>>
>>51513102
>support was recently added for Unity3D
fuck's sake
>>
>>51512993
I don't believe in writing my own parsing algorithms.
>>
>>51513138
why you mad?
>>
Working on an HTML 5 chatroom:
http://raskie.com:85
>>
>>51513174
Are you serious? Using lex and yacc for parsing sexpr or anything similar is inane. Literally kill yourself.
>>
>>51513119
well ok

how would I go about freeing that memory I allocated?
Do i just run through the loop again, copy the curr->next to a temporary pointer and then free that pointer?
>>
>>51513205
Why would I write my own parser when I can use Lex and YaCC to create one for me?

Anyway, it works. That's more than can be said for the one you suggest I write from scratch (what is code reuse and sensible library use?), because that one does nothing - it doesn't exist.
>>
File: image_71.jpg (92 KB, 850x478) Image search: [Google]
image_71.jpg
92 KB, 850x478
I'm interested in learning some programming. What would be so good resources to learn from, IDE's to use, and which programming language would be easiest to get into?
Probably not gonna turn it into much just a new thing to learn how to do.
>>
>>51512936
This example is very misleading, because the first node created (which data is 1) will end up being the last element of the list.
Of course, the most efficient way of adding nodes in a linked list is adding it at the beginning, so you don't have to traverse the list to add the node. A good exercise here would be to rewrite that example by writing the function that takes an integer and a list and add a node containing the integer to the beginning of the list. It's not exactly how it happens it the loop of your example.
>>
>>51513231
Writing a "parser" for sexpr will probably take you less lines than lex/yacc.
I seriously can't believe why shitheads like this are allowed to exist, holy shit.
>>
>>51512898
Isn't this that one anime with sexy kids and traps?
>>
>>51513175
unity3d games look, run and play like shit. if there's anything nintendo has going for it it is quality and social (real-life social) games. unity3d is going to make nintendo games more like other console games except nintendo has much weaker hardware that isn't going to run well.
>>
>>51513272
Tbh, the Lex and Yacc versions are probably more readable. Also it's likely that it's faster than a hand-written parser would be.
>>
>>51513346
>unity3d games look, run and play like shit.
Who gives a shit as long as they're fun? KSP is made in unity. That justifies it in my book.
>>
>>51513385
>Who gives a shit as long as they're fun?
You're not going to have any fun with a game that runs terribly on the Wii U's already anemic hardware.
>>
int main() {
return (int) malloc(1000);
}


this triggers the autists who say pointers != ints
>>
Anyone knows where I could find a PDF on this Color Science: Concepts and Methods, Quantitative Data and Formulae ?

I'm desperate
>>
>>51513239
>What would be so good resources to learn from
http://greenteapress.com/thinkpython/ is my go-to introductory programming text. It's one of the few books that actually teach and explain the key challenges involved, rather than just mentioning them and hoping for the best. Also, it's free.

>IDE's to use
I strongly recommend you work without any until you are comfortable working with more barebones tools. Once you understand exactly what is going on when you develop things, then you can start using tools that automate parts of the process where you don't see it. When you start noticing tedious *but not challenging* aspects of your programming, then you can start exploring tools that lift some of that burden, but no earlier.

>and which programming language would be easiest to get into?
Python is generally hailed as friendly on beginners yet powerful for real-world projects. The book I recommend above uses it, and it's probably the best general-purpose language to start programming with in the absence of specific preferences.
>>
>>51513413
pointers arent ints
but sure you can cast them to ints if you like
>>
>>51513403
you could easily just optimise it to run fine on wii. Drop the polycount, effects etc.

Monument valley is another unity games. Looks amazing, and sports a flawlessly smooth framerate.
>>
>>51513413
Well, it doesn't necessarily fit in an int. But of course casting a pointer to an int is a valid operation, if somewhat of a meaningless one.
>>
>>51513413
You can cast to whatever you want, but why?
>>
Java vs C#? Which is better?
>>
>>51513512
C#
>>
>>51513413
this is cancerous.
>>
>>51513512
nether
>>
>>51513512
C# is a better language, but a terrible platform, which makes it useless.
>>
>>51513512
java
>>
>>51513534
i thought C# was available on linux with it being open source and everything
>>
>>51513534
>but a terrible platform
It's a great platform. What makes you think it's bad?
>>
>>51512936
Just for you: an expert programmer's interpretation of simple lists.

In this implementation, we use a dummy head node, meaning that we have a pointer called ``head'' which isn't used to store a value but instead just serves to remember where the beginning is.

#include <stdio.h> 
#include <stdlib.h>
#include <assert.h>

struct node {
int val;
struct node *next;
};

struct node *
new_node(void) {
struct node *n = malloc(sizeof(struct node));
n->val = 0;
n->next = NULL;
return n;
}

struct node *
make_node(int val) {
struct node *n = new_node();
n->val = val;
return n;
}

size_t
length(struct node *head) {
size_t len = 0;
for (struct node *cur = head->next; cur; cur = cur->next)
++len;
return len;
}

void
insert(struct node *head, int val, size_t index) {
assert(index <= length(head));

struct node *n = make_node(val);
struct node *cur = head;
for (size_t i = 0; i < index; ++i) {
cur = cur->next;
}
n->next = cur->next;
cur->next = n;
}

void
append(struct node *head, int val) {
insert(head, val, length(head));
}

void
prepend(struct node *head, int val) {
insert(head, val, 0);
}

void
print(struct node *head) {
printf("list of length %zu: ", length(head));
printf("[ ");
for (struct node *cur = head->next; cur; cur = cur->next) {
printf("%d", cur->val);
if (cur->next)
printf(", ");
}
printf(" ]\n");
}

int main(void) {
struct node *list = new_node();
for (size_t i = 0; i < 3; ++i)
append(list, i);
prepend(list, -1);
insert(list, 444, 3);
print(list);
return 0;
}
>>
>>51513426
thanks guy
>>
dude... *hits bong* ...monads... *exhales* ...lmao
>>
how do you reset a sprite color
>>
>>51513824
very careful
>>
>>51513706
Why do you post all your types on a separate line?
>>
>>51513706
>asserts
FOR WHAT REASON
>>
>>51513881
For the same reason any and all asserts are used, you dolt.

(Not that guy.)
>>
>>51513879
it's BSD coding style
The justification I've heard for it is that its really easy to find where you've defined a function by searching for ^function_name
>>
File: 50278999_p0.jpg (458 KB, 600x800) Image search: [Google]
50278999_p0.jpg
458 KB, 600x800
Just a brief bit of noise here.

I'm using MSYS2 and can't seem to find any documentation about how make is able to interpret paths in a makefile. I'm trying to build a program that depends on zlib and can't figure out how to point to the "system installed" version. I copied its headers and referenced them as ./zlib/zlib.a etc, but know there's a better "right" way to do this.

How do I reference libraries and headers (in an MSYS environment)?
>>
>>51513912
The GNU style has the same characteristic.
>>
>>51513928
You specify the directories to search for headers by using -I switches when invoking the compiler. You specify the directories to search for libraries by using -L switches when invoking the linker.

For header paths, the specified directories shouldn't include any component which is part of the header name. E.g. if the OpenGL headers are /usr/local/include/GL/gl.h etc, you'd use -I/usr/local/include, because the header is named <GL/gl.h>.
>>
/g/ I need an advice

I have an opportunity to enroll in UC San Diego for computer science, but it seems their major is more Math centered

Like, it's more of a math major than computer science major, which is okay for me but...

How good is that for employers seeking a CS degree? Should I just enroll on a college that is more focused on computer science?
>>
>>51513879
Both what he said >>51513912 and that function definitions can get pretty wordy.

 
/* Newlines are misplaced here. */
const struct inode *security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
{
...
}
/* better: */
const struct inode *
security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) {
...
}
>>
>>51514066
computer science is math, though
maths is a very good skill to have for jobs, too
>>
>>51514066
>wtf i just wanted to program video games
>>
>>51514030
I was looking at it, again, and finally stopped to see the obvious. The makefile was never trying to reference system libraries, it was expecting a local directory. So I guess what I had set up was what it was made for to begin with... Fixed it by pointing explicitly though.

Thanks.
>>
>>51513208
it wouldnt even be that complicated. Since the memory is a part of the heap and it is still just in ram you could just se. first and next to null. The other other allocations of memory are then freed and you would then just have to clear the objects. If your program was stringent on clearing out all memory you could have a clearing function that simply invoked the destructor for each object/node at the end of your reallocation phase. like garbage collection.
>>
>>51514066
>How good is that for employers seeking a CS degree?
It depends specifically on what you want to do. The qualifications associated with the term "CS" are almost meaningless now, as different places treat it as a code monkey degree or a mathematics degree or somewhere in between.
>>
>>51513208
void
free_nodes(struct node *head) {
struct node *cur = head;
while (cur) {
struct node *next = cur->next;
free(cur);
cur = next;
}
}
>>
>>51513480
Well, I can see a specific case where you don't want to do pointer arithmetic with this value, like peeking into memory with a byte granularity.
>>
>>51513272
The guy is already building his own lisp, he's too far gone from reality son, let it go.
>>
>>51514521
Then you cast to char* and back.

Pointers aren't as simple as linear addresses on all platforms, and if you aren't trying to support the most esoteric of hardware you shouldn't even bother with C. Pointer arithmetic will not always be equivalent to integer arithmetic.
>>
>>51514337
>>51514084
>>51514148
I don't mind math, I have high grades on all my math courses so I don't really care if it's math centered or not

If I'm looking to program artificial intelligence and specialize in that area, is that really the way to go? And if employers would want to see more Computer Science classes instead of more math classes, if you understand what I'm saying.

Would you do a math-centered CS course for AI /g/? Thanks for the replies btw
>>
>>51514568
>And if employers would want to see more Computer Science classes instead of more math classes, if you understand what I'm saying.
CS is applied math or just specialized math courses anyways unless you're at some shitty school that treats it solely as Oracle-certified Java training.
>>
What is an uniary minus in C++?

Seems like it just gives the variables vaule but negative. Like

int a = 7
cout << -a
{/code}

Would just print -7. Would that also change a in place to be -7? I dont understand why this is a thing,
>>
>>51514584
Oh okay
I'm sorry for being confused, here I heard each UC has a different focus of computer science courses, which made me wonder which one to go. I heard UC San Diego was more "math than CS" so I didn't really know what that meant

I might just go to San Diego I guess.
Thanks
>>
>>51514568
>If I'm looking to program artificial intelligence and specialize in that area, is that really the way to go?
Yes, absolutely. AI is *particularly* math-heavy; specifically, it is heavy in the fields of math typically studied in mathematics programs (linear algebra, probability theory, multivariate calculus, that sort of thing), as opposed to the mathematics specific to theoretical computer science like automata theory.

>And if employers would want to see more Computer Science classes instead of more math classes, if you understand what I'm saying.
Some do and some don't. Many employers just want more cheap code monkeys to abuse, and thus want CS programs to function as close as possible to trade schools. Others are indeed interested in employees that actually know the shit necessary to push the envelope, which is the kind of activity where you really do need all that CS background.
>>
>>51514625
-a
a.operator-()
normally returns decltype(a) and is const
>>
>>51514625
Yes, a minus gives the variable's value, but negative. If you weren't stupid that would be obvious.
>>
File: KRC.jpg (125 KB, 300x377) Image search: [Google]
KRC.jpg
125 KB, 300x377
>>51512915
Lisp is a fucking horrible hipster langage. It has NOTHING that isn't in C. The same with Objective-C.

Pic related: it's what you morons need to read.
>>
>>51513879
not them but it helps to creafe coherency with other disciplinary imperatives. For example, writing. Like in writing, you generally elaborate over a series of sentences and then make a new line when an idea is complete.
"My class needs ints. An int for this, an an int for that, so on and so forth."
"Now, my class needs a pointer to manage those ints."
"Now I'll need a character array."

"Now that we have our variables, let's define a manner for those ints to be explicitly incorporated into our program.
Firstly, we need to describe the numeric operations to those ints. This can be described as such. Thus to be surmised as such.
Secondly, we must define a compositional adjunction for these operations in pairs. Adding one will increment. In contrast, subtracting one will decrement.
Next, we'll need a top down view of the operations. Let's take our pointer and ... ..."

"With our numbers in order we will now need to appropriate function to our character array.
First, we will need to allow for functorial insertion and extraction via the front or from any particular indexed point in the array.
Next, we will need to allow for a characterized/comparative search in our array, which used in conjunction with our primary index functions should allow for extraction.
Etc, etc."

It helps with organization. Just incase it helps, know that whitespace is completely ignored by the compjler. You could write

void fart
()

{ code code code
}

and the compiler would use it to define a function. Ultimately, there is a syntax that it seeks out so make sure not to split words with whitespace. Not that you would but we are on 4chan and the contrarian tumblrinas and keks happen by some times to fuck with the whole thing we have going here.
>>
File: CPP.jpg (57 KB, 320x320) Image search: [Google]
CPP.jpg
57 KB, 320x320
>>51514705
C is a fucking horrible hipster language. It has NOTHING that isn't in C++. The same with Objective-C.

Pic related: it's what you morons need to read.
>>
Help me reverse a list /g/
rrev [] = []
rrev (x:xs) = rrev xs ++ x

*Main> rrev [1,2,3]
<interactive>:4:7:
No instance for (Num [a0]) arising from the literal `1'
Possible fix: add an instance declaration for (Num [a0])
In the expression: 1
In the first argument of `rrev', namely `[1, 2, 3]'
In the expression: rrev [1, 2, 3]
>>
How do I comprehend Java OOP?
>>
>>51514768
"x" is just a value, not a list. So you can't use "++" on it.
>>
>>51514763
Ill read this after programming principles and practice using c++
>>
>>51514768
[1,2,3].reverse()
>>
>>51514768
best lang coming through
le_list[::-1]
reversed(le_list)
>>
>>51514769
Do a lot of programming without it. Then you'll be able to know when certain things would have been useful.

It's better than learning it without any experience, then thinking that you have to apply it everywhere.
>>
>>51514769
the essence of objects
>>
File: D Lang.jpg (31 KB, 383x499) Image search: [Google]
D Lang.jpg
31 KB, 383x499
>>51514763
C++ is a fucking horrible hipster language. It has NOTHING that isn't in D. The same with Objective-C.

Pic related: it's what you morons need to read.
>>
>>51514763
I don't think you understand.

C++ is another hipster language.Much like Lisp, another hipster language, it offers NOTHING over C. The same for Haskell, Java, Node.js, and all the other stupid shit.

Drop your C++, Haskell, Lisp, Java, and Ruby. Start using a real man's language. The hipster languages won't even exist soon. Like Fortran or Cobol they seemed cool for a while, maybe even 20 years if they were lucky, but they never lasted any longer before people realised that they offered nothing that you couldn't do even better in straight C.
>>
>>51514859
I don't think you understand.

C is another hipster language.Much like Lisp, another hipster language, it offers NOTHING over C++. The same for Haskell, Java, Node.js, and all the other stupid shit.

Drop your C, Haskell, Lisp, Java, and Ruby. Start using a real man's language. The hipster languages won't even exist soon. Like Fortran or Cobol they seemed cool for a while, maybe even 20 years if they were lucky, but they never lasted any longer before people realised that they offered nothing that you couldn't do even better in straight C++.
>>
>>51514851
What about that gc though?
>>
Does anybody have any experience using any APIs for parsing natural text / named entity recognition? Curious to hear what your experiences were. Seems like there are myriad tools out there.

what's the deal with nerds on this board saying that C > everything. There are factors other than "can i tell the computer to do anything it can do" that are attractive.
>>
>>51514859
I don't think you understand.

Some people here write actual software.
>>
>>51514912
Prolog
>>
>>51514908
extern C
>>
>>51514920
just looking for an existing API that I can use. I don't have time to try to make something myself. Probably going with GATE at the moment.
>>
>>51514798
That's what I was supposed to get from the error message? Jesus christ that's cryptic.
>>
>>51514925
That doesn't make any fucking sense at all.
>>
>>51514965
It always helps to provide an explicit type expression. When type inference is involved, error messages may not make sense.
>>
>>51514991
ignore him
core.stdc.stdlib.malloc
core.stdc.stdlib.free
>>
>>51515006
Yeah but the whole library uses the GC. Doing things from scratch in D would still be better than C (what isn't) but you lose so much.
>>
>>51514965
>>51515004
*type declaration. But you get the point.
>>
>>51512898
>tfw programming assignment that I have no idea how to do is due in a few hours
>Its easy guise, just create a data structure for this problem youve never encountered in java which is a language youve never used before.
Just gonna take the L on this one.
>>
>>51515051
extern (C++)
>>
I wrote a function in bash that traps itself on SIGWINCH. Is that a bad idea?

my_function(){
trap 'my_function' SIGWINCH

if [ some_stuff == whatever ]; then
# do stuff
else
trap - SIGWINCH
fi
}
>>
>>51515099
extern (Haskell)
>>
>>51515051
>>51515099
>>51515108

scratch all that

@nogc
function attribute

D is working on making the whole std lib (phobos) @nogc compliant

rip other languages
>>
>>51515133
you'd still need to malloc though
or write code to malloc for you, it is D after all
>>
>>51515151
holy shit that get
>D officially best language
>>
>>51515151
D has destructors unlike C, so you can write data structures once and not end up spending all your mental energy trying not to create memory leaks.
>>
File: logo-sun.jpg (20 KB, 360x193) Image search: [Google]
logo-sun.jpg
20 KB, 360x193
>>51515173
Innovation!
>>
c# newbie here, how do i properly do exception handling for StreamReaders?

        StreamReader reader;

try {
reader = new StreamReader(path);
}
catch (Exception e) {
//log error, throw popup, etc
}
finally {
reader.Close();
}


If i do the above then reader.Close() complains that it's an unassigned variable.
If i put the declaration inside try, then reader doesn't exist in the finally block at all.
If i put the initialization before try, i can get unhandled exceptions from the constructor.

What the fuck to do?
>>
>>51515208
The exception would get thrown inside the constructor, before the variable is assigned.
>>
File: 1448346356458.jpg (674 KB, 2000x1516) Image search: [Google]
1448346356458.jpg
674 KB, 2000x1516
D! D! D!
>>
File: ss+(2015-11-24+at+09.57.49).png (2 KB, 322x23) Image search: [Google]
ss+(2015-11-24+at+09.57.49).png
2 KB, 322x23
Processingfag from yesterday, I need help
Entity swimmer;
void setup()
{
size(600, 600);
swimmer = new Entity(100, 100);
}

void draw()
{
background(50, 50, 255);
swimmer.move();
swimmer.display();
}

class Entity
{
int posX; //starting horiz. position
int posY; //starting vert. position
float speedX; //horizontal speed
}

void Entity(int startX, int startY)
{
posX = startX;
posY = startY;
speedX = 25;
}
void move()
{
if (keyPressed)
{
if (key == "LEFT")
{
posX -= speedX;
}
if (key == "RIGHT")
{
posX += speedX;
}
}
}


//display
void display()
{
fill(255);
rectMode(CENTER);
rect(posX, posY, 20, 20);

}

It's giving me an error whenever I attempt to compile it. Help.
>>
>>51515208
>>51515219
Oh, and what that means is that while you can't call Close(), you don't have to.
>>
>>51515232
someone already told you what to do
class Entity
{
int posX;
// etc
} <- move this to the bottom, after all the other junk
>>
>>51515221
desu the parameter stuff (ref/inout/scope/etc) is nonsense
>>
>>51515249
So I'm suppose to split initialization and reading into two try/catch blocks? It seems like the only reasonable way to do it...

        StreamReader reader;

try {
reader = new StreamReader(path);
}
catch (Exception e) {
// log/display file error
return;
}

try {
// read
}
catch {
// log/display reading error
}
finally {
reader.Close();
}


Right?
>>
>>51515232
Your class needs to contain the methods you're trying to give it
class Cheese{
int etc;
int et2;
void Cut()
{
//etc
}
void Slice()
{
//etc
}
}
>>
File: gay_lambda.gif (8 KB, 648x432) Image search: [Google]
gay_lambda.gif
8 KB, 648x432
>>51514705
This guy is true. Fuck your Lisp, >51512915. You functional faggots are the cancer that is destroying programming.

Pic related: Lambda means gay.
>>
i just got a job offer for a C# shop that pays 6 figures

i've only done ruby, php, perl professionally and i've messed around with c, c++.. but it's always been in linux

i pretty much have to accept because of the money.. but how bad is it going to be f a m i l y ?
>>
>>51515297
Can confirm, Lambda is Greek, so it either means gay or debt
>>
>>51515298
Pretty bad, champ
>>
>>51515297
>doesn't like dick in ass
what are you, gay?
>>
>>51515297
functional is the future of programming : ^ )
>>
>>51515283
You can clean it up quite a bit with "using". Even if an exception is thrown inside, the Dispose method (which for a StreamReader is the same as Close) gets called.
try {
using(StreamReader reader = new StreamReader(path)) {
// use it
}
} catch(Exception e) {
// log
}
>>
>>51513512

Depends on where you want to work.
>>
File: golden_ratio.gif (16 KB, 649x512) Image search: [Google]
golden_ratio.gif
16 KB, 649x512
/dpt/, do you believe?
>>
>>51515381
what does that even mean.
>>
>>51515429
your love is truuuuu~~
>>
>>51513706
>Just for you: an expert programmer's interpretation of simple lists.
just fuck off
>>
>>51515297
Functional programming is Cultural Marxism applied to programming.
>>
If you use one of the following languages: C++, Ruby, Lisp, Objective-C, Haskell, Rust, PHP, Visual Basic, C#, Scheme, Node.js, Python, Julia, Pyston, Nimrod, D, or (WORST OF ALL) Google Golang: You use a fucking horrible hipster langage. It has NOTHING that isn't in C, one of few languages to have survived for more than 25 years. All of the languages I listed above will be dead, or almost dead, within 25 years of their creation.

Pick up a copy of Kernighan and Ritchie's The C Programming Language. Written in 1973, it will teach you how to program for real, and make compiled programs. Not to talk a pile of trash into a hipster interpreter.
>>
>>51513706
Where are the frees?
Please tell me you're not actually wasting memory like this.
>>
>>51515514
>It has NOTHING that isn't in C
ITT: Anon rediscovers the Turing machine
>>
>>51513413
I'm more triggered at the lack of indentation.
>>
>>51513512
C.
>>
On the tenth page of my language specification. Finally finished the section about the core syntax, now I'm writing up about its module system. I've already come up with a few ideas that I really like and will definitely keep in the final language.
>>
>>51515514
Sorry C-uck, I have real software to write and can't waste time rewriting data structures and string libraries.
>>
>>51515573
What's your language like lad?
>>
File: qwer2.jpg (776 KB, 1199x7206) Image search: [Google]
qwer2.jpg
776 KB, 1199x7206
If you use any of these languages, you're a shit programmer.
>>
>>51515585
It's kind of meant to be a successor to MLs (specifically OCaml) so the syntax is very similar to SML, OCaml, etc. It also gets a few features out of Haskell (type classes, etc.) but it isn't that similar to it. The main features are:
>dependent typing
>powerful modules
>good metaprogramming
>>
can someone explain to me what a hashset is and how its not just a set. Ive heard its a common question during an interview.
>>
>>51515614
>Terra not listed
Phew, dodged a bullet. I can continue to enjoy my multi-stage programming in peace. Won't you join me?

http://terralang.org/
>>
>>51515620
>dependent typing
Copycat.

I kid. Personally, I prefer Haskell syntax to ML syntax but ML modules are quite nice.

>>51515632
A hash set is an implementation of the set ADT. It uses a hash table as the method of determining whether a given element is already contained.
>>
>>51515614
Good thing I use ISPC.

Take note of the power of SIMD C-ucks.
>>
>>51515614
>not using C+=
>not conforming with the CoC
>>
>>51515632
hashsets are O(1). sets are something else.
hashsets are implemented using a hashtable.
>>
>>51515285
>>51515263
Fuck, disregard.
But yeah, now I'm getting a NullPointerException error whenever it tries to call move() and display()
>>
>>51515523
Serializing a list doesn't hold all unused objects in memory and with enough breakpoints in the code you can make sure only the used memory gets handled over.

Unless you're working on AI, and a rigorous one at that, you don't really need to kill yourself over a few 4kb class declarations. It's one thing to code well and it's another thing to write programs.
>>
>>51515650
Terra has to be the biggest fuck up I've ever seen.

All that work and you still just use malloc and free for memory.

What a waste.
>>
>>51515679
What would you prefer?
>>
>>51515666
> Unless you're working on AI, and a rigorous one at that,

I'm not surprised people don't know what the fuck they are talking about.

I'm surprised when they don't realize they do.
>>
>>51515665
Disregard that, too. Left out a line of code.
Now I just need to get it to move properly since it won't budge
>>
>>51515691
destructors and move semantics
>>
>>51515651
Yeah, I get it. There are some things I really like in Haskell, but I can't really get behind a lot of the syntax. I'm trying my best to get away from the disgusting/awkward parts of the ML syntax but it is pretty difficult.

Anyways, yours will probably be better because there's no way this type system will be at all sane~
>>
>>51515665
move() and display() are functions native to Processing. You might want to keep those out of the class declaration. Don't forget to update the move() function to change the positions from within the Swimmer entity rather than as global variables.

move()
{
swimmer.posx += 25
}

instead of

move()
{
posx += 25
}

kind of thing
>>
>>51515666
those 4kb add up, especially if that wasteful function is called hundreds of times a minute.
>>
>>51515710
What?
>>
>>51515762
But it won't work outside of the class declaration. Unless I've come to a terrible misunderstanding and I need to re-evaluate my life choices. Which I do
>>
>>51515876
Why not try one of those youtube Processing tutorials? I remember watching one and thinking it was simple enough. I'd help you out a bit more but I'm on what amounts to a 56k modem right now.
>>
bool f(){
bool x=true;
if (x==true){
return true;
}
else{
return false;
}
}

Guess how often I see this as a TA.
also how do you make blocks of code.
>>
>>51515971
{code}
code here
{/code}
with square brackets
>>
>>51515728
>d*structors and m*ve
k-kuffar! get out!!
>>
hello dpt
anyone still awake?
>>
>>51516005
bool f(){
bool x=true;
if (x==true){
return true;
}
else{
return false;
}
}
>>
>>51515876


int rectWidth;

void setup() {
size(640, 360);
noStroke();
background(0);
rectWidth = width/4;
}

void draw() {
// keep draw() here to continue looping while waiting for keys
}

void keyPressed() {
int keyIndex = -1;
if (key >= 'A' && key <= 'Z') {
keyIndex = key - 'A';
} else if (key >= 'a' && key <= 'z') {
keyIndex = key - 'a';
}
if (keyIndex == -1) {
// If it's not a letter key, clear the screen
background(0);
} else {
// It's a letter key, fill a rectangle
fill(millis() % 255);
float x = map(keyIndex, 0, 25, 0, width - rectWidth);
rect(x, 0, rectWidth, height);
}
}


Hey, if this code is telling of the functionality then that means your move function shouldn't have keyPressed as a condition and that instead you should create a keyPressed() function and write your code in there.
>>
>>51516061
>>51515971
yeah, the indentation is horrible
>>
>>51516061
dude use some indentation
christ
>>
how do i make video game
>>
>>51516108
Game game = new Game("3D");
game.addBadGuys();
game.makeExplosionsLookReallyCool();
game.enableSecretFinalBoss();
game.setYouCanDoAnything(true);
game.start();
>>
>>51516139
you forgot
game.addLensFlare();
>>
i dont feel well dpt
hold me
>>
>>51516207
*holds*


I bet what I just did is against the CoC though, sorry if it triggered you
>>
File: 1390637423220.gif (320 KB, 500x373) Image search: [Google]
1390637423220.gif
320 KB, 500x373
In MATLAB in particular, I have a vector that is going to change a LOT. (Basically going to record inputs from a user in a vector)

Would it be faster to make a fuckhuge vector and then trim off the zeros, or just concatenate the old vector + new input everytime? I know its faster to preallocate the vector rather than extending it every iteration, but I'm wondering if that rings true for cat(1, a, b) as well.
>>
File: yh9zw.png (69 KB, 750x453) Image search: [Google]
yh9zw.png
69 KB, 750x453
>>51516253
ah, yes
but - I guess you consented!
>>
File: Screenshot_2015-11-24_22-30-42.png (318 KB, 1087x459) Image search: [Google]
Screenshot_2015-11-24_22-30-42.png
318 KB, 1087x459
That got morbid pretty quick
>>
>>51513119
that's a circular linked list, dumbass
>>
File: possibly cheating..png (37 KB, 584x613) Image search: [Google]
possibly cheating..png
37 KB, 584x613
>not using your own code to read dpt
>not using your own code to use someone else's code to read dpt
>>
>>51516287
problems like this are the most interesting, imo
>>51516274
>Would it be faster
if only there was a standard way to test the speed of things
if only there was a way to get the time, run the two differing codes, then compare their execution speed
we'll have to wait for the 22nd century, I guess
>>
>>51516316
Does D come with a JSON library?
>>
>>51516332
import std.json;
auto x = parseJSON(string);
x["key"]...
>>
>>51516355
Nifty
>>
File: SCAN0083.jpg (692 KB, 1853x1285) Image search: [Google]
SCAN0083.jpg
692 KB, 1853x1285
>>51516070
I should probably post my assignment page
>>
>>51516253
Nevermind I'm good now.
I did a ton of blow but I evened it out with some beers.
>>
>>51516359
better edition:

get("https://a.4cdn.org/" ~ board ~ "/thread/" ~ thread ~ ".json")
.parseJSON
["posts"]
.array
.each!((JSONValue str) => str["com"].writeln);
>>
wasm when
>>
>>51516413
last x posts:
.array
[$-x..$]

fuck I love D
>>
>>51515876
Hey guy, try this code out. My Processing is still downloading but here's some code that should work if the examples themselves aren't fucked.

class Entity
{
int posX, posY, speed;
Entity()
{
posX = 0; //starting horiz. position
posY = 0; //starting vert. position
speed = 25; //horizontal speed
}
Entity(int startX, int startY)
{
posX = startX;
posY = startY;
speed = 25;
}

}


void setup()
{
size(600, 600);
noStroke();
background(50, 50, 255);
Entity swimmer = new Entity();
}

void draw()
{
if (keyPressed)
{
fill( 50, 50, 255 );
rect( swimmer.posX, swimmer.posY, 50, 50 );
if (key == UP)
{
swimmer.posY += speed;
}
if (key == DOWN)
{
swimmer.posY -= speed;
}
if (key == LEFT)
{
swimmer.posX -= speed;
}
if (key == RIGHT)
{
swimmer.posX += speed;
}

}
fill( 255 );
rect(swimmer.posX, swimmer.posY, 50, 50);
}


I didn't use the second constructor but it should still work.
>>
>>51516413
why does C# syntax have to be so bloated
new HttpClient().GetStringAsync("https://a.4cdn.org/" + board + "/thread/" + thread + ".json")
.ContinueWith(x => (JsonConvert.DeserializeObject(x.Result) as JObject)
["posts"]
.ToList()
.ForEach(post => Console.WriteLine(post["com"]))
).Wait();
>>
>>51516321
Hmm. Okay. I guess I probably should have thought of that but at the time it wasn't something that donned on me.

It's definitely quicker to preallocate and delete the unused terms than it is to just increase the vector size. For my purposes, it probably isn't all that big of a deal but it's nice to know into the future.

Cheers anon
>>
>>51515576
You're right you can't write a library once and use it multiple times in C or even download libraries. Shit is legitimately impossible
>>
>>51516454
Same
I haven't gotten too deep into it, but I'm liking what I've seen so far.
>>51516506
wew
>>
>>51516507
in the general case
whenever you're unsure about performance...benchmark the fuck out of it.
make an objective decision yourself instead of relying on what others say
>>
>>51516294
Oh yeah, my mistake.

It's circular. In a doubly linked list each node has a reference to a before and next node. A circular doubly linked list has a reference to the front from the back and each node in it has a reference to the next and before nodes.

Sorry about thanks.

Thanks for the correction, anon!
>>
>>51512915
>>51514705
MEMORY
O
D
E
L
>>
Null terminated byte arrays
Significant whitespace
cin/cout
>>
File: 194.png (36 KB, 400x259) Image search: [Google]
194.png
36 KB, 400x259
Hey /dpt/ I have a noob python question

I have an arbitrarily-sized list of bins -- [0, 2.5, 10, 11, 20]. The "size" of the bin can change from number to number as well, no pattern to it.

If I have a number, how can I determine which range-based bin that number belongs to? I.e. if I have int 1, it will show it belongs to the (0, 2.5) bin. If I have 5, it'll show itself as belonging to (2.5, 10), etc

Also, how can I return the bin's index?

Is there a faster way to do this than the naive comparison-based method? I'd rather not use numpy.
>>
File: 1383399938741.png (84 KB, 629x350) Image search: [Google]
1383399938741.png
84 KB, 629x350
>>51516501
It's not working, but I might have pasted it wrong.
Actually, if you wouldn't mind, can you maybe shoot me a Skype request? It'd make shit a ton easier.
ID: screwattacked
>>
I have 12 hours to learn Erlang. Where should I start?
>>
File: 1439590011623.jpg (259 KB, 1000x1502) Image search: [Google]
1439590011623.jpg
259 KB, 1000x1502
>>51516599
Here.
>>
>>51516584
as the list is sorted, the answer wants you to use a binary search. look that up.
>>
File: d2.png (40 KB, 1179x517) Image search: [Google]
d2.png
40 KB, 1179x517
>>51516506
now do this
>>
>>51516584
index = None
for i in range(len(bins) - 1):
if i >= bins[i] && i < bins[i + 1]:
index = i


You can then use the index (of the bin's lower bound) to get the bounds of the bin.
>>
>>51516506
And people say monads are just a meme.
>>
Unix question here

Reading up on chmod documentation (yes i'm that new)

I understand that chmod u+s sets a file to run with it's owners permissions, but my confusion is to why it's u+s not o+s.

i would've thought that if i run a file i don't own, i would fall under Other permissions, not user permissions. What am i missing?
>>
>>51516584
if i understand you correctly, do you mean something *conceptually* like this?
bins=[0,2.5,10,11,20]
binning=lambda n:list((n[i],n[i+1]) for i in range(len(n)-1))
def findBin(i,n):
for l in range(len(n)):
if i>=n[l][0] and i<n[l][1]:
return l

print(findBin(4,binning(bins))) # should put it in bins[1], so this returns 1


I'm trying to think of the smarter intuition behind this that avoids a lot of this stupid for loop crap, but it's escaping me at the moment. I have a headache and it's been a long day.
>>
If you don't know morse code then you literally have no right to call yourself a programmer.
>>
>>51516657
filter your html encodings faggot
>>
>>51516721
nty
>>
File: 9e7yk.png (52 KB, 939x393) Image search: [Google]
9e7yk.png
52 KB, 939x393
>>51516657
why do you use two regexs
the second contains the first
just for good measure, I included it anyway
>>51516721
as you wish
>>51516686
uh, what? there were no monads used in mine or the other guy's code
>>
>>51516741
>why do you use two regexs
oh, you replaced with new line
didn't see that. oh well.
regex is hardly needed for that, though. string replacement would be much faster.
>>
>>51516741
Nope, it's definitely a monad. ContinueWith is bind, and Wait is sort of like the monad's "run" operation.

https://ruudvanasseldonk.com/2013/05/01/the-task-monad-in-csharp
>>
just parse the page with html.
regex.
simple
  o  o
\____/
>>
>>51516701
never mind i'm a dumbass.
>>
>>51516769
oh, I guess in that way.
ContinueWith isn't used much anyhow, as C# has 'await'.
that link looks to be implementing something similar to javascript's Promises, though
>>
>>51515514
Python's 25th anniversary is in February next year, only a few months away. C++, Scheme, Lisp, Haskell, and Objective-C have already been around for over 25 years. VB is also almost 25 years old, I think.
>>
open ModularSelectors

module Selection =
getOS >>= \os ->
getArch >>= \arch ->
select[operating_sytem = os, architecture = arch]
open MyModule Selection

r8
>>
I'm thinking of remaking a minimalist version of Zork, but as a Bash script. Thoughts on who would want to see this or whether there's something stopping me from doing it?

Doing it cause I'm bored and like to code, no other real reasons or goals.
>>
>>51513757
Personally I would learn C++/Java/Python. Those are typically the 3 languages that most big name companies want you to be proficient in starting. There are exceptions, like I think Apple uses mostly C, but anyway, if you learn one of those, then learning new languages is generally easy.
>>
File: 1440203491333.jpg (40 KB, 600x450) Image search: [Google]
1440203491333.jpg
40 KB, 600x450
>be imperative programmer
>always make fun of anons on /g/ for functional programming, muh monads, muh currying, muh endofunctors, etc
>taking compsci final exam
>question 3
>"Show how the curried function definition mult x y z = x ∗ y ∗ z can be understood in terms of lambda expressions."
>mfw I should have studied haskell
>>
>>51516880
Honestly I would use Python. It seems simple enough to do in bash, but I think it falls more in the domain of Perl/Python/Ruby than in shell scripting.
>>
>>51516907
Functional programming is fundamentally ingrained into computer science. Things like computability theory and type theory would be nonsensical if the models had side effects and weren't pure like lambda calculi.
>>
>>51516316
Okay, this might be a really really dumb question but, why are your imports in your main?
>>
>>51516605
What anime specifically? I didn't know they had an anime on Erlang.
>>
>>51516940
>I'm wondering if there's anything faster
Are you having performance problems that you can pin on this bit of code?
>>
File: 1416064879504.jpg (90 KB, 797x810) Image search: [Google]
1416064879504.jpg
90 KB, 797x810
>>51516707
>>51516674
These two work but I'm wondering if there's anything faster, might have to implement binary search like >>51516623 mentioned or use bisect.bisect in some way

thanks btw
>>
>>51513512
java
>>
>>51516907
If you are studying computer science and refusing to learn about functional programming, you're an idiot. The imperative and functional perspectives have been around since the formalization of computer science, with Turning's Turing Machines and Church's Lambda Calculus. You should really take the time to understand both. If you don't, you'll be a worse programmer, and a worthless computer scientist.
>>
>>51516969
What do you like about Java over C#?
>>
>>51516953
>>51516964
Yep, just using %timeit in ipython and the runtime seems to blow up for large amounts of numbers to be binned or large amounts of bins.

That's for my implementation, though and >>51516707
might be quite a bit faster, gonna check right now.
>>
Would you rather be prone to premature optimization, or premature ejaculation?
>>
>>51517015
According to most people, I already prematurely optimize (plus I have good stamina in bed) so I'll stick with what I've got.
>>
File: d3.png (55 KB, 1034x716) Image search: [Google]
d3.png
55 KB, 1034x716
now it uses a higher order function

>>51516944
So they stay in my main
>>
>>51516940
Ah, just remembered it; your mention of bisect gave it to me. Given that you have the bins list in order (or if not, that you can sort them quickly enough with built in methods), I would suggest bisect_left.

from bisect import bisect_left
bins=[0,2.5,10,11,20]
brrr=lambda bins,n:bisect_left(bins, n)-1
print(brrr(bins,4))
>>
>>51516952
I have no idea.
I've watched one anime in my life and that was Black Lagoon or something, because a friend pretty much forced me.
If you consider stuff like pokemon and dragon ball Z an anime I guess that too, but that was when I was in elementary school, so I just consider them "cartoons that were on TV".

I don't really watch cartoons as an adult. Maybe stuff like Rick and Morty, American Dad, or mostly the Simpsons because I grew up with the Simpsons as well, but that's about it.

I was just making playful banter on how you should off yourself for a language I actually know nothing about.
>>
>>51517049
You do realize that the get() call is a monstrosity right?
>>
>>51517065
By the way, this is the most honest post you'll ever get from me. I'm drunk and I need to be up in less than 6 hours for work, yet the cocaine is saying "you should finish this rock!". So, good night, I'm going to force myself into bed.
>>
>>51517071
you're right
i've converted it to

("https://a.4cdn.org/" ~ board ~ "/thread/" ~ thread ~ ".json").
get

thank you for pointing out this failure
>>
So lua has this thing called the registry, not sure what it entirely does. But I see it has the code:

/* variable with an unique address */
static const char Key = 'k';

/* store a number */
lua_pushlightuserdata(L, (void *)&Key); /* push address */
lua_pushnumber(L, myNumber); /* push value */
/* registry[&Key] = myNumber */
lua_settable(L, LUA_REGISTRYINDEX);

/* retrieve a number */
lua_pushlightuserdata(L, (void *)&Key); /* push address */
lua_gettable(L, LUA_REGISTRYINDEX); /* retrieve value */
myNumber = lua_tonumber(L, -1); /* convert to number */


I think I get what this is saying, I might not, so I would like to get a better understanding.

So can push a string (does it have to be a string) onto a table, and have it equal to something (such as a number, can it only equal a number/string?)

Is this something that might work with an entity component system? Is this similar to metatables? Do you need both to coexist? Is one better than the other or are they too different to say?
>>
how does setf in common lisp work?
like why does set-x/y-velocity work but not reset-velocity?
(defmethod set-x-velocity ((me moveable-entity) xvel∆)
(setf (slot-value me 'xvel) (+ (slot-value me 'xvel) xvel∆))
me)

(defmethod set-y-velocity ((me moveable-entity) yvel∆)
(setf (slot-value me 'yvel) (+ (slot-value me 'yvel) yvel∆))
me)

(defmethod reset-velocity ((me moveable-entity))
(set-y-velocity me 0)
(set-x-velocity me 0)
me)
>>
File: d4.png (30 KB, 662x681) Image search: [Google]
d4.png
30 KB, 662x681
>>51517049
>>
>>51517224
it's the most beautiful code i've ever written
it's mostly just calling someone else's code
>>
>>51517174
Well, you're persistent, I'll give you that.

The reason I told you about the registry is because it's a way to associate Lua values (functions) with C values. That way, you're able to give different objects different Lua functions to call for updating/drawing/whatever.

Integrating this with components is something else entirely, and it might not even be very useful. Typically, an ECS gives you enough flexibility that you don't need to also use scripting at that level.

Metatables aren't really useful for this, but it would be quite useful to have some sort of class system on the C side so that you can share the same Lua functions between many objects.
>>
>>51517224
It's cute how codemonkeys write glue code for other people's libraries and think they actually made something.
>>
>>51516599
learn Go instead, 12 hours is more than enough for the basics
tour.golang.org
>>
>>51517298
>he didn't write his own regex library
>he didn't write his own web fetching library
>he used language features
haters gonna hate
>>
>>51517298
Libraries are there to be used, anon.
>>
>>51517322
Importing a library is not a language feature.
It's using other people's code.

>>51517339

It's unavoidable if you want to do anything productive, but if literally all your code is just calling other people's functions, you're a codemonkey.
>>
>>51517342
>implying i would want to work as a programmer
>>
>>51517287
so in C I would need a struct with an array, and I would need a way to send information from that specific struct to lua and back?
>>
>>51512915
github link?
>>
>>51517349
I don't know what that has to do with anything.

You can just use the registry to have each object associated with a Lua table created by a constructor (also a Lua function) or something which gets passed into the update/draw functions.
>>
C is a good first language because it pretty much forces you to implement your own libraries before you can do anything useful.
>>
>>51517369
>C
>forces you to implement your own libraries
meme tier joke
>>
>>51517369
That's a reason why C is a bad first language (and isn't true regardless). You don't want new programmers to get discouraged because every task seems unapproachably complicated, and you don't want them to learn a terrible NIH mindset.

C is a good first language because it forces you to build a mental model for your code that is similar to what actually happens on a real machine. This mental model is invaluable for really understanding programming, and is the kind of thing that you might not pick up from, say, Python.
>>
>>51517409
>C is a good first language because it forces you to build a mental model for your code that is similar to what actually happens on a real machine.
This. Also, being forced to write every free() or at least call every "destructor" shows you exactly what garbage collectors have to do for you behind your back. This applies also to things like non-trivial copies, virtual function calls, etc.
>>
>>51517409
>what actually happens on a real machine
Types don't real
>>
>>51517442
>what are special-purpose registers
Thread replies: 255
Thread images: 30

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.