/dpt/ - Daily Programming Thread

Logic Programming Edition

(functional also welcome but keep OOP IN THE LOO in the pajeet general)

Old: How is Lisp for logic programming btw?

Other urls found in this thread:

mercurylang.org/
en.wikipedia.org/wiki/First-class_citizen
twitter.com/NSFWRedditImage

IGNORE THIS THREAD IT WAS POSTED PREMATURELY ON A SLOW PART OF THE DAY AND IT'S FUCKING GAY

kill yourself

>Created before the bump limit
>Shitposting in the OP
Delete this shit. I don't care if you're not the trapfag.

>How is Lisp for logic programming btw?

Use prolog like a normal human being.

kill urself cunt

fuck off tripfag, Prolog isn't even the only or even the best logic programming language, you retarded mongrel

What are some real world uses of Prolog or logic programming in general? I know Nokia used Prolog for the N900/Maemo5 process scheduler

What's the best one?

>What are some real world uses of Prolog or logic programming in general?
makes you even more smug then haskelel

>What are some real world uses of Prolog or logic programming in general?

From what little exposure I've had to it, I find it very elegant/simple. You're just stating facts and deriving things from these facts.

>tfw you fix your C++ code by turning it into C code

my only real mistake was falling for the STL containers meme.

Am i fucking retarded for not getting this?

Say we have an array a = [1,5,7,9]
length is n = 4
for(i = n - 1; i > 0; i--){
do something
for(j = i - 1 ; j >= 0; j--){
do something (x)
}
}

How many times will the line on X be executed (with n a random array length). Is it (n-1) * (n-1).
A friend of mine said it was (n(n-1)) / 2. But I don't see how that can be correct.

>lapishit posters can't even quote the right posts

a bird mom poster would never do this

N-queens problem

i can play the spamming game too fucking cancerous smug fag

Damn, I just clicked a random post to get a quick reply window.

you are retarded.
Its simply nested loop.

4 times 4 do somethings.its n^2 thats it.

Dont let you confuse yourself by that n-1. Its simply because the first index is 0 instead of 1.

Outside executes n - 1 times (ex: n = 4, executes for 3, 2, 1 = 3 times). Inside executes i times (ex: i = 5, execute for 4, 3, 2, 1, 0 = 5 times). Taking into acount that i is the current n - 1, then for n = 6, for example, you'd have

n = 6, i starts at 5
i = 5 && j will go from 4 to 0 (= x5 executions) || outter loop x1 = inner loop x5 = line x5
i = 4 && j will go from 3 to 0 (= x4 executions) || outter loop x2 = inner loop x4 = line x4
i = 3 && j will go from 2 to 0 (= x3 executions)| | outter loop x3 = inner loop x3 = line x3
i = 2 && j will go from 1 to 0 (= x2 executions) || outter loop x4 = inner loop x2 = line x2
i = 1 && j will go from 0 to 0 (= x1 executions) || outter loop x5 = inner loop x1 = line x1
total amount of executions of that line: x15

it's easy to spot the relationship (just imagine the pattern - n = 5 is n = 6 minus the first line, so x4 + x3 + x2 + x1, and the same strategy applies if you increase n instead of decrementing it): 1 3 6 10 15 21 etc, which are the triangular numbers with the n triangular number being n*(n-1)/2 (proving this is easy but falls outside the scope of this discussion)

oops, last line should be n*(n+1)/2

so neither of you is right

What is this image from?

shit, second correction: the triangular numbers are n*(n+1)/2, yes, but I mixed up the variables: your sequence is shifted (n = 6 is 15, which is the 5th triangular number)

so replace the formula for the triangular numbers with k*(k+1)/2, knowing that k = n - 1, substitute and you get (n-1)*n/2 like your friend said

>get told to learn C as my first language
>wanna study EE so that makes sense
>The only programming I've done was some basic stuff on Python during GCSE (loops, tables, displaying images)
>look through recommended book, only find one (Head First C)
>begin the first exercise
>errors all over
>all this shit I don't recognize
>only thing I could run properly was "Hello World"
Fuck help me Sup Forums. Should I just piss off and learn JavaScript first or something?

Are you sure? If i put n = 1, i would be 0, so nothing would get executed. However using your fomula it would get executed 1 time. Using the other formula it'd be 0.

>learn JavaScript first or something?
Yes.

Fellow EE here

Don't worry. Most EEs are absolutely retarded about programming for some reason. You'll fit right in in the industry.

see my correction I kind of mixed up the variables I was using

You're not going to get it instantly, it takes some practice to internalize a language. But keep going at C, you don't have to master it just understand how programming works. Also, don't expect to be able to program without having to look at references constantly, nobody remembers every single language's syntax and standard library by heart.

The inner loop gets evaluated i times with i from 1 to n - 1. So it's pic related which is a known sum ("Kleiner Gauß" sum_{ i = 1 }^n = n(n+1)/2 ).

>nobody remembers every single language's syntax and standard library by heart.
False! I am superiorly aware of my own Scheme's internal implementation and standard library, as well as of its beautiful, elegant & simple syntax.

C is where you begin to study the languages as a real man. Python and JS are for babies.

Also, get Kochan.

Reread what I wrote
>nobody remembers EVERY single language's syntax and standard library by heart.

Ask someone for help.

>my scheme implementation is "every single language"
Why are schemers so illiterate?

learn haskell dude

Where can I read about what visual studio puts as its default clear values for debug?
I get:
îþîþîþîþîþîþîþ
and I think I'm having a heap corruption and VS is being most unhelpful, only giving me a (very) small piece of assembly and a pointer to where the illegal access was.

Not sure how to debug this properly..

int main(void)
{
_Static_assert(__alignof__(long) > __alignof__(char), "non-pathological");
(void)(long *)__builtin_assume_aligned((char *)__alignof__(char), __alignof__(char));
// Why doesn't this trigger any warnings?
}

Well, of course no one knows every single language's syntax (because many "languages" - most of them, in fact - are not even worth knowing in the first place), so that's not an interesting fact to discuss. I'd rather discuss whether or not it's possible to know an entire language and at least an implementation by heart, and it turns out that it's possible for some languages (real languages) and impossible for others (Cshit, Cshit++, etc)

Don't you ever fucking quote my posts again if you're going to talk of that meme language

How do you Sup Forumsuys feel about this

>Prolog isn't even the only or even the best logic programming language

I didn't say either of those things. Learn to read.

Ok so I found that it's a procedure in nvogl32.dll.
So I'm probably doing something wrong with my vertex buffer.
No worries dudes. I got this.

just read a book, nigger. apps for learning stuff are never good.

/dpt/-chan, dai suki~

Ask your much beloved programming literate anything (IAMA).

It has been proved that prolog is a dead end (by the fifth computer generation project and by the guy who invented the actor concurrency model).

>What's the best one?
mercurylang.org/

>actor concurrency model
That's literally just Scheme, f'am.

t. The Sussman

What's the deal with cmake

// This is OK too.
(void)(long *)(void *)(char *)__alignof__(char);
GCC is trash.

laughingbitches.jpeg
>does not know haskell

wtf dude
just use Atom, vim, vs code, emacs, etc

vs code provides intellisense

OP didn't as about your opinion on Prolog either your insufferable faggot.

Why would I waste my time learning a shitty meme language? If I really needed to get my ML fix, I'd use OCaml, thank you very much.

Now shoo, shoo memeposter!

How's IronPython, PS a shit

Great way to sell your shitty habits to advertisers, just to learn syntax

What if I want a job OP?

>GCC is trash.
>implying you could right a compiler

shyddydoo

it's probably easier than you'd think even for a full-fledged compiler

Most CS degrees teach you how to write a compiler

So the OOPfags apparently created their own thread lmao

kys

If I have a program where I don't free malloc'd memory before exiting, when it exits, is the memory that was allocated available to the OS again?

depends on the OS but yes

yes

no, it's lost forever; don't do it, or you'll have to buy more rams

no you have to start up the program and free up the memory for it to ever be available again

Yes.

Yes. The kernel knows what memory every process has allocated and will free it automatically once the process is terminated. However, you should still force yourself to free every allocated bit of memory as soon as possible. Once your program becomes some subroutine of a bigger program you will fuck things up and leak memory like a motherfucker.

Basically any OS except DOS does this

>Once your program becomes some subroutine of a bigger program
cucked hard

Niggas I need some help with R I also asked /sci/ and /sqg/ but no help so far:

Anyways I saved a lot of data frames in nested lists.
I know I can access my values with mylist[[1]][[1]][2,2]
for the value in cell 2,2 but I wanna save all [2,2]s of all nested list as a vector or list in a variable.
How do I do this?
With normal lists I'd do this
variable

Learn how to write.

>However, you should still force yourself to free every allocated bit of memory as soon as possible.
No, you should do it as late as possible (preferably not at all if you can get away with it) because freeing memory is a very costly operation.

Don't talk to me or my child process ever again.

Racket lisp implemented Prolog, Datalog, a lisp-like Prolog called Parenlog, and Kanren. Racket treats languages as libraries and modules, which means you can freely intermix purely logical modules of code with regular Lisp code in your preferred style.

lisp is truly God's gift to mankind

Well, okay, assuming available memory is not a problem then of course. But you should really free it yourself or you might regret it sooner or later.

How and why?

Not that user, but freeing and allocating memory involves asking the kernel to free and allocate memory. That takes some time. So you always want to keep the number of mallocs and frees as low as possible. I.e (just assume this example makes any sense)

const size_t N = 100;
int *test[N];

for ( int i = 0; i < N; ++i )
{
test[i] = malloc ( sizeof ( some_struct_t ) );
some_function ( test[i] );
free ( test[i] );
test[i] = NULL;
}

That is shit. Better is:

const size_t N = 100;
int *test = malloc ( N * sizeof ( some_struct_t ) );

for ( int i = 0; i < N; ++i )
some_function ( test[i] );

free ( test );
test = NULL;


It seems obvious here to do latter, but it may not seem obvious otherwise. So it's not really about when you allocate and free but how often you allocate and free. If you have a large chunk to free at the beginning of a program that you won't need further, then you should of course free it however. Makes no sense to keep it allocated then.

It's easy as shit to program AI in it. Also it's easy do deal with linguistics in this manner.

Is it wise to learn Haskell for fun and C++ for work?

Yes. Learning haskell makes you a better c++ programmer

It is wise to learn everything you like and as much as you can, but keep in mind that you also have to organise your time.

>ImportError: /usr/lib/python3.5/site-packages/nacl/_sodium.cpython-35m-x86_64-linux-gnu.so: undefined symbol: crypto_sign_ed25519_pk_to_curve25519

Wat do?

>make a program that uses only ints
>get a floating point exception

why does literally everything in my life only get worse

I understand that asm.js is purely for writing the algorithmic part of your application because there's no way to interact with the dom, but how are you supposed to interact with the js part?

Do I have to cook up some shit-tier message passing system?

The best course of action would be to kill yourself.

Is this a troll?
Yes, which is why I decided on only Haskell and C++.

Using Powershell is literally like hammering nails into your balls. I'm trying to return a string from a function and it gives me the object type

Man, you're bad at this. Read there manual or spend five minutes reading a tutorial.

Yeah, read a tutorial to figure out why my function can't just return my string

Are you, or are you not, using the appropriate attributes?

Figured it out, had to uninstall PyNaCl, install libsodium systemwide and reinstall PyNaCl with SODIUM_INSTALL=system pip install pynacl

No, you should use a modern language that doesn't require you to manually allocate memory

Why do you always get rekt so hard? Are you simply retarded?

NEW THREAD WHEN?

imagine i have this function


int test(int array[4], bool flag);

can i pass the array in the argument when calling ?
like

test({1,2,3,4}, false);

?

If you don't know how to do that, then yes, obviously.

no, this isn't javascript.
in C, arrays and functions are not first class, you have to pass them as pointers.

>class
C has no classes, dip

int test(std::array, bool flag);
should work

int test(int *array, char flag);
...
int arr = {1, 2, 3, 4};
char flag = 0;
test(arr, flag);

en.wikipedia.org/wiki/First-class_citizen

not what he meant by first class

You are being baited.

how's the .22 rifle ?