/dpt/ - Daily programming thread

What are you working on?
Previously

Other urls found in this thread:

youtu.be/4tyTgyzUJqM
github.com/yglukhov/nimx
nim-lang.org/
learnxinyminutes.com/docs/python/
strawpoll.me/15098544
love2d.org/wiki/flat_table
edx.org/course/introduction-computer-science-mitx-6-00-1x-11
automatetheboringstuff.com/
krautplausch.hopto.org/te/vote/index.php
krautplausch.hopto.org/te/vote/show.php?id=zmmhbypzrw
en.wikipedia.org/wiki/Region-based_memory_management
nim-lang.org/docs/gc.html
ucsd-progsys.github.io/liquidhaskell-blog/2016/09/18/refinement-reflection.lhs/
pathsensitive.com/2018/01/the-benjamin-franklin-method-of-reading.html
docs.oracle.com/javase/specs/jls/se9/jls9.pdf
twitter.com/NSFWRedditImage

OP is a fag

First for Nim.

Trying to make a C++ VLA class by hacking the ABI with embedded assembly. What's the stack structure when initializing/freeing a class?

Any advise for learning java? I'm new to programming and my professor is ass at explaining anything

>Any advise for learning java?
Don't.

Have to. It's part of the program

>It's part of the program
Good goy. Just do as you're told. Go along with the program. Learn your Java.

This is pretty much mandatory for every program you write in java:
public class [filename here]{
public static void main(String[] args){

}
}
The class's name must be the filename; otherwise, javac refuses to compile your code.
Learn when to use static and when not to, as you'll otherwise be using a lot of trial and error on your code, trying to figure out where it's needed and where it buggers up your code.
Java is anal-retentive about classes and everything being object-orientated.

How often to you figure out how to make something work after a few hours of pounding your head on the table and when you do finally figure it out it turns out to be such a simple solution that you facepalm?

A lot...

How the fuck do you append a string to a stringstream?
import streams

var x = newStringStream("hello \n")
x.write(" world\n")
var line = ""

discard x.readLine(line)
echo line
discard x.readLine(line)
echo line

perhaps you guys will help me. i'm not good at this stuff

I thought )))))))))-syndrome only happened on Lisp
I was wrong

I mean, that's what learning's about. This is literally the only way to make progress in any field. First you don't know something, then you deliberately spend time and resources on exploring just outside your area of competence, and at the end your knowledge is greater than it was before.
You should be happy every time this happens. You should be concerned any time this isn't happening.

Would you happen to be learning Caml from a retarded teacher?

I wish I wasn't such a brainlet. m͟
>tfw can't understand Haskell

Personally, I prefer the })})})})}) of JavaScript.

Lol, but a functor is just a category in the monoid of endomonads, what's so hard about that?

W͟H͟Y͟ ͟I͟S͟ ͟H͟A͟S͟K͟E͟L͟L͟ ͟S͟O͟ ͟H͟A͟R͟D͟

You're just reading from the end of the stream, because that's the position after you're done writing. Go back go the beginning:
import streams

var x = newStringStream("")
var line = ""

x.writeLine("foo")
x.writeLine("bar")
x.writeLine("baz")

x.setPosition(0)

discard x.readLine(line)
echo line
discard x.readLine(line)
echo line
discard x.readLine(line)
echo line

Unportable UB ridden shit.
Trash it now.

Would you believe me if I said it's from C++?

it's pretty much )})})})})
because of nested lambda and function call

>Would you believe me if I said it's from C++?
No. Lrn2operatorprecedence

Don't give a shit about portability. GCC and Clang both use the same ABI. All I care about is whether optimization flags can fuck everything up.

bullshit. the class name does not need to be the file name. it doesn't even need to have the .java extension. stop learning programming by pressing every key until it works.

please? i don't know what went wrong

>whether optimization flags can fuck everything up.
This should be obvious.
Whatever you're doing is definitely UB.

Looks like you haven't defined curl_global_init, curl_easy_init, curl_easy_setopt, curl_easy_perform, or curl_easy_cleanup. Just define them and you should be good, you've got this man :).

that's the job of curl.h

a some_function() {
obj = a();
return obj;
}


lets say a takes up 20 bytes, and I do the following:

a obj = some_function();


will 20 bytes be freed when leaving the method or will 40 bytes be used?

In ncurses, is there a good way to change field names without having to pass around pointers to the standard window?
Basically I've got a label for a field set, but because this interface is laying on top of a multi-threaded application, the only clean way I've figured out how to refresh that label on a certain event is to basically have another thread running with pointers to the main subwindow and the standard screen itself, and will clear the label and rewrite it on a certain event.
However it's messy as fuck and god only knows I'm begging for some convoluted race condition doing it this way

>obj = a();
>a obj = some_function();

In the worst case, you'll be returned a copy but the original will be destroyed. That doesn't mean your code is correct - you need to follow the rule of 3 (or 5).

Aside from the fact that logic makes 0 fucking sense, if it's garbage collected (I assume java) then once all references to the previous object are gone, it'll be freed.

>the class name does not need to be the file name
>test.java:1: error: class Hello is public, should be declared in a file named Hello.java

>it doesn't even need to have the .java extension
>error: Class names, 'test.txt', are only accepted if annotation processing is explicitly requested

The booklet from which I was taught at Uni says that the filename should be exactly the same as the class name, with the word "exactly" in bold.
I even just tried compiling test code with a differing filename and file extension, and the compiler wasn't having any of it.

>stop learning programming by pressing every key until it works
If I keep at it, I'll write the entire works of Shakespeare using this method.
In all seriousness, I never learned how to properly use "static" so I was always floundering about, trying all combinations until it worked; hence, I thought it pertinent to mention that it's something worth learning.
I still haven't learnt it, only because I don't write Java any more.

Writing shell scripts count as programming?

depends, if the language supports return value optimization.

Assuming C++, which seems to be the likely candidate here.

>I am retarded

How do I do basic graphics in either C or ARM assembly on a raspberry pi?

Like on any computer: SDL2.

Depends.
Are you using X11/Wayland or are you trying to do it without any of that?

What even are those?
Ideally I want to do it from scratch

somebody PLEASE just give me QEMU's Cirrus VGA driver's VBE 2.0 settings for a 1024x768x16 setup with a linear memory buffer and page flipping

>Ideally I want to do it from scratch
The "from scratch" way is probably about 20 times harder than using a library like SDL2/GLFW.
I know; I've done it.

>Ideally I want to do it from scratch
There's no doing it from scratch as soon as you have an OS. Even in assembly, writing an empty program that terminates correctly requires a system call (and I mean it's impossible to do it without that syscall). Otherwise, you're basically asking how to make an OS.

There are different levels of "from scratch".

Damn ok well then what library is best/simplest?

Implementing C++'s ostream in Nim

What makes this better than D or Crystal? I'd imagine compiling to C is a blessing and a curse

Yes. Shell scripting is programming and web scripting is programming, despite both being relatively trivial.

>compiling to C is a blessing and a curse
Not much curse to it, man. There aren't a lot of instructions in assembly that are going to be used by your compiler that aren't available in C, or wouldn't be used by C's optimizer.

Thanks

What are you trying to do?
Are you going to use OpenGL or more simple 2D rendering?

How does rvalue and lvalue really works in C++ for a function return?
If I have a function that return by value, will that considered as rval or lval?
for example this code:
struct Foo{
int val;
Foo() : val(0){}
Foo(int i) : val(i) {}
};
struct Bar{
Foo val;
Foo get_a(){
return Foo(12);
}
Foo get_b(){
Foo temp(12);
return temp;
}
Foo get_c(){
return val;
}
};
[/code]
So Bar::get_a() obviously will return a rvalue Foo.
But how about Bar::get_b()? You can get the location of temp in the stack inside the function, and in Bar::get_c(), the location of val is also in the stack.

Why do lispers and haskellers hate each other so much?

Fuck I messed up the tags
struct Foo{
int val;
Foo() : val(0){}
Foo(int i) : val(i) {}
};
struct Bar{
Foo val;
Foo get_a(){
return Foo(12);
}
Foo get_b(){
Foo temp(12);
return temp;
}
Foo get_c(){
return val;
}
};

c++ is the greatest language of all time

you meant to say c right?

these are all rvalues aren't they?
you can't do
get_x() = something
with any of them

C is trash

Is it good, is there any real use for it?

Because Lisp is a shit FPL. Really, so is haskell, but Lisp is worse and a shitty excuse for an FPL.

Ok fuck.
I'm new to poo-script and can't figure out how to print my fucking int array. Eclipse keeps demanding that i either change the return type of the displayAll method to String (and thus change the input to a string as well, thus fuckin negating the goal). No stack-exchange solutions so i came here for help. This ain't even for work, but its driving me up a wall.

Here's the code (non-offending code excluded):
#problem child
System.out.println(displayAll(intArray));

#Method
private static void displayAll(int[] intArr){
for(int i : intArr) {
System.out.println(i);
}
}

But how the conversion being happened?
What I understand about function returning is by the old C style function return.
the stack will be:
empty stack | argument | pointer to caller | return area | existing stack |
and what happened on return is the function will do copy assignment operation to fill the return area of the stack, and then jump back to the caller function, and then the caller function will do another copy assignment to the desired location.
but how about C++?

but why are you trying to print the return value of a void function? just call your displayAll instead of trying to print the (non-existent) result

i get the impression it's meant to be a language you can just jump into but without requiring an interpreter like python

>arguments
>on the stack
Nobody uses i686 anymore, user.

The only thing I see that is wrong in the screenshot is that you are using both libcurl.a and libcurl.dll.a. Try removing libcurl.dll.a from that list

>System.out.println( void )
This should help you.

I tried it.
It worked :,^(

Thanks senpai, but i feel stupid now.

youll get there man

malloc is an enemy of performance

Assuming that's c++ and you mean if temporary 40 bytes will be used, then the answer is that it depends on the compiler.

A compiler is allowed by c++ standard to optimize returned object to not perform copy, even if there are side effects.
This is called 'return value optimization' (RVO).

Preventing copying for return object is possible starting from c++17 if the object type does not have a copy constructor, a move constructor and the object is returned directly:
return a();
instead of:
obj = a();
return obj;

What's a good example o an FPL then.

Idris.
Maybe Agda in a few years.

Also, your compiler will most likely not perform a copy since it can perform 'named return value optimization' (NRVO)

I need your help /dpt/... Noob here!

I need to create an algorithm that generates non-repeating numbers between 1 and 5 in a two-dimensional array. The rules follow a lot like sudoku...

1 5 3 4 2
2 3 4 1 5
4 1 2 5 3
3 4 5 2 1
5 2 1 3 4


How do?

as rust uses jemalloc it doesn't have this problem

create an array 1 .. 5, randomly access arr[i] and remove arr[i]. Repeat

fill the entire grid with
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5


then loop
while(!ValidGrid()){
//pick two indices randomly and swap their values
}

>like sudoku
Start from coordinate 0,0, randomly select a number.
Move to 0,1, create an array of 1 to 5 and then scan horizontally and vertically for another number already in place, then remove the number from the array.
Repeat until the row is full
Repeat the same thing until you got the 5x5 board.

Neither of those will guarantee that no columns do not contain duplicate numbers.

why wont this work? using MVS
#define INPUT_A_LENGTH 10;
#define INPUT_B_LENGTH 10;

int main()
{
char input_a[INPUT_A_LENGTH];
char input_b[INPUT_B_LENGTH];

// Wait f or user to provide input
std::cout

of course it does
it swaps until the grid is valid, hence ValidGrid()
obviously if there are duplicates in a row, then ValidGrid() returns false

Bogo sort efficiency, 0/10 would not hire

>#define INPUT_A_LENGTH 10;
Don't put the semicolon there.
It's causing it to expand to
char input_a[10;];

slapped it together using some fancy C++ features for funsies!

#include
#include
int main() {
using namespace std;
auto ValidGrid = [](auto &v) {
for (auto &it : v)
if (set(it.begin(), it.end()).size() != 5)
return false;
for (int i = 0; i < 5; i++)
if (set({ v[0][i], v[1][i],v[2][i],v[3][i],v[4][i] }).size() != 5)
return false;
return true;
};

vector v = { { 1,2,3,4,5 },{ 1,2,3,4,5 },{ 1,2,3,4,5 },{ 1,2,3,4,5 },{ 1,2,3,4,5 } };
while (!ValidGrid(v))
swap(v[rand() % 5][rand() % 5], v[rand() % 5][rand() % 5]);

for (auto &it : v) {
for (auto &jt : it)
printf("%d", jt);
printf("\n");
}
return 0;
}

Keep crying, templatehaskellers

Pick a random permutation of [1,5]. That's your first row.

Row X is the same sequence rotated X times.

1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
3 4 5 1 2
2 3 4 5 1


From here, swapping any two rows or any two columns will also meet the requirement.

fast Hilbert curve generation

How the fuck do I learn to use OData to communicate with server side entity framework controllers to work with the data on the client side in the view controllers

No, realy, what's wrong with this as an example?

Is Qt worth learning? Is it used in real program or just manga downloaded and crypto wallets.

not this person but how well does qt integrate into visual studio
would like to try making some gui enabled shit like a multi-platform manga reader

should I learn bash/awk/sed or just go with perl?

Would like to help you, but OData is a few levels above my head

Midterms next week.

C++, Java, hand-written.

Also making an AI in python and a webapp in node.js

Definitely bash/sed/awk.
Perl is dead shit.

>Making an AI in python
So just
>Import ai
>Import sklearn
>Import statmodels
And then writing a wrapper?

should I go with python or ruby instead? and I didn't think perl was completely dead

anyone?

I guess? I'm a fucking novice.

both

Looks like that's from DDS or Nocturne.

I appending to a list always O(n) ?
I can see that if your list is mutable and you allocated extra memory, and know the size of the list beforehand, it's not.
I read somewhere that allocating memory was O(n) so even if you know the size of a list, etc. it's still O(n).

What about lisp, why do I have to re-make my entire list ? Surely there should be a way to just add something at the end ?
I know lists work like linked pairs, but there should be a way to add a pointer to replace that last nil by a pointer to another pair. Or is that just my biased imperative mind talking here ?

No, you can make a list with O(1) append (of a single element)
Just hold a pointer to the back.

>I appending to a list always O(n) ?
A list is an abstract data structure. The time complexity depends on the specific implementation.
>What about lisp, why do I have to re-make my entire list ? Surely there should be a way to just add something at the end ?
Lisps commonly have immutable lists.

>(of a single element)
No, you can append linked lists of any length in O(1), as long as you have a pointer to the tail of the first list.

yeah that too

Don't keep adding to the end, make a big list. Just make sure not to overflow.

You're trash.

Thanks anons. Am programming on a rpi so trying to make code as efficient as possible.

I want to write an authoritative server for a game written in javascript. What is likely to be fastest if I put in the effort towards being asynchronous: C, C++, Node.js, or one of the fancy new languages like Rust and Go?

Worry about the big shit first before you worry about micro-optimisations.

Should I in Windows API return the value of the default window procedure?

what

return DefWindowProc( ... );

try to suck him

If I create a listening server socket which accepts any connections, will it be able to accept any protocol? (Telnet, SSH, HTTP...)

Need help with Java instanceof.

interface Cars
SportsCars implements Cars
Ferrari extends SportsCars

I need to count the amount of Ferraris in an ArrayList of Cars. Can i use

for (Cars c: cars) {
if (c instanceof Ferrari) {
count++;
}
}


Or will i have to use instanceof twice?

>tfw dumb phoneposter and code tag breaks the page layout for me

Given that the socket is of the right type (TCP/UDP) yes

Appending to a list is O(1)

>things that make you go hmm

I can't resist trying to learn C++. What the fuck is wrong with me?

t.C/C# brainlet who thinks C++ is too hard for him but still wants to learn it a bit at least

downloaded Bjarne's book

>What makes this better than D or Crystal?
I don't know, user. I don't program in D or Crystal. It looks more mature than Crystal but less dead than D, though, and it has many cute extra features like the ability to define ints with custom ranges (it's even able to figure out if various operations will result in numbers within the target range, and implicitly convert from larger int types if so), units, multimethods, concepts, and effect system and other stuff.

H-Hayai
youtu.be/4tyTgyzUJqM

>Is it good
So far, I can say it's better than C, C++ and Rust.

>is there any real use for it?
Seems pretty good for applications, at least. No idea how suitable it is for extreme low-level stuff like kernel programming.

>Why do lispers and haskellers hate each other so much?
I dislike Haskellers because they're smug type theory weenies, but they're not even willing to go the full nine yards and learn Agda.

I implemented this once, for my own programming language. Never finished that. I never finish anything.

hey Cred Forums how exactly would i update a vector if the user generated the values and then wanted to allow the user to change one of the values in the vector?

for instance if the user generated 85, 4, 9, 26, 54,
and then i prompt them to enter one of the numbers they entered and then enter a new number and replace the number they selected.


so far i have
int oldJersey; /* number to be replaced */
int newJerseyInput; /*number to be updated*/

cout > oldJersey;
cout > newJerseyInput;

for (int i = 0; i < jerseyNumbers.size(); i++)
{
if (newJerseyInput >= 00 && newJerseyInput

Can I make a graphical nim program with a toolkit that looks nice (unlike tk), is cross platform (unlike gtk) and starts instantly (unlike python)?

"C/C++"
"C++ is superset of C"
"They are almost the same"

FUCK. I Hate everyone who uses "C/C++", those are completely different. Had project written in C, tried to convert it to build as C++ in Visual Studio, it broke everything.

Had to do reinterpret_casts and what not to make it work, instead of direct casts etc. C++ is much more restrictive when it comes to being statically typed.

Of course not all errors were compiler errors, but annoying warnings are annoying too

How do you insert codes on a post?

...

I don't know there's any mature pure Nim library for that, but I'm sure you can find bindings for whatever it is you want to use.

Rust + tokio will probably be the fastest. But the question is, is it worth the effort? As much as I hate Go, it's simpler to learn and has lots of ground for writing servers (http server built into the standard library). So in your case, I'd pick Go.

C and C++ don't have that many asynchronous frameworks. They can be faster than Rust, but only slightly, and they have lots of weird quirks and there are little-to-no frameworks for web development, so you'd have to basically write a complete webserver from scratch, while in the other languages, it's roughly 3 lines to start a server.

Lastly, Node.js can be OK, but compared to the other languages it's not very fast and uses much more RAM.

I'd recommend Go because, even though the language is a dumpster fire, it would probably get the job done the fastest.

> >

>Had to do reinterpret_casts and what not to make it work, instead of direct casts etc.
Sounds like bullshit to me. There are definitely incompatibilities, but C-style casts work fine in C++. They're just unidiomatic. Perhaps you're talking about implicit conversions?

...

For example i had
GetVersionExA(&osVersionInfo)

Where osVersioninfo is struct
after converting to C++ it didn't work without reinterpret_cast like this

GetVersionExA(reinterpret_cast(&osVersionInfo));

C(++)

github.com/yglukhov/nimx

It's documentation is non-existant though but it has been used in production

>BOOL WINAPI GetVersionEx(_Inout_ LPOSVERSIONINFO lpVersionInfo);
>implying i know what the type of YOUR osVersioninfo is
>implying anyone knows what the fuck this opaque microshit garbage really boilds down to
Doesn't really tell me anything, but as I said, it looks like you're talking about implicit conversions rather than "direct casts".

>not using some nice immediate-mode GUI library

Studying how to bubblesort numbers with C++
Can anyone here explain why:
>This works

for ( i = 0; i < 9; i++ )
{
for ( j = i + 1 ; j < 10; j++ )
{
if ( num[i] > num[j] )
{
temp = num[i];
num[i] = num[j];
num [j] = temp;
}
}
} But this does not
for ( i = 0; i < 9; i++ )
{
for ( j = 1 ; j < 10; j++ )
{
if ( num[i] > num[j] )
{
temp = num[i];
num[i] = num[j];
num [j] = temp;
}
}
}

I already know massive library dependent languages like python, c#, c++, where 'programming' consists more of googling the problem and finding the best library or way to do it than actual coding, now I'm looking for a nice, tight language I can still make useful program in but where I don't have to import 20 libraries and Google 40 interfaces to make it work. What's the best compact language you guys use?

Didnt work.

kek

>being this new
Alright. Party's over, /dpt/. The code tags use square brackets.

A functor is a morphism in the category of categories.

nim-lang.org/

And in case you had library problems with it you could wrap a C/C++ lib.

Functors aren't real.

>massive library dependent languages like python, c#, c++, where 'programming' consists more of googling the problem and finding the best library or way to do it than actual coding
So let me get this straight... you're asking for a language that lacks libraries for common stuff, so you could waste your time reinventing the wheel and feel justified in doing so?

Are you retarded? There's no such thing as a library dependent language, nobody's stopping you from doing everything from scratch, you download other people's shit to save you time.

10/10

I'd just like to interject for a moment. What you're referring to as C++, is in fact, C/C++, or as I've recently taken to calling it, C plus C++. C++ is not a programming language unto itself, but rather another library of a fully functioning programming language made useful by the C standard library, compiler, and vital debug symbols comprising a full programming language as defined by ANSI.

Yes

I'll check it out.

that argument doesnt work for languages which are limited such that you have to use libraries written in other languages just to get basic functionality, like python which needs libraries written in C just to run in a finite time , or C# that needs libraries that changes the emitted intermediate language code just to make using properties bearable.

No this should work, have you tested it?

So just use C. But then some really low level stuff has to be done in asm.

I have learned java for a year now, should I move on to C or C++?

don't bother learning C++ unless you hate yourself.

Its that bad huh?

What does the *.* stand for?

You dont know what wildcards are?

i thought it had something to do with vlans, but now that i've seen it mentioned in linux CLI i have no idea.

REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

I WANT TO USE QML WITH FANCY QT GRAPHICS BUT I DON'T WANT C++ IN MY CODEBASE
WHEN THE FUCK WILL QT FINALLY LEARN ABOUT METACLASSES

So don't use it with c++? What's the probe?

...

Non C++ QML bindings are lacking

Working on adventofcode level 6/2. My solution in Python has been running for 5 minutes.

What data structure are you using?

completely new to programming, where should i get started with python?

learnxinyminutes.com/docs/python/

Maybe you should re-think your "solution".
My took less than a second in perl.

Nothing fancy, a set containing a tuple representing the bank state.

That should by fast enough unless you're using a shitty hash. Maybe you did something wrong

thanks

use the python3 one instead actually

yeah it works senpai

I don't understand dpt's hatred for Java: it's a much cleaner and easier to read language than its predecessors, it follows an efficient, tested and true programming paradigm, has plenty of libraries and frameworks that make any kind of software easier to produce and is widely available thanks to the JVM.

Java hatred originates from Microsoft shills when they were shilling C sharp

...

>where should i get started with python?
In hell. Learn Agda.

strawpoll.me/15098544

First time in Cred Forums and second time programing (hence why this will be a dumb question) but how would I do to read from a table nest with two of the same name values?

For instance

table = {
{
subtableA = 1,
subtableB = 2,
subtableC = 3
},
{
subtableA = 4,
subtableB = 5,
subtableC = 6
}
}

In regular tables without the same name of the values it's easy because then it would be table.subtableA or whatever, but since it's got two values, how am I suppose to identify the one I need?

Using LOVE2D framework. Help me Obi One.

I'm trying to insert a vector of ints into a set of ints:
auto merge_target = connections.back();
merge_target->insert(v.begin(), v.end());
But I get this error
error C2663: 'std::_Hash::insert': 6 overloads have no legal conversion for 'this' pointer
I can't figure out what's wrong. merge_target is an iterator to a set

>Help me Obi One
>Obi One
>One
Just google it, you lazy piece of shit. The absolute fucking state of public education...

I did. love2d.org/wiki/flat_table

Been googling for a while now.

i don't know what that is

how do i use push_back if my vector was initialized to

vector newVector(5);

class [class name] {
public static void main(String[] args) {

}
}

you don't. Use std::vector::reserve() to allocate enough space, but did not insert the item.
If you do that you need to use:
v[i] = x;

where i is the last initialized element
instead of:
v.push_back(x);

edx.org/course/introduction-computer-science-mitx-6-00-1x-11
and
automatetheboringstuff.com/

the problem im having is that initially i need the user to input some int's into the vector then be able to add or subtract them later on.

How do I run a C++ function using Javascript/HTML+CSS?
I have a function that takes in a string, converts it into another string (fairly complicated stuff I can't just do in JS) and outputs a "transformed" string.
I've been told I need to run a server of sorts, but I haven't the faintest as to how to actually do this.

I figured it out. Actually, merge_target is of type set::iterator, and since C++11 set::iterator is an alias for set::const_iterator. Yes, you read that right.

What's you're problem? You just created a vector with a reserved size for 5 elements. Just use push_back like you normally do.

>You just created a vector with a reserved size for 5 elements
He just created a vector with 5 default constructed elements.

You would need to run a C++ web server and use AJAX

What am I doing wrong?

function isValidWalk(walk) {
while (walk.length === 10){
var position = [0, 0];
walk.forEach(function(direction){
if (direction === 'w'){
position[0] -= 1;
} else if (direction === 'e'){
position[0] += 1;
} else if (direction === 'n'){
position[1] += 1;
} else if (direction === 's'){
position[1] -= 1;
}
});
if (position == [0, 0]){
return true;
} else {
return false;
}
}
};

isValidWalk(['n','s','n','s','n','s','n','s','n','s']); //should return true//

>if (position == [0, 0]){
> return true;
> } else {
> return false;
> }
> }

push_back will add a new element to the back, insert will add a new element to a specific position, pop_back will remove the last element, erase will remove an element from a specific position.

>Nim is a systems [...] programming language
>garbage-collected

A little poll server.

krautplausch.hopto.org/te/vote/index.php

Sample poll: krautplausch.hopto.org/te/vote/show.php?id=zmmhbypzrw

What do you mean by this?

>tripfag
>retarded
checks out

Why do you have a while loop checking that walkjas lengthy 10?

that's pretty fucking egregious actually

Position is the pointer to the first element in the array so try comparing the elements directly. Also use a select case maybe.

>muh gc meme

>it has a GC so it can't be a systems language

>tripcode

It's [\code] [\/code]
Remove \.
Also it'd be wise to do a diff for readers.

Supposedly the walk has to last exactly 10 min, and every time you move you spend 1 min walking.

Going with

if (position[0] && position[1] === 0) {
return true;
}


Gives me the same result, same as using two variables, x and y for positioning instead of an array and then checking if both equal to 0.

Don't people usually say that it forces GC so it's bad for systems programming?
Even optional GC gets this critique leveled at it usually since you normally find that the standard library uses these features.

Hold on a minute, I'm going to go find a screenshot I took of a method I found at my job that's similar in spirit to this.

en.wikipedia.org/wiki/Region-based_memory_management

When in doubt use parentheses.

Pic related, I condensed it to fit on the pic but originally it was formatted normally taking up about 100 lines. It was also just in the middle of a larger method but I extracted it to make it clear wat it was doing, instead of returning it assigned the Boolean to another variable that was used further down.

>assuming there is a heap to allocate the regions themselves

My god

>region based memory management
Sure. That's one strategy. This is entirely separate from GC though. Why even post that?

>Don't people usually say that it forces GC so it's bad for systems programming?
They usually say it, sure, and it usually devolves into "you wouldn't write a kernel in it", as if that's the only thing that falls under "systems programming".

How would you write it, /dpt/?

nim-lang.org/docs/gc.html

You're just posting links at me?
Stop. I'm being oppressed.

atLeastOneTrue :: [Bool] -> Bool
atLeastOneTrue = foldr (||) False

Neat, but unfortunately you broke the API. Clean out your desk, user, you're fired.

If I had to have those arguments (you probably don't, but let's imagine).
I'd write
return b1|b2... ;
You could also do a sum and convert to bool. Not actually sure what's better.

You can do better than that even in Java...
boolean isAtLeastOneTrue(boolean... args) {
for(int i = 0; i < args.length; ++i)
if(args[i])
return true;
return false;
}

template
bool isAtLeastOneTrue(T x) {
return x;
}

template
bool isAtLeastOneTrue(T x, Ts... xs) {
return x || isAtLeastOneTrue(xs...);
}

Can you do it without using templates?

#define ( [
#define ) ]

Yes, but I would rather not.

using instanceof is a defect of your code. please reconsider.

C#:
bool AtLeastOneTrue(params bool[] bools) => bools.Any(x=>x);

>m-muh sepples
>m-m-m-muh templates
>is unironically uglier than java

Who are you quoting?

This.

What the fuck am I even looking at.
Why not just take this shit:
dumbCamelCaseShitName(a, b, c, d, e, f, g, h, i, j, k, l);

and simply replace it with this shit:
a || b || c || d || e || f || g || h || i || j || k || l;

Do you pajeets write functions to replace +, -, *, /, &&, |, and & as well?
The fucking state of Cred Forums in this day and age.

I'd like to interject for a moment

Why not use composition instead of inheritance, and make an enum prop of CarType?

Discuss, Cred Forums.

Because those solutions mean that the function can take any number of arguments.

>hardcodes the arguments
>need to modify the function every time the number of arguments has to change

Reasons to use Idris or Agda over Haskell?

Dependent types & totality, but that being said you can get a good deal of what they offer with LiquidHaskell (which is now a fully complete theorem prover thanks to refinement reflection).

.a are unix static libraries (archives of object files)
On windows, you need to link against .lib files only.

This board is brain damaged.
I am asking why you need a function in the first place.

Since you are not actually making anything, it doesn't fucking matter.

It's an exercise. No one said it was actually production code.

seething

Calm down, original guy said he extracted the method to make it clear wat was being done, and then someone asked how you would rewrite that method, which led to the methods you see.

What's specifically the advantages of having dependent types of totality. I've heard that dependent types are going to be implemented in Haskell eventually but I don't know why that's a good thing.

try
if(position[0] === 0 && position[1] === 0)

template
bool variadicOr(Ts &&...ts)
{
return (ts || ...);
}

this is already in prelude called or

or [a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12]

if (boolean) {
return true;
} else {
return false;
}

can be shortened to

return boolean

bool oneTrue(params bool[] args) {
return args.Any(x => x);
}

Dependent types make your types more precise and able to express more properties about your program and prove them (sometimes automatically). Totality is more or less a prerequisite for dependent types because, without it, you're 1. not guaranteed that successful type checking actually guarantees the properties and 2. able to make the compiler hang during type checking. LiquidHaskell eases the proof burden a lot.

Shit, that's even smarter than mine, I forgot about variadic folds.

Haskell has an external plugin LiquidHaskell that provides limited refinement types, and it will soon have a DependentHaskell extension giving it dependent types. I'm pretty sure you can already do dependent type stuff with a bajillion extensions, it's just a fucking bitch to do in Haskell.

Nice, I guess there is a Java version with lambda as well

In python:
isAtLeastOneTrue = any

>Haskell has an external plugin LiquidHaskell that provides limited refinement types
ucsd-progsys.github.io/liquidhaskell-blog/2016/09/18/refinement-reflection.lhs/

in Haskell
or
or
any id

...

You're a mongoloid. Literally no one said it should be a method. People were simply posting less disastrous versions of the given method. Now go pat yourself on the back for knowing what the fucking or operator is, you unsung basement genius.

And for the record, you spergalicious retard, your solution has quite different semantics, so it may very well be broken in the original context. I'll leave it to you to figure out why, not that I expect you to be able to do it. You are the trash of /dpt/.

redpill me on ada

Only if it's >>>>>>>>>>> syndrome.

If you're okay with the verbosity of Ada, you might as well use ATS.

Why do i keep forgettinghow to declare arrays

because you haven't declared enough arrays yet ?

just declare 1 array of arrays

You have to put up with more than verbosity to use ATS. Why did they have to make it so incredibly ugly?

in J its just
isAtLeastOneTrue =:+./

I think.

Oh no, short circuiting or means things won't get evaluated after the result is known. Like whoever wrote the original garbage had any fucking clue what they were doing in the first place.
The fact anyone bothered writing a "less disastrous version" instead of replacing the whole thing is good indication that nobody who replied was thinking. The whole problem with 90% of the alternatives is that they break the API so if you're going to break the API why not just throw the whole thing out to begin with. At least the Haskell programmers used their brain cells and realised the feature was already part of the language. Face it, you all over-thought this problem and decided to engage in a little bit of mental masturbation to see which idiot could come up with the most complicated solution which used their favourite language features.

If for some unholy reason you had to keep the interface, you would just do what was shown in:
anyway.

angery

ah i see now im enlightened

>The fact anyone bothered writing a "less disastrous version" instead of replacing the whole thing is good indication that nobody who replied was thinking.
The fact that you "fix" code by altering its semantics without knowing the original context shows that you're a fucking retard.

>If for some unholy reason you had to keep the interface, you would just do what was shown in:
No, because that's a distinctly fucking inferior way of doing it, once again demonstrating that you're a retard.

I can see how you think that was sarcasm, but...
This guy is correct.

Just keep doing it over and over again.
Try to do it from memory. Check it. If it's wrong, wipe it. Try to do it from memory again. Check it. If it's wrong, wipe it. Try to do it from memory again. If it's right, come back 10 minutes later, and try to do it from memory again.
Also, check this:
pathsensitive.com/2018/01/the-benjamin-franklin-method-of-reading.html

What language?

No i didnt think that was sarcasm

boolean atLeastOneTrue(boolean... args) {
return Arrays.stream(args).anyMatch(b -> b);
}

> The fact that you "fix" code by altering its semantics without knowing the original context shows that you're a fucking retard.
The fact you "fix" the code without asking any more questions to see if there isn't a better way to get rid of the whole fucking thing shows you're a fucking retard. The fact you "fix" the code by using a different language or by breaking the API or by creating a new function to call from within shows you're a fucking retard.

>No, because that's a distinctly fucking inferior way of doing it, once again demonstrating that you're a retard.
Inferior way to do it...? where the better way of doing it is to:
- Break API
- or change to a different language
- or write a C++ template and call the C++ template
- or do some other dumber shit

>creating new objects to save 3 lines of code

dude the jit will take care of it lmao

>The fact you "fix" the code without asking any more questions to see if there isn't a better way to get rid of the whole fucking thing shows
... that I don't give a fuck. I just rewrote it while keeping the original semantics intact.

> using a different language or by breaking the API or by creating a new function to call from within
I wasn't doing any of that.

>Inferior way to do it...?
Yes. a || b || c || d || e || f || g || h || i || j || k ||... is an inferior retard-tier way of doing it, whether you put it in a method or not. Just stop posting. Every time you respond, your humanity is diminished in the eyes of anyone who observes it.

Refer to

>this is what happens when bool is treated as its own type instead of the int that it really is

Stop using my smug anime girl while making retarded posts.

>I don't have to worry, compiler magic will solve it for me
Lol yeah keep believing in it, home boy

>Yes. a || b || c || d || e || f || g || h || i || j || k ||... is an inferior retard-tier way of doing it, whether you put it in a method or not. Just stop posting. Every time you respond, your humanity is diminished in the eyes of anyone who observes it.
Are you literally brain dead?
Assuming you need to keep the API you have three options:

1. Use the original crap

2. bool shit(bool a, bool b, bool c, bool d)
{
return a || b || c || d;
}

3. bool shit(bool a, bool b, bool b, bool d)
{
return your_shitty_replacement_function(a, b, c, d);
}

How is #2 any worse than #3?

It's already been explained. || is a short-circuiting operator. You're actually looking for |, but for some reason you consistently fail to realize this.

Because #2 assumes you have a fixed number of arguments.

... syntax also entails creating a new object

That's irrelevant, we're keeping the API so we have a function being passed arguments, they're already evaluated so short circuiting inside the function is irrelevant. Try again

You do have a fixed number of arguments, we're keeping the original shitty API. Try again.

God thanks, now I remember this is some stupid mistake I already made in the past.

Got it working now.

I'd go with python for larger scripting jobs.
sed and awk are very useful for quick text processing.

boolean isAtLeastOneTrue(boolean... args) {
for(int i = 0; i < args.length; ++i)
if(args[i])
return true;
return false;
}

Here you go, you stupid fuck. It has the same semantics as the original, and it's extremely unlikely to break the existing code (unless you want to argue that someone was overriding it within the same package in a subclass, presumably to do something other than what the name implies, and relying on polymorphism to call it). Now please tell me all about how your 12-parameter function and a || b || c || d || ... is better.

to lower, split to char,dictionary for the frequency, sort chars, comibne chars and then to upper.

>It has the same semantics as the original
No it doesn't, it takes a variable number of arguments. Won't give an error if you don't pass all the arguments. Why didn't you stop to consider that it might have been a requirement of the original code? Try again.

It also assumes the programming language supports such a construct. You don't even know what programming language the original was using, hint: it probably wasn't Java.

You just changed the requirements of the problem to fit your narrative, so that you may feel that you have won. Go to bed.

>... syntax also entails creating a new object
Not really, because this is actually a core argument-passing mechanism of the language, so you can count on it being optimized specifically. With what you did, you have to rely on the quality of general optimizations like escape analysis.

Bullshit, all you retards have been moving the goal posts all day long. I'm just using your own standards of judgement.

>No it doesn't
Yes, it does. All the calls to it are guaranteed to produce the same result.

>It also assumes the programming language supports such a construct. You don't even know what programming language the original was using, hint: it probably wasn't Java
You're actually right about this one thing, so here's your silver lining to being a moron.

boolean... is syntax sugar for boolean[]

New thread:

>boolean... is syntax sugar for boolean[]
It clearly isn't. Are you retarded?

boolean isAtLeastOneTrue(boolean... args) {
if(args.length != 12) throw new RuntimeException("Autism demands 12 booleans.");
for(int i = 0; i < args.length; ++i)
if(args[i])
return true;
return false;
}

That's actually a pretty shitty idea, user.

>muh static type checking
I suppose with sufficient autism you really are locked into a giant autistic sequence of ||'s.

So now you think that changing the programming language is not changing the semantics. You also think this 6 lines of BS is better than a single line of || repeated 11 times and wrapped in a function in the unlikely event that any of the complete and utter BS you've spewed so far actually matters for the original code. You've also opted for runtime exceptions to catch compile time bugs.

No wonder you're a java programmer, it's fitting.

>being too dumb to follow the conversation and tell apart different posters
>thinking i'm a "java programmer" despite evidence to the contrary
You're mentally-challenged. Every single post of yours so far just screams "cretin".

Actually I think that (or a b c ...) is better. I was just editing user's code in an attempt to appease your dysfunction. I use lisp not java because static typing is shit.

>Actually I think that (or a b c ...) is better
This is the one case where Lisp operators look better than normal infix notation.

it literally is in java

>tfw you fix a nasty bug
brb going for a smoke

Nothing in this line of posts suggests you are anything but a Java programmer considering that all posts with any code have contained what looks like Java.

Going by the original "rules" which were arbitrarily defined here
I would argue that "using a completely different fucking language" has "different semantics."

You idiots spew random shit and complain about the simplest solution because it doesn't follow some arbitrary retarded set of rules and then you claim that a solution in a completely different fucking language is better than a solution which could at least have been implemented in the original program.
You claim semantics are different and then you provide code with different semantics.
You claim the API has to be the same and then you provide code with a different API.

You're all a bunch of screeching autistic brainlets who are physically incapable of writing simple and coherent programs.

>I would argue that "using a completely different fucking language" has "different semantics."
And this is a fucking retarded argument, because you can write a function in a completely different language that still exhibits the same semantics, but I already admitted that you're right about the original code not being Java. Just stop posting. Every time you do, you just solidify the suspicions that you're an inbred subhuman.

>it literally is in java
void foo1(int... crap) {
}

void foo2(int[] crap) {
}

foo1(new int[]{1, 2, 3, 4}); // doesn't work
foo2(1, 2, 3, 4); // doesn't work

Looking forward to hearing this:
>but hurrrr int... is still literally just syntax sugar for int[]

Do you realize what syntax sugar means?

>Do you realize what syntax sugar means?
X being syntax sugar for Y means X and Y have different syntax but identical semantics. Clearly, int[] doesn't declare a function with a variable number of arguments, you absolute mongoloid, so int... x is not syntax sugar for int[] x.

The semantics are identical. They both create a new array of ints from a variable length list and pass it into the method. The sole difference is the syntax used.
How do you get to the point where the things you say prove yourself wrong and you don't realize it?

>one declares an array argument
>the other declares an arbitrary number of arguments
>The semantics are identical
You're seriously subhuman... there's no way around it. You're this moronic sperg, aren't you:

There is precisely one argument, the array which is constructed at the call site. The fact that you write a comma-separated list of values (i.e. the syntax) does not mean the semantics are any different.
You can compile them both and get the same bytecode with the only difference being the method signature.

>foo(1, 2, 3, 4, 5, 6, 5)
>there's precisely one argument

Yep. The meaning of both pieces of code is that the method receives one argument, an int[] which is constructed at the call site. Thus the semantics are the same.
Posting memes doesn't make you correct.

>foo()
>foo(1, 2, 3, 4, 5, 6)
>yep. one argument
Say, you inbred piece of shit, can you define "argument" for me? ;)

public class Variadic {
public static void variadicPrint(String... args) {
for (Object o : args)
System.out.println(o);
}
public static void main(String[] args) {
variadicPrint("one", "two", "three");
variadicPrint(new String[]{"four", "five", "six", "seven"});
}
}

> output

one
two
three
four
five
six
seven

docs.oracle.com/javase/specs/jls/se9/jls9.pdf
>A method declares executable code that can be invoked, passing a fixed number of values as arguments.
Not a variadic number.

as much as that guy annoys me, i have to agree with him, param is just sentatic sugar in most if not all languages. Both have the same IL code in C#.

void foo(int[] arr){}

foo(new int[] {1,2,3,4});


and
void foo(params int[] arr){}

foo(1,2,3,4);


IL:
IL_0000: nop
IL_0001: nop
IL_0002: ldc.i4.4
IL_0003: newarr System.Int32
IL_0008: dup
IL_0009: ldtoken .1456763F890A84558F99AFA687C36B9037697848
IL_000E: call System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray
IL_0013: call g__foo0_0
IL_0018: nop
IL_0019: ret

g__foo0_0:
IL_0000: nop
IL_0003: ret

Completely ignored. Can you define "argument" for me, you inbred piece of shit?

Specifically, explain the difference between a parameter and an argument.

Seems quite clear from that statement.
In Java an argument is one of a fixed number of values which is passed to a method when it is invoked.

its the same thing?

>one of a fixed number of values which is passed to a method when it is invoked.
foo(1, 2, 3, 4);

Alright. How many values are being passed, tard? Show me again your inability to understand arithmetic. Next you're going to argue that in bar(1, 2), no arguments are being passed, because the function is inlined, or because the arguments go straight into registers. I honestly don't care how you try to save face at this point. You just can't sink any lower.

>its the same thing?
Wrong, you retard.

>How many values are being passed, tard?
one. it passes an array of 4 items.

>4=1
>it passes an array

Given a method signature of void foo(int... bar) there is one argument.
The alternative you suggest is predicated on the idea that a single method may receive a variable number of arguments, which is explicitly forbidden by the language specification in clear terms.

A self portrait is not a substitute for an argument.

>foo(1, 2, 3, 4)
>1 is an array
>2 is an array
>3 is an array
>4 is an array
>all of them are the same array
>there is one argument

you seem to be confused between syntactic sugar the compiler just exchanges with something else, and optimization that is performed by stuff like in-lining. check the IL here its the exact same thing.

You are confusing semantics with implementation details. Anyone who makes such a mistake in the first place beyond help. Conversation over.

no, now your just being facetious. 1,2,3,4 is shorthand for int[] {1,2,3,4}, which is an array.

Who are you talking to?

>True || True = True
>No, that's just an implementation detail. IT MIGHT NOT BE!! All I have to do is write my own compiler that breaks the standard and it could be FALSE!!

>1,2,3,4 is shorthand for int[] {1,2,3,4}, which is an array.
No, you fucking retard. 1, 2, 3 and 4 are arguments passed to the function. 1, 2, 3, 4 is not a shorthand for anything.

true || true = true is part of the semantics of the language. 1, 2, 3, 4 being a shorthand for an array, or whatever other moronic delusions you're suffering from, is not part of the semantics of the language. Consider suicide.

What language are you talking about because obviously we arnt using the same one.

What's a "function"?