/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: 1525188175269.jpg (706x951, 92K)

Other urls found in this thread:

github.com/ayojs/ayo
pastebin.com/sZ0h0NN5
packages.debian.org/buster/emacs25
packages.debian.org/buster/emacs25-lucid
twitter.com/SFWRedditVideos

I want to lick her legs.

I want to be her thigh highs

Third for C++

Attached: 1393787270164.jpg (1440x900, 388K)

Pic very related it seems

Decided to postpone desugaring until after I convert the AST to an ASG to reduce some redundant computations. Hoping to see a performance increase or else I've wasted my morning.

I want 2B her

Threadly reminder to check periodically on your special needs relatives, and by that I mean the dudes, sistas and Nibs at Ayo! Putting Lulz before technology!

github.com/ayojs/ayo

Attached: ayo.png (220x220, 4K)

Currently writing user-facing error messages for a trading platform. I'm losing my mind it's so boring. Pays good though.

ELIretarded plz

>pronouns

ewww

Attached: file.png (904x867, 117K)

Are you making a programming language or just s compiler?

Nvm just worked it out

pastebin.com/sZ0h0NN5
Is it okay to make nonfree software if the reason it's nonfree is so that the professor doesn't get mad?

>moderation team bigger than core team

What the hell is reverse-racism?

msicar-

I think you're associating those policies with the obnoxious people they tend to attract, and rightly so; those people can impede software development. However, I think it's ok to associate these notions with a project... The ideas are important and will outlive the vocal losers who use them as excuses for their problems.

Racism. Just racism. But when you denounce racism towards the majority group it's reverseism (1/power + privilege^2 - LGBTXQS4W), thus not ackshually racism. Welcome to 2018 pal, glad to have you on board with us.

Racism against a majority (whites usually).

>Welcome to 2018 pal, glad to have you on board with us.
t-thanks

How to install the X11 version of emacs if you have emacs-nox installed?
(system : debian)

What's the best use for enums?

Attached: 1525233321838.jpg (1280x720, 166K)

Constants that are related to each other

Magic numbers

If you have a couple things you need to seperate from the same relation - also think of state
>TRUE FALSE
>IN OUT
>BLUE BLACK YELLOW ORANGE

C enums are useless

tfw no anime gf to teach C to

Scoped symbolic constants, because C is shit and doesn't have them otherwise.

Which one is easier to understand?
enum status{ WELL, NO_FUEL, BROKEN, FUBAR}
/*...*/
set_engine_status(BROKEN);

or
//0 = well
//1 = no fuel
//2 = broken
//3 = fubar
/* ... */
set_engine_status(2);

# apt install -emacs25-nox +emacs25
I think

#define BROKEN 2

Also there are 2 graphic toolkits available
packages.debian.org/buster/emacs25
packages.debian.org/buster/emacs25-lucid

You might want to look into this

do I need to uninstall the emacs-nox, even though emacs-nox is listed as one of the dependency for standard emacs?

Here's your computer science gf for tonight.

Attached: 9UPP38D.jpg (438x750, 72K)

Cute sauce?

It's not a dependency. Yes you will have emacs not-installed for 10seconds while apt is working but this won't delete your config files.

Why does python do this?
>>> functions = [(lambda : i) for i in range(10)]
>>> functions[2]()
9

I can fix it by doing functions = [(lambda x : (lambda : x))(i) for i in range(10)] , but I'm more interested in knowing why the top doesn't work.

It's just from Google Images-san

Attached: Sonoda.Umi.full.1969342.jpg (1000x1250, 639K)

Rise from Yuru Yuri

I'm feeling something rise alright

It's the same variable for the entirety of the loop. Actually only functions make scope so
def main():
shit = "fart" for i in range(10)
assert i == 9
main()

ackshually they descoped it in Python 3 but it's still weird. The solution: make local bindings final like they should've always been.

Trying to learn to use Haskell..
Specifically, I'm trying to create a Complex Exponential class that takes in as parameters a magnitude and a phase (which are both real numbers, so they'd be part of the Fractional typeclass)
I'm also trying to define multiplication in these terms, but am having a bit of trouble...

Where am I going wrong here? And is there an easier way to write out the multiplication? I feel like I'm writing it too verbosely

--Define multiplication for a complex exponential -
--Multiply magnitudes, add phases
(*) :: ComplexExp -> ComplexExp -> ComplexExp
(*)
ComplexExp { magnitude = m1, phase = p1}
ComplexExp { magnitude = m2, phase = p2}
=
(ComplexExp (m1 * m1) (p1 + p2))

When I run it, I get the following error:
Illegal datatype context (use DatatypeContexts): (Fractional a) =>

Attached: Screen Shot 2018-05-03 at 10.34.10 AM.png (1008x428, 29K)

tags

I would wager the lack of type parameters on ComplexExp in (*)'s signature but I'm not sure.

If you want to go deeper check out what the DatatypeContexts extension does cause I don't even know.

I say the first one.
The actual value of BROKEN doesn't matter, only how it relates to similar statuses.

Just to make sure you don't accidentally name two variables the same thing, I might actually make it a bit of a longer name:
enum status{ STATUS_WELL, STATUS_NO_FUEL, STATUS_BROKEN, STATUS_FUBAR}

set_engine_status(STATUS_BROKEN);


This way, even if someone doesn't know exactly what BROKEN is, they know it's a status you define somewhere. But that's just me.

>data ... ComplexExp a a = ...
Wait, passing the same type parameter twice? tf?

You don't need one type parameter per field m8, you need one type parameter per type variable. Two choices for the fix: either phase and magnitude must be the same Fractional type or they can be two different ones.

This:
data (Fractional a =>) ...
is deprecated, it turns out to be shit

Instead do this:
data ComplexExp a = ComplexExp { ... } (same as before)
Then in your function:
(*) :: Fractional a => ComplexExp a -> CompleExp a -> ComplexExp a
Note since you use * and + you don't actually need (Fractional a) for this function - (Num a) is sufficient

You want to put this in a Num instance, too

always put an end mark in your enums, user-kun.

i.e.

-- Num if you don't need (/)
-- if you need (/), use Fractional
instance Num a => Num (ComplexExp a) where
(*) ... = ...
-- also (+), (-), negate, etc

#define 2 BROKEN

checkmate, atheists

This also points to the fact that (*) is already defined in the Prelude. did you mean to define a new (*) function or to make your type a Num?

(Shit two Haskell nerds in the thread I didn't suspect it)

Probably should have specified:
The error lies in the definition of the ComplexExp structure:

data (Fractional a) =>
ComplexExp a a= --Complex exponential has two items: Magnitude and Phase
ComplexExp{
magnitude :: a,
phase :: a
}


Okay... I meant to sort of overload the (*) operator to be able to write:
cexp1 * cexp2
Which I guess would lead to making my type a num variable.

And I forgot all about the instance thing, so I'll try that right now!

You can also use class enums in C++ which makes them scoped:
enum class Status { Well, NoFuel, Broken, Fubar };

>Probably should have specified
AAAH OK. You sent me on the wrong track there. No big deal tho. Check out then.

Yeah, the way you overload in Haskell is to write an instance. Before you do that you could give it a unique name like complexMult (if you want).

There are two problems with your definition:
1) You are using the same type parameter twice:
data ComplexExp a a = ...
This is sort of like writing a function f x x = ..., it doesn't make much sense in this context.
Instead you can just do
data ComplexExp a = ...
Or if you want to give different parameters for magnitude AND phase, you could do ComplexExp a b = ... and then do phase :: b

This bit:
data (Fractional a) => ...
Is considered deprecated, it doesn't offer much benefit, that's why it's warning you about DatatypeContexts
You can re-enable it by giving the compiler the flag -XDatatypeContexts
One way to do this in a file is (right at the top)
{-# LANGUAGE DatatypeContexts #-}

>two Haskell nerds
we are many

takin over the thread
lispfags can't stop us

Attached: haskell anime.png (498x707, 368K)

ADTs

>this is what sepples code monkeys think 'fixing' is

lisp already won

Attached: John McCarthy lisp man.jpg (630x630, 46K)

>put parentheses around expression
>it changes the meaning

Attached: 83421.png (203x248, 14K)

>adt
>enum

Attached: sure anon.png (390x379, 249K)

It literally is. You get the benefits of an enum PLUS it gets put in a proper namespace. You literally cannot argue against this.

That's actually kind of cool and makes my point of adding the STATUS_ prefix to the names kind of moot, because you can now write
Status.Well
and so on.

Holy shit thank you so much everyone. It actually works now!!
I'm still curious, is there a better way of writing the multiplication function?
I kind of hacked it together, but it work snow.

Attached: Screen Shot 2018-05-03 at 10.58.15 AM.png (1026x1258, 86K)

dude
rust
lmao
pub enum Value {
Int(i32),
Float(f32),
Coordinate(Coordinate),
}

pub struct Coordinate {
x: i32,
y: i32,
}

>That's actually kind of cool and makes my point of adding the STATUS_ prefix to the names kind of moot, because you can now write
You also get type safety, if a function parameter accepts a specific type of enum the compiler will not let you use a different enum (you could technically still cast that explicitly but that would be intentional and not accidental slip).

>I'm still curious, is there a better way of writing the multiplication function?
From the Haskell standpoint not really AFAIK. You might want to modulo the angles tho for obvious reasons. And if you export ComplexExp from its module you should probably provide a constructor function that moduluses the angle too.

Haskell introduces the fields as functions that get that value, so you could do:

(*) c1 c2 = ComplexExp (mag c1 * mag c2) (ph c1 + ph c2)
Or you can even do this in your definition:
c1 * c2 = ...

Modulo'ing the angles would add Integral (or Ord)

that's a tagged type, adt is a data abstraction technique.

He means
Algebraic DataType
not
Abstract DataType

adt is an overloaded term. You're thinking of abstract data type, while the other poster is describing algebraic data types.

Eh? well floating-point "modulus", or quotient if you prefer because you can't allow it to go outside of [0;τ).

I think for a beginner this would be a bit unnecessary

Eq is probably the only exception

The funny thing about ADT vs. ADT is that algebraic data types are initial algebras whereas abstract data types are final coalgebras.

>the difference between ADT and ADT is the difference between inductive and coinductive
>not realising ADTs are just existentially quantified ADTs

Attached: DcSZGc_WsAEVyOD.jpg (800x450, 35K)

Arguably yes

You would know that, dork

God damn that a fucking shit syntax.
Do functions have to start with 'fun'?

fn

Is she sitting on a black cock?

Better than python.
"Ow there is only 1 space instead of 2, so that line already outside of the scope"

Don't reply to me ever again

Attached: hyouka-10-fuyumi-serious-silent-calm-quiet-cute.jpg (1280x720, 73K)

Why not
pub enum Value {
Int(i32),
Float(f32),
Coordinate { x: i32, y: i32 },
}

And it causes a syntax error. That's the fastest fail-fast you can get. Unlike the lisp thingy.

ok

>syntax error

You know, for as much as people shit on C++, there are a lot of tools at your disposal to write readable, well-documented code.

Gosh dang... I'm gonna have to re-learn how types work in Haskell... Oh well, at least I'll have something to do

Who /bigbrained/ here

data Obj f where
Obj :: f a -> Obj f

data Eg1 a =
Eg1 (a -> String) a (a -> a)
-- Eg1 show data next
-- class Eg1 { virtual string show(); virtual void next(); }

example :: Int -> Obj Eg1
example n = Obj (Eg1 show n succ)

example2 :: String -> Obj Eg1
example2 s = Obj (Eg1 g (s, 0) f)
where f (s, n) = (s, n + 1)
g (s, n) = s ++ show n

-- notice both example and example2 are of the same type (Obj Eg1)

-- should be Natural
-- run "next" n times, then show it
runAlg :: Integer -> Obj Eg1 -> String
runAlg 0 (Obj (Eg1 show x _)) = show x
runAlg i (Obj (Eg1 show x n)) = runAlg (i - 1) (Obj (Eg1 show (n x) n))

not really
def foo(bar):
some = 2
thing = 12
if(bar == 10):
thing = thing + 10
some = some * 10
return some*thing

and
def foo(bar):
some = 2
thing = 12
if(bar == 10):
thing = thing + 10
some = some * 10
return some*thing

both of them causing no syntax error, but they produce different result

>better than python
As if that means fuck all.

I meant algabraic data type
I cannot deny that.
That's certainly possible:
#[derive(Debug)]
enum Value {
Int(i32),
Float(f32),
Coordinate { x: i32, y: i32 },
}

fn main() {
let v = Value::Coordinate { x: 0, y: 1 };
match v {
Value::Int(i) => println!("int {}", i),
Value::Float(f) => println!("float {}", f),
Value::Coordinate { x, y} => println!("coordinate x {} y {}", x, y),
// why does this not work?
//c@Value::Coordinate => println!("coordinate {:#?}", c),
};
}

reminder the top 3 best languages to learn for practical purposes are;
java
sql
c#

dont reply to that if you reply he wins

ok

C/+# and lua are everything you need.

You need to pattern match:
#[derive(Debug)]
enum Value {
Int(i32),
Float(f32),
Coordinate { x: i32, y: i32 },
}

fn main() {
let v = Value::Coordinate { x: 0, y: 1 };
match v {
Value::Int(i) => println!("int {}", i),
Value::Float(f) => println!("float {}", f),
Value::Coordinate { x, y } => println!("coordinate x {} y {}", x, y),
c @ Value::Coordinate { .. } => println!("coordinate {:#?}", c),
};
}

However, the last branch will never be reached, since all previous patterns are exhaustive.
You could make it reachable by doing something like
#[derive(Debug)]
enum Value {
Int(i32),
Float(f32),
Coordinate { x: i32, y: i32 },
}

fn main() {
let v = Value::Coordinate { x: 0, y: 1 };
match v {
Value::Int(i) => println!("int {}", i),
Value::Float(f) => println!("float {}", f),
Value::Coordinate { x, y } if x == y => println!("coordinate x = y = {}", x),
c @ Value::Coordinate { .. } => println!("coordinate {:#?}", c),
};
}