/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

python.org/dev/peps/pep-0008/#tabs-or-spaces
srfi.schemers.org/srfi-119/srfi-119.html
en.wikipedia.org/wiki/Summation#Capital-sigma_notation
twitter.com/NSFWRedditGif

Working on a roguelike, just started. Feel like I'm stressing too much about the architecture but I don't want to regret choices later.

2nd for Tk

Trying to decide between using Scheme and Idris for making a game

Scheme more practical.

There was a big lisp-vs-haskell debate in the previous thread, you might be interested

rolling for one of these cause i'm bored

I couldnt wrap my tiny brain around postfix notation until I wrote in FORTH.
Thanks, FORTH.

I hate programming more and more every day.

What languages/libraries/tools are you using? Can you try different ones?

Thanks, I guessed that, but no static typechecking makes me super uncomfy and nervous.

Stop using languages and libraries that are a net pain in the ass. Stop working as a code monkey. Work on different projects. Stop programming for a while, stop programming forever.

Etc.

I start an HPC workshop this week so I'm brushing up on my C.

The only time I genuinely hate programming is
A) Working in Java for just about anything. It's just a flat out unpleasant language to work in and the lack of pointer manipulation in an OOP language is fucking obnoxious.
B) Working in Python, because it's too easy to break the entire program on a syntax error that's reported 50 lines after the fact

>Working in Python, because it's too easy to break the entire program on a syntax error that's reported 50 lines after the fact
Do you get that with other dynamic languages too?

No, because including an extra space on a line doesn't cause the program to explode.

Oh, yeah. I'd forgotten Python did that.

Use OCaml. It's very practical.

rollan for an easy one

My minecraft clone uses Scheme.

It's not a big deal since you don't have to compile it. There's no implicit conversion so you don't have to deal with subtle bugs like you do in Javascript or PHP.

roll

Never worked with python. You mean something like including an extra space at the end of the line, or between commands, outright breaks a program?

what exactly am I expected to make
it's an interesting law, but what's to be done with it in terms of programming?
re-roll

Python uses Whitespace as part of its syntax, so if you're not paying attention and accidentally brush the space bar you can unexpectedly fuck everything up, and about half the time it's really bad at reporting what line has the mystery space on it.
It's the only language I know of where having leading "whitespace marks" like you'd see in a Word document is useful.

Out of curiosity how does python handle spaces vs tabs? I use a tabstop of 2 and sometimes mix spaces in, even when I write C code.

Sounds worse than batch's handling of if / else and parenthesis.

python.org/dev/peps/pep-0008/#tabs-or-spaces
Officially you're supposed to use spaces (which is a terrible, terrible idea)
In v3 mixing them will break the program completely
In v2 it's allowed, but you will constantly fuck yourself in the ass doing so.
Basically its fucked up and whatever editor you're using you should have it auto-replace tabs to spaces or vice versa.

For what god-forsaken purpose are you still using batch scripts

Ruby, will you still be able to browse Sup Forums when you do your PhD?

>no unsigned type
>no native threads

Rate my kode:
define : factorial n
__ if : zero? n
____ . 1
____ * n : factorial (- n 1)

display : factorial 5
newline

srfi.schemers.org/srfi-119/srfi-119.html

>Officially you're supposed to use spaces
>In v3 mixing them will break the program completely
Ewwwwwww.

So say you have a function with a lot of arguments, do you just have to let it word wrap rather than part of it go on a new line?

disgusting

To some extent, yes. I try to allocate some time out of my day where I do nothing productive and just veg.

>do you just have to let it word wrap rather than part of it go on a new line
Oh that's the best part. The official spec is to limit all line length to a maximum of 79 characters.
And there isn't any defined way to handle line continuation, so you get

if (this_is_one_thing and
that_is_another_thing):
do_something()
or
if (this_is_one_thing
and that_is_another_thing):
do_something()
or even
with open('/path/to/some/file/you/want/to/read') as file_1, \
open('/path/to/some/file/being/written', 'w') as file_2:
file_2.write(file_1.read())

What lines are part of the previous statement and which are the actual next times? Who the fuck knows! We chose the worst syntax structure imaginable!

>Working in Java for just about anything
This so much. Java is one of the worst languages I ever had the displeasure to learn. Any time I had to write code in it, my desire to program diminished further and further.

Java 8 is a significant step up from 7 and earlier, but it's still much less nice than many other languages.

I wish programmers had refused this shit from the beginning. Lisp was robbed, ML was robbed, and now we're stuck with tedious, mediocre garbage.

>For what god-forsaken purpose are you still using batch scripts
I was once inspired by a batch script, and therefore wrote my own version in batch. Although I try to tell myself there can be freedom and ease in greater limitation, I often ask myself the same question.

It's a file optimizer script, and pretty solid though. The best I know of, that's publicly available anyway. It's sitting on a hard drive I don't feel like gaining access to (no machine that has SATA ports). I might do a bash rewrite eventually.

>I wish programmers had refused this shit from the beginning
The people who adopted it were the ones looking to crank out an application fast and cheap. Java was a huge pioneer in what it started because you didnt have to worry about memory safety and it was pretty dang easy to write comparatively speaking.
The only reason it's still used now is because of JVM portability, but hopefully that'll slowly die off with some help from LLVM and the CRE from MS.
C# isn't nearly as fast as Java is right now, but it basically fixes every aspect of Java that makes it so goddamn unbearable to work with (Including an unsafe block that allows pointer manipulation)

What did you do your masters in? I'm looking at starting some graduate work but I'm still unclear on the whole process and how people select a thesis topic and whatnot.

>Java was a huge pioneer in what it started because you didnt have to worry about memory safety and it was pretty dang easy to write comparatively speaking.
I think Lisp had both of those qualities way before Java did.

>C# ... basically fixes every aspect of Java that makes it so goddamn unbearable to work with
I disagree. C# is still boilerplate heavy and not very amenable to non-trivial abstraction.

How do you generate the maps?

This

Are there external static typecheckers?

I'm pretty sure it's in Hospitality and Tourism.

Java allowed for GUI's to be made easily, OOP was popular at the time, and it was shilled hard by a large company (Oracle).

Meanwhile Lisp had lost ground on AI, and nobody really cared about popularizing it.

>Lisp
Maybe, but lots of theoretically-great languages don't catch on for a lot of reasons. Java is much more "friendly" to write to most people.

>C# is still boilerplate heavy
In the sense of you still have shit like
public int num { get; set; }
public int num2 { get; set; }
public List list = new List();
public static void main(string args[]) { //blah }
Then sure. But it has waaaaay more compact accessors and implementation/inheritance systems.

>and not very amenable to non-trivial abstraction
explain

>shilled hard by a large company (Oracle).
Ah, of course.

It was shilled by Sun. Sun got bought out after Java became big.

did it twice for shit's and giggles

(define (slowfib x)
(cond ((= x 0) 0)
((= x 1) 1)
(else (+ (slowfib (- x 1)) (slowfib (- x 2))))))

(define (fastfib n)
(let ((x 0) ;return value
(z 0) ;fib of x-1
(t 0) ;temp value
(c 0)) ;counter
(fastfib-helper n x z t c)))

(define (fastfib-helper n x z t c)
(if (= x 0)
(begin
(set! x 1)
(set! c (+ 1 c))
(fastfib-helper n x z t c))
(if (not (= c n))
(begin
(set! t z)
(set! z x)
(set! x (+ t x))
(set! c (+ 1 c))
(fastfib-helper n x z t c))
x)))

scheme@(guile-user)> (fastfib 10)
$8 = 55
scheme@(guile-user)> (fastfib 100)
$9 = 354224848179261915075

Not really worrying about that yet. My focus on this project is trying to make a good planning based AI since that's what I feel like is the only unique thing I might be able to offer.

It might even be mostly a fixed overworld where the focus is on interacting with NPCs.

What are your ideas?

Stylizing some code for a presentation

nice

Essentially I'm trying to make a variation of a STRIPS-style planner that uses a utility function rather than goal states. It's basically going to be a best-first search on a graph of state transitions where the edges are actions... I think. But I'm not sure. The goal is to only use planning on higher level things in a hierarchy and then do lower-level stuff like pathfinding in a more or less hard-coded fashion (but the results of pathfinding might factor into costs on the graph).

Kind of hazy at the moment, but I'm going to stop worrying about planning the whole thing before I have any code written, and start writing the basics every roguelike needs and work from there.

>
Is that html?

Wow I suck at this
#include
#include

#define POINT_A1 6, 1
#define POINT_A2 4, 5
#define POINT_B1 2, 0
#define POINT_B2 3, 2


typedef struct {
int x, y;
} Point;

typedef struct {
Point a, b, c, d;
} Rectangle;

Rectangle newRectangle(const Point a, const Point c) {
Rectangle out;
out.a = a;
out.b = (Point) { a.x, c.y };
out.c = c;
out.d = (Point) { c.x, a.y };
return out;
}

Point *getDiagonal(const Rectangle r) {
Point *out = malloc(2*sizeof(Point));
if (r.a.x < r.c.x) {
if (r.a.y < r.c.y) {
out[0] = r.a;
out[1] = r.c;
} else {
out[0] = r.b;
out[1] = r.d;
}
} else {
if (r.a.y < r.c.y) {
out[0] = r.d;
out[1] = r.b;
} else {
out[0] = r.c;
out[1] = r.a;
}
}
return out;
}

int main () {
Rectangle a_Rectangle = newRectangle((Point) { POINT_A1 }, (Point) { POINT_A2 });
Rectangle b_Rectangle = newRectangle((Point) { POINT_B1 }, (Point) { POINT_B2 });

Point *a_Diag = getDiagonal(a_Rectangle);
Point *b_Diag = getDiagonal(b_Rectangle);

if ( a_Diag[0].x > b_Diag[1].x ||
a_Diag[0].y > b_Diag[1].y ||
a_Diag[1].x < b_Diag[0].x ||
a_Diag[1].x < b_Diag[0].x ) {
printf("The two rectangles don't overlap.\n");
return EXIT_SUCCESS;
}
printf("The following points define the diagonal line of the overlapping rectangle:\n");
printf("( %d, %d ) ( %d, %d )\n",
a_Diag[0].x > b_Diag[0].x ? a_Diag[0].x : b_Diag[0].x,
a_Diag[0].y > b_Diag[0].y ? a_Diag[0].y : b_Diag[0].y,
a_Diag[1].x < b_Diag[1].x ? a_Diag[1].x : b_Diag[1].x,
a_Diag[1].y < b_Diag[1].y ? a_Diag[1].y : b_Diag[1].y);

free(a_Diag);
free(b_Diag);
return EXIT_SUCCESS;
}

Holy shit how did it not occur to me that it looks like HTML... this is bad ...

rolling for gf

>4 points to define a rectangle
You can easily do it in 2.

Rectangle newRectangle(const Point a, const Point c) {


???

Yes, but the actual definition still has 4.

Now do it with lazy infinite recursion (delay and force).

I'm a plebeian when it comes to scheme and I understand none of what you want me to do

Eh, it's a simple enough change I suppose
#include
#include

#define POINT_A1 6, 1
#define POINT_A2 4, 5
#define POINT_B1 2, 0
#define POINT_B2 3, 2


typedef struct {
int x, y;
} Point;

typedef struct {
Point a, c;
} Rectangle;

Point *getDiagonal(const Rectangle r) {
Point *out = malloc(2*sizeof(Point));
if (r.a.x < r.c.x) {
if (r.a.y < r.c.y) {
out[0] = r.a;
out[1] = r.c;
} else {
out[0] = (Point) { r.a.x, r.c.y };
out[1] = (Point) { r.c.x, r.a.y };
}
} else {
if (r.a.y < r.c.y) {
out[0] = (Point) { r.c.x, r.a.y };
out[1] = (Point) { r.a.x, r.c.y };
} else {
out[0] = r.c;
out[1] = r.a;
}
}
return out;
}

int main () {
Rectangle a_Rectangle = (Rectangle) { (Point) { POINT_A1 }, (Point) { POINT_A2 } };
Rectangle b_Rectangle = (Rectangle) { (Point) { POINT_B1 }, (Point) { POINT_B2 } };

Point *a_Diag = getDiagonal(a_Rectangle);
Point *b_Diag = getDiagonal(b_Rectangle);

if ( a_Diag[0].x > b_Diag[1].x ||
a_Diag[0].y > b_Diag[1].y ||
a_Diag[1].x < b_Diag[0].x ||
a_Diag[1].x < b_Diag[0].x ) {
printf("The two rectangles don't overlap.\n");
return EXIT_SUCCESS;
}
printf("The following points define the diagonal line of the overlapping rectangle:\n");
printf("( %d, %d ) ( %d, %d )\n",
a_Diag[0].x > b_Diag[0].x ? a_Diag[0].x : b_Diag[0].x,
a_Diag[0].y > b_Diag[0].y ? a_Diag[0].y : b_Diag[0].y,
a_Diag[1].x < b_Diag[1].x ? a_Diag[1].x : b_Diag[1].x,
a_Diag[1].y < b_Diag[1].y ? a_Diag[1].y : b_Diag[1].y);

free(a_Diag);
free(b_Diag);
return EXIT_SUCCESS;
}

#lang racket

(define (in-fibs [a 1] [b 0])
(stream-cons a (in-fibs (+ a b) a)))

(for ([i (in-range 30)]
[f (in-fibs)])
(printf "fib #~a = ~a\n"
(add1 i)
f))

Negro why do you have so many variables and why are you using set! everywhere?

Can you guys tell me what's the most effective way to learn data structures and algorithms? What are some good resources for a beginner?

>Negro why do you have so many variables and why are you using set! everywhere?
I have no idea what I'm doing desu senpai

It was fun to see peoples solutions last time, so:

Given an integer input, print the following shapes:
* *
* *
*
* *
* *

* ***
* *
* *
*****
* *
* *
*** *

and do what with the input?

CLRS is a good book

This dumb. What does the integer signify? Does 0 mean to print the X and 1 mean print the 卐?

If the input was 5, those shapes would be printed like that.
If it were 7, it would print the same shapes at a different size.

I've looked at that one and it has mathematical notation which I can't understand, though if you could point me in the right direction as to where I could start understanding it, it'd be much appreciated.

Anyone know how i can map out the memory of a running program in windows using c++ do I use readprocessmemory or? Also I need to map a program that isn't mine

> it has mathematical notation which I can't understand
Take some calculus courses, summation is very very important in algorithms.

kek


out1 = ["* *\n * *\n *\n * *\n* *","* ***\n* *\n* *\n*****\n * *\n * *\n*** *"]
out2 = ["* *\n * *\n * *\n *\n * *\n * *\n* *", "* *****\n* *\n* *\n* *\n**********\n * *\n * *\n * *\n****** *"]

main = do
i

>mathematical notation
Are you talking about big-O notation?

whoops, that should be

mapM_ putStrLn

B-but look how pretty fizzbuzz is user! /s

say "Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100
Perl shits on python.

No, I looked on the inside of it and it had some sigmas and some other shit thrown in there I know nothing about.

Never got to calculus, but I'll work my way up and wrap my head around it, guess I have to, does it have to be advanced calculus? Thank you for the reply too, even if I'm only being able to get a sense of direction it helps alot!

>pretty

Delay and force are ways of making and getting so called promises. Basically packing data into a promise means you won't evaluate it until you "force".

Delay can be a macro that converts
(delay x)

to
(lambda () x)


And force can be a macro that converts
(force x)

to
(x)

If you define a macro stream-cons to convert
(stream-cons a b)

to
(cons a (delay b))

defined as
(define-syntax stream-cons (syntax-rules () ((_ a b) (cons a (delay b)))))

And a function stream-cdr:
(define (stream-cdr stream) (force (cdr stream)))
(define (stream-ref stream n) (cond ((= n 0) (car stream)) (else (stream-ref (stream-cdr stream) (- n 1)))))

You can create infinite lists like so:
(define ones (stream-cons 1 ones)
(stream-ref ones 1000) ;=> 1

Computer Science. My research was in cybersecurity. Your thesis topic is something you'll probably end up deciding with your advisor. To get into grad school, you just need good letters of recommendation and good GRE scores. Once there, whatever you need help on, talk to your advisor about.

>advanced calculus
Ehhh, not really. Vector calculus and multivariable dont really play into CS too much.
The important part is understanding and recognizing Summation patterns and how to manipulate them for calculations, and understanding how derivatives and integrals work.

en.wikipedia.org/wiki/Summation#Capital-sigma_notation

Sounds awesome desu, good luck and keep us updated!

Rubester, which languages did you do in undergrad?

what the hell
i've got a long way to go in learning scheme it seems

Just one more thing, is lambda calculus related? Like if I did the little schemer would that help?

>you're LITERALLY posting on the same thread as the people who doesn't know sigma summation notation
>these are the people that are giving you programming advice
Truly shocked.

It's very useful to learn for a lot of functional languages or even lambda functions in OOP languages like C# (LINQ), Ruby (do blocks), or Java (lambda expressions)

Everyone has to start at the beginning.

You did too at one point.

#lang racket

(define ((shape f) n)
(for ([y (in-range n)])
(for ([x (in-range n)])
(display (if (f x y n)
#\*
#\space)))
(newline)))

(define-syntax-rule (define-shape (name . args)
body ...)
(define name
(shape (λ args body ...))))

(define-shape (cross x y n)
(or (= x y)
(= x (- n y 1))))

(define-shape (swastika x y n)
(define n/2 (quotient n 2))
(define n-1 (- n 1))
(or (= x n/2)
(= y n/2)
(and (< x n/2) (= y n-1))
(and (> x n/2) (= y 0))
(and (< y n/2) (= x 0))
(and (> y n/2) (= x n-1))))

(cross 13)
(newline)
(swastika 9)

>ah, that picture again
Have the proper old hags once again, dear user.

I worked on feeding the output of a compute shader into a regular vertex-fragment pipeline shader, to make a simple particle system. I made a compromise, which is not receiving the output of the compute shader CPU-side, however it gives me a boost in frames due to not needing to call glMapBuffer each frame.

>(define ((shape f) n)
What??

My waifu doesn't look that old!

Thanks, I'll do my best. We'll see how it turns out.

The mother-in-law looks very young for her age.

How is that a compromise? It sounds like exactly what you should be doing.

I think you might've missed the "pretty" in that comment.