/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: Gt+loli+queen+gt+not+a+neet+_29e3dec39c8f15b179dbc5ca7fcd16b6.jpg (1280x1397, 217K)

Other urls found in this thread:

en.wikipedia.org/wiki/C--
twitter.com/SFWRedditImages

Uguuu~

Attached: 1527231873221.gif (205x274, 16K)

Idea: Take the concept of overriding a method, and generalize it so that not only do methods no longer belong to classes, but also, rather than just depending on the runtime type of a hidden receiver parameter, the method resolution depends on arbitrary runtime conditions that don't even have to be type related.

I guess it would look something like this, for example:

int use_bar_impl;

when (use_bar_impl) {
void foo() {puts("bar");}
}
void foo() {puts("foo");}


I know it looks like you could do the same thing with an "if," but that's just for this simple example. I can think of some situations where resolving the conditions *within* the function, rather than in the process of resolving which implementation to use, doesn't scale as well.

Is this already a feature in some languages? If so, what's it called? I know multimethods are when method resolution depends on the runtime types of multiple parameters and not just the receiver, but this is even more general.

is rust appropriate for writing simulations?

Use C.

But I don't like bare function pointers.

use Haskell

Ok but that's still not an actual answer to the question

simulations? what do you mean?

just use type classes

What if few conditions are true at the same time? Throw a runtime error that method is ambiguous?

What if method A is being opened depends on method B being opened, which itself depends on A? Would you try to figure out dependencies (which is non-trivial and, if we're talking about most general case, undecidable) or just limit the amount of recursion on the stage of overload resolution?

That just shows Haskell has multimethods.
What I'm asking is, what's it called when there's a feature that allows method resolution to depend on arbitrary runtime conditions. E.g. not restricted to testing the specific runtime type of something whose type we know belongs to a certain typeclass.

Numerical simulations of physical systems. Is rust at all competitive with fortran/c/c++ for this sort of thing?

just use an if statement or pass the parameter in ffs

>What if few conditions are true at the same time? Throw a runtime error that method is ambiguous?
Interesting question. I was thinking about that myself. I guess use the most specific condition? Or, if they're equally specific, the one declared last.
Even so, that's not ideal, just the best approach I can think of.
>What if method A is being opened depends on method B being opened, which itself depends on A? Would you try to figure out dependencies (which is non-trivial and, if we're talking about most general case, undecidable) or just limit the amount of recursion on the stage of overload resolution?
Or just allow the method resolution to enter an infinite loop
I mean think about it, if you have:
int g();
int f() {
return g();
}
int g() {
return f();
}
int main() {
f();
return 0;
}

Then we fully expect the compiler to just allow the infinite loop to happen, right?
Why should this be different?

>just use an if statement
Not always scalable
>or pass the parameter in ffs
This is one reasonable and equally powerful alternative approach: first class functions. However, I think sometimes allowing method resolution to depend on arbitrary conditions may be more expressive.

yes

This is so stupid. You could even just have a mutable reference to a function. There is no point at all in attaching it to method nonsense.

>first class
I meant higher order not first class

>I guess use the most specific condition?
Then you have to give rules on what is more specific (see C++, it's a fucking nightmare to do properly).
>the one declared last
What does "last" mean?
Say, this:
int foo() { return 1; }
int x() { return foo(); }
int foo() { return 2; }

Would x() return 1 or 2? And we're not even touching multiple modules yet.

>There is no point at all in attaching it to method nonsense.
In some situations it can be more expressive.

no

All I know is, there are languages that successfully implement this. E.g. Inform 7.
All I'm asking is what it's called

Yes.
See: Inform 7

What does Jow Forums think about test driven development and agile?

>This is so stupid.
let people code like they want, bully.

Inform 7 is a very... unique language, from what I know. The concept of relation between entities is first-class in it. How exactly does this sort of... "conditional dynamic overloading", for the lack of better words, work in it?

Well, it's a little restricted because it only applies to actions the player or NPCs can take in the world, rather than arbitrary functions, but the basic principle is still there.

It allows multiple overloads to be selected at the same time. It's got (at least) three keywords / key-"phrases" for controlling how a selected overload is incorporated into the control flow with respect to other selected overloads: "before," "instead," and "after." As for specifying the actual conditions for selecting the overload, the keyword it uses is "when." There are a few other keywords / key-phrases for controlling this sort of thing as well, but I don't remember them.

So, defining an overload for an action might look like this:

Instead of taking something
when Fred is carrying the noun,
say "Hey, [regarding the noun][those] [are] my [noun], you filthy animal.".


It's been awhile since I last worked with Inform so I could be wrong

If I have a datatype that represents dollars, what should $0.03 / 2 return?

does anyone know of any resources on how to organize a tournament? how to generate the brackets, calculate BYEs and stuff like that?

Trying to understand shared library in linux
Why the fuck this thing not crashing?
initial code:
//header.hpp
struct Foo{
void printfoo();
};
//sharedlib.cpp
void Foo::printfoo(){
std::cout

A loan for $0.03 over two years (with default interest rate).

$0.015.

Fractional cents are actual things that exist. Despite the fact that no physical amount of cash is sufficiently small to represent them.

Most likely the function is located at the same address in both versions. Try extracting symbols and segment information (nm, objdump).

Probably not the place to ask, but I'm in a bit of a fudge.
Basically, the Stopwatch class doesn't seem to work for me unless I use the fully-qualified name.
I tested this problem with another class from the same namespace (BooleanSwitch, to be more precise) and I haven't had such a problem with it.
Any idea why? I'm fairly confident that I'm referencing the assemblies properly ("csc stopwatch.cs /r:System.Runtime.Extensions.dll /r:System.dll /r:netstandard.dll").

Test code below:
using System.Diagnostics;
using static System.Console;

class Stopwatch{
static void Main(){
BooleanSwitch bs = new BooleanSwitch("Test","Testing");
System.Console.WriteLine(bs.DisplayName);

Stopwatch sw = new Stopwatch();
sw.Start();
sw.Stop();
WriteLine($"Is the processor clock of high resolution? {(Stopwatch.IsHighResolution?"True":"False")}");
WriteLine($"Frequency: {Stopwatch.Frequency}Hz");
WriteLine($"Nanoseconds per tick: {System.Math.Pow(10, 9) / Stopwatch.Frequency}ns");
}
}

Attached: 1490788750390.gif (500x502, 839K)

HOW THE FUCK DO I GET THE ABSOLUTE VALUE OF A FLOAT

Mask (e.g: f & 0x7FFF;).

Make that f &= 0x7FFFFFFF;

>doesn't seem to work
Doesn't work how exactly? Compile error? Runtime error? It just doesn't work? I don't exactly have libtelepathy.so installed on my system.

Also, maybe the problem is that your own class is named Stopwatch, so there's ambiguity in name resolution?

>I know multimethods are when method resolution depends on the runtime types of multiple parameters and not just the receiver, but this is even more general.
Clojure's multimethods allow you to choose the concrete method based on the result of calling any function on the parameters. People usually use "class" to achieve the traditional behavior, but it can also be yield more sophisticated constructs. For example, here's a multimethod that multiplies its arguments if they have different signs and adds them otherwise:
(defmulti m (fn [x y] (not (= (>= x 0) (>= y 0)))))
(defmethod m true [x y] (* x y))
(defmethod m false [x y] (+ x y))

(m 2 4) ; => 6
(m -1 5) ; => -5
I think this could be used to achieve what you propose. The function that runs on the arguments doesn't have to be pure, so it's possible to choose the implementation based on global state. Example:
(def ^:dynamic disabled false)

(defmulti m (fn [x] disabled))
(defmethod m false [x] x)
(defmethod m true [x] "disabled")

(defn f [] (m 5))

(f) ; => 5
(binding [disabled true] (f)) ; => "disabled"

abs(x)?

>popping float out of x87 stack to main stack
>setting bit mask
>pushing in x87 stack again
Versus
>literally just fabs

it can't be done

double my_abs(double x) { return x < 0 ? -x : x; }

>32-bit floats

Attached: rrN1XeX.png (454x404, 158K)

I need a scheme interpreter that works on windows 10.
MIT-GNU scheme doesn't.
Which one do I choose?

Fucking finally.

Julia 1.0 is scheduled to be officially released August 6. The github issues are all gone, the only thing left is package updates and possibly some minor hotfixes.

I'm hoping it'll go from early adopter stage to mainstream. It already has several times more jobs than Rust despite the fact that Rust has been post 1.0 for three years.

Attached: Zeon_flag.jpg (1280x1024, 1023K)

Wrong it should return $0.02

>> Not using a bitmask with the sign bit of the double.

There are several implementations of Scheme that work on Windows 10, most notable are QEMU, Virtualbox and VMWare.

I was hoping for native.

I'm into statistics and such things, I like R and dislike python. Should I try julia?

I am trying to write a Leddit Downvote bot so that I can take over a small sub that I participate in.
Anybody got any resources on this?
I am not a skiddy looking for some premade shit, I already know python and how to use the reddit API.
I am mainly just wondering if anybody has used vpns in python extensively

Attached: 72b8c9cc73ef06a163c23be3670c83c6.jpg (415x660, 27K)

Technically yes, in practice not really because of lacking library support and the fact that you lose safety anyway if you use the Rust FFI since most C and Fortran libraries stray very far from idiomatic Rust and are kind of annoying to provide a safe interface to.

Julia is generally better for this, since it already has good existing bindings to anything you'd want, and a large enough scientific computing community to do full rewrites of the few libraries that are too annoying to bind to.

Employed Haskell programmer here :)

Attached: 1473556669811.jpg (1369x1183, 338K)

It's undefined behavior. There's no guarantee it WOULDN'T work, but discussing this is pointless because this particular instance doesn't tell us anything about the general case.

If you only ever do statistics, I think you're probably fine with R.

You can still check out Julia to see if you like it better than Python though. Unlike Python it has excellent R interop with RCall.jl.

Attached: RJulia.png (1000x489, 113K)

but does it have *fearless* concurrency??

>reddit
Get out.

>1369x1183
weakling

Attached: 44.jpg (2738x2366, 699K)

so what makes julia stand out? I feel like I've mostly seen it mentioned in statistical settings but maybe that's mistaken

I bet you've been posting here since 2016.
I miss old Jow Forums

It has green threads and channels like Go for easy concurrency, and a number of special purpose abstractions intended for distributed computing.

It doesn't have something like the Rust sync trait + borrow checker for compiler-enforced thread safety, but it's still perfectly viable for large distributed projects that run on thousands of machines like celeste.jl which had to be both parallel and concurrent.

and yes if you're wondering, I am in fact too lazy to attempt a simple altavista query regarding my question

Should I use C or C++ ?

What's your favorite sorting algorithm
Mine
>good old merge

Attached: 1447710010193.png (362x362, 48K)

bogo

float abs(float x) {
return x & ~(1

Mine is Merge too. Mostly because of the fact that it can efficiently sort linked lists, which randomized QuickSort can't do.

For what?

oops that should be *8

C--
>en.wikipedia.org/wiki/C--

owo whats this

>oops that should be *CHAR_BIT
ftfy

Change the class name or do something like:
//alias
using DStopWatch = System.Diagnostics.Stopwatch;

You can also redefine Stopwatch in the global namespace and use global::Stopwatch but that is fugly

masking sign bit but will work with any size float

Numerical computing more generally. That does include statistics, but it's more directly aimed towards deprecating matlab (it has nice syntax for linear algebra), while also being fast enough to implement the stuff that you'd normally write in Fortran/C/C++.

It's very good at giving you zero cost abstractions and at striking a good balance between ease of use for quick scripts (for casual matlab/python/R users), advanced higher-level functionality and metaprogramming (lisplike macros and generic programming) to let you tackle difficult problems with less code and build good abstractions, while also being very fast and giving you a lot of control over low level details.

Basically, it's really good for making top tier libraries that are easy to use for end users while also being versatile and fast. It has best in class numerical libraries for some things like optimization problems and for differential equations. It also has some really nice machine learning libraries that might become best-in-class options in the future for things like boosted decision trees and some kinds of neural networks.

Ignore the last line.. That is useful when you use the class and not when you are redefining it w/ dependecy on the existing one

Developing malware.

would this work if float was wider than int, since then you'd have a shift by more than the width?

works with floats of any size

Sleepsort

Wrong, 3 cents divided by 2 does not equal 2 cents.

Yeah, that sounds really cool and right up my alley thanks. Might as well check it out anyhow

Oh, I deleted that part.
Compile-time error: "'Stopwatch' does not contain a definition for 'Frequency'" and "[...] for 'IsHighResolution'", as well for the Start and Stop methods.

>maybe the problem is that your own class is named Stopwatch, so there's ambiguity in name resolution?
...
Fuck, I completely missed that. That was the problem.
Why the hell did I name the namespace Stopwatch. Why did I even bother with a namespace in this situation.
No wonder looking it up on Google wasn't fruitful. It also had nothing to do with pre/post .NET 3.5.
I feel like a right divvet but I still thank you.

>literally just fabs
>Implying fabs doesn't do the exact same thing

>32-bit
If he wanted double, he should've said double.

Attached: tarsier-footer.png (280x222, 33K)

Yes it does $0.03 / 2 = (~$)0.015
Ends with a five so it gets rounded up.

You'd better be implementing your sleepsort with non-preemptive multitasking user. Otherwise you'll occasionally get wrong answers.

>Ends with a five
Yes.
>so it gets rounded up.
No.
Fractional cent values are valid quantities of money.

>implying I didn't write a whole OS for the sole purpose of invoking sleepsort on it

At some point you need to apply a discretization, might as well be at the physical boundary.

So in other words... When something is like a multimethod but dispatches based on arbitrary conditions...
Then... It's literally just called a multimethod.

... Cool.
Thanks.
Unironically thanks. Actually helpful. Did not know that.

>At some point you need to apply a discretization,
You really don't.

Oh yeah? How do you propose we represent monetary values less than machine epsilon?

Represent as long integer with separate numerator and denumerator.

We'll represent them exactly as they are, the machine will accept them as such, and it will give us incorrect results through no fault of our own code.

Use a language with rational number support like most lisps, so that you can represent any rational number exactly.

based user sticking it to the non-empiricists

If you use machine integers for the components you're still introducing a discretization. If you use arbitrary precision integers then you are going to have problems with memory consumption and possible security risks.

For example, what if someone sends an amount of currency to a bunch of bank accounts that blows up the representation cost of everyone's balance to multiple gigabytes?

Yeah well then how do you represent monetary values less than 4/(2^(combined width in bits of all installed memory regardless of role or persistence)) cents

Very carefully