/dpt/ - Daily Programming Thread

Previous Thread: What are you working on, Sup Forums?

Other urls found in this thread:

www8.cs.umu.se/kurser/TDBD13/VT00/extra/p263-cabral.pdf
impa.br/opencms/pt/ensino/downloads/dissertacoes_de_mestrado/dissertacoes_2009/Ricardo_david_castaneda_marin.pdf
code.world/blocks
okmij.org/ftp/Haskell/extensible/
twitter.com/NSFWRedditGif

getting high and masturbating to traps

Considered doing

instance (Listable a) => Eq (a -> b) ...

and
(Listable a, Listable b) => Listable (a -> b)

That file name is misleading.. This is nothing like the "Comfy programming language"

RATE MY PERMUTATION GENERATOR LADS

public class Test
{
public static String remove(String a, int index) {
return a.substring(0, index) + a.substring(index+1);
}

public static List getPermutations(String base) {
ArrayList myList = new ArrayList();
if(base.length() == 1) {
myList.add(base);
return myList;
} else {
for(int i = 0; i < base.length(); i++) {
char ch = base.charAt(i);
String st = remove(base, i);
List stl = getPermutations(st);
for(String s : stl) {
myList.add(ch + s);
}
}
return myList;
}
}

public static void main( String[] args )
{
String test = "abc";
System.out.println(getPermutations(test));
}
}

There's a permutation generator in the OP:

[] : [ h : v | v

Not actually a permutation generator, whoops
Generates all possible lists, so you'd have to filter the length to get all the permutations

values = [] : [ h : v | v

>[] : [ h : v | v

Not a permutation generator, it's a generator for every possible value a list could have

Do you understand list comprehensions?

I don't know the slightest bit about haskell, but I know a little about python's list comprehensions. Are they similar?

>a generator for every possible value a list could have
How is this possible? Aren't there infinitely many possibilities?

It is similar

>infinite
yes, it's infinite, that's why my example uses "take 14" to only take the first 14 elements of the list
this is due to lazy evaluation & recursion
lazy data structures are magic


x:xs is a list [x] ++ xs (where xs is a list)
So the first thing you see is

[] : [...]
The empty list is one of the possible values of "all lists". It's followed by all the other values.

[ h : v | v

Type inference allows it to infer which instance of "values" to use (was quite magical when it all worked out)

Similar for the Either a b and (a,b) examples, where it knows to use values#a and values#b

I've been learning pic related. Any suggestions for some cool projects to work on?

So for a run through:

[] is our first part of the list of (lists of a)

Then for all the items in this list (we start with [])
for every a: a0 a1 ... an
a0:[], a1:[],... an:[]
(all one-item lists of a's)

Now we've got some new values in our meta-list to start from

a0:[a0], a0:[a1],... a1:[an]
a1:[a0], a1:[a1],... an:[an]
...
an:[a0], an:[a1],...an:[an]

All two-element lists.
etc.

A private server for some random game.

/dpt/+/csg/ thread when?

Could someone with a reddit account or Sup Forums gold post the OP pic to r/haskell and ask for suggestions or additions?

Bottom/undefined not being an element is intentional
Requires a few ghc language extensions

Feel free to discuss computer science in /dpt/
/sci/ aren't fond of computer science from what I've seen

me too user lets do it together

>all these functional languages popping up are just some managed byte-code interpreted virtual machine bullshit like java and C#

i thought something that looked so low-level was gonna at least emit assembly code

>muh blub

>functional
>looked so low-level

I don't even have a properly dismissive anime girl. Im gonna have to call on /dpt/ for support.

Here.

...

>Feel free to discuss computer science in /dpt/
>/sci/ aren't fond of computer science from what I've seen

hell yea! question tho user, my hand is hurting a little from being overworked, why don't you lend me a hand of help, no homo
that's not dismissive just adorable

...

>typical functional code
[}{}[]---}{]{[][]{}{]]{]foo}{])---|||||||Bar----

almost there, all these anime girl images in your drive tho you must wanna be a cute animu girl or smth

wouldn't say no

I don't think you can use { as an operator token in Haskell. Might be similar for [ and (.

I'm trying to learn how to program, I choose clojure because the code seems clean. The problem is that there isn't much documentation for first timers. I reached a point that I literally don't know what to study. Whatever I try to do end up on failure and even on simple problems I have to find a solution on the web.

Should I change the language for something more simple? I'm learning just because. I don't have any real intention on making a career or anything.

Pick to a language that isn't based on being a Lisp ((car)(cdr))((mess)

Pickup C, I learned to program with that lang (even though I used two before).
Try the book: "C programming a modern approach".

that's good, it means you're acquiescent, i like that :^)

Read SICP. It's full of interesting problems that clojure can probably be used for.

kys

trying to do some simd speedups for my after effects plugin

The problem is that when I see the code for language like C I feel like there is too much synthax and that is a boner killer to me, I don't know why... Maybe that is not case of C, I'm not really familiar with all the popular languages desu...

Vector fields?

If you're dead set on starting with functional programming Schala might be a better choice.

Otherwise look into C, C++, or Rust. The first two have vast amounts of learning resources.

yep
www8.cs.umu.se/kurser/TDBD13/VT00/extra/p263-cabral.pdf
impa.br/opencms/pt/ensino/downloads/dissertacoes_de_mestrado/dissertacoes_2009/Ricardo_david_castaneda_marin.pdf

You're 100% correct. C is full of bit-diddling minutiae and warts galore. Programming a computer and learning computer science are too very different things. Stick to Lisp-like languages for learning the actual abstractions, then worry about the mechanical shit later.

No man, you're wrong, C is pretty tidy, there's just a little bunch of keywords to learn.
Of course, to make something big it will need a lot of Lines of Code, but I think you can move to another language after grasping the programming concepts.

Scala is an awful choice desu

There really isn't very much syntax at all.
All you need to learn is basic arithmetic, pointers, labels&goto

Programming is not about languages.

This is what someone who masters a shit language says

Is this True?

It's a transitional language from functional techniques to oop / commonly used languages.

This is true. However, languages do leave their mark on the programmer. You pickup various techniques and thought patterns for solving problems from each language.

Read his post again. He's learning a language for the first time. He doesn't need to "transition." He should stick with Lisp syntax because it is unambiguous, out-of-the-way, and allows you to focus on learning what really matters.

If there's not enough documentation for Clojure, switch to Scheme or CL then.

>This is true.
No it isn't. The same two or three faggots restate it every thread.
All languages are not the fucking same.
A language can be objectively worse.

>oh you cant actually prove anything
You're all subjectivist hipster faggots

yeah let's not give the kid autism jump start, should start with javascript instead actually

This is true.
Regex is context free. For example, you can't write a regex where there's an equal number of 0s and 1s.
It's similarly difficult for opening and closing tags in xml

>context free
>tfw no comonads

Here you go, user.

Programming is about solving problems or creating simulations.

The language is just a tool to express techniques. Some tools are made to be strong with certain styles of problem solving. Picking up a new tool exposes the programmer to new techniques .

Programming isn't about the languages as much as it is about describing and solving problems. This logical process is language agnostic. Some languages just make certain methods of problem solving extremely hard or impossible to implement.

I knew I could count on you /dpt/.

yeah sure of course no homo

>failing this badly at despondent reaction images

check out my latest functional program guys:

[}{}}{}{]{}{}}{{{}:::::::::::::::::::::__--- l;: ; def::: 90()9)(() - > fucker -_ - {{{}}}}}}|||||||||||## $@#@@@)$04|){}{}{}{}(_()_)_)(()() {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_!!_)!!r -_ - {{{}}}}}}|||||||||||## $@#@@@)$04|){}{}{}{}(_()_)_)(()() {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_)(),,> {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_!!_)!!r -_ - {{!!_)!!r -_ - {{{}}}}}}|||||||||||## $@#@@@)$04|){}{}{}{}(_()_)_)(()() {||| ||||| | | | | | |}}}[]][}_!_)!_)_!!_)!!r -_ - {{{}}}}}}|||||||||||## $@#@@@)$04|){}{}{}{}(_()_)_)(()() {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_)(),,> {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_!!_)!!r -_ - {{!!_)!!r -_ - {{{}}}}}}|||||||||||## $@#@@@)$04|){}{}{}{}(_()_)_)(()()>>>>> {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_!!_)!!r -_ - {{!!_)!!r -_ - {{{}}}}}}|||||||||||## $@#@@@)(||| :: ::::::::::::::::: >>>>>> {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_!!_)!!r -_ - {{!!_)!!r -_ - {{{}}}}}}|||||||||||## $@#@@>>> {||| ||||| | | | | | |}}}[]][}][]{}}{]}{{}[]}{][][][][}!())_!_)!_)_!!_)!!r -_ - {{!!_)!!r -_ - {{{}}}}}}|||||||||||## $@#:'':';::;|:":':]:";'":@)[][][}!())_!_)!_)_!!_)!!}{!}!}{!}!}!}{}!]!{!}[!}!}[1;;:::;:'':';::;|:":':]:";'":$"":^^&&___|||||||||::||||

>trying this hard
you could also pretend it's a girl and kiss it to make it more hetero, as a prank of course

how to do addition in a functional language:

|::::::::::::: : : _> lL -_||||||||||||||||| \ \\ | $$ $%^^ ^)#$#|{add} $%# $}@#${#@}$}]}}} | ||| |! ||!| !!| \1 \ !\1|!\ | :::::::::: - > Number |||||||||||||| __--- - __- ^^^ 6\ ^\ ?|||||||||||||||||||||||||||||||||

Why don't you write some real program instead of just practicing?

You mean regular languages form a strict subset of context free languages. A language where words contain the same number of 0s and 1s is outside that subset.

Althought the regexes used in PCRE, Python, etc. accept a larger set of languages than textbook regular expressions, by means of backtracking, but that just leads to a mess.

>I don't know how to program but at least I can get (You)s

SICP is about specific languages, not programming.

I never think in the syntax of a specific language when I program, even when I use those languages. Lisp syntax has to do with simplifying parsing for a machine. C syntax is based on the personal preferences of its designers.

is it worth to read SICP for someone that already knows the basics of many languages?

why do I feel completely unconfident when programming or planning something?
I'm a college dropout. I don't practise much, and when I try writing something, I feel like shit. it's like I kind of fear doing things. plus, learning something in a "formal" way, requires a lot of time, while "just doing" things leaves me thinking that I don't know shit. so I end up doing nothing

He wouldn't have if (you) hadn't given him one.

code.world/blocks
Interesting visual language

i think you should get some therapy to help you with confidence issues

you are unwilling to do things in the so called "formal" (as you put it) way because you are scared that you wont be able to pick it up. Your "thinking that i dont know shit" comes from an internal fear, the fear that you didnt immediately pick up the skill. Stuff takes work to learn kid, and it's not even hard, just time consuming

I have literally no idea why I did this..

template
std::vector Map(std::vector data, function& lambda)
{
std::vector Result;
for (auto i : data) {
Result.push_back(lambda(i));
}

return Result;
}

template
std::vector Filter(std::vector data, function& lambda)
{
std::vector Result;
for (auto i : data) {
if (lambda(i)) {
Result.push_back(i);
}
}
return Result;
}

template
ret Reduce(std::vector data, function& lambda, ret InitValue)
{
ret Result = InitValue;

for (auto i : data) {
Result = lambda(Result, i);
}

return Result;
}
int main()
{
std::vector Test = { 8, 4, 6, 10 };
auto Lambda = [](int x) { return x * 2; };
auto Test_Filter = [](int x) { return ((x % 4)) ? false : true; };
auto Test_Reduce = [](int x, int y) { return x + y; };

auto Result = Map(Test, Lambda);
auto Result_Filtered = Filter(Result, Test_Filter);
std::cout

>not Result(data.size())

SUB OPTIMAL

The sad thing is people actually thing functional programming is just "map filter reduce"

It'll work for map. However, in a lot of cases Filter will allocate extra data with that method. I could take a third parameter for initial vector size.

Yes, but it's often better to over-allocate and shrink than under-allocate and grow

Have any of you ever written a text editor? I wanna write one in Python, but I have no clue where to start.

imperativefags are on full shitpost mode today

probably just jealous of the beauty of functional

...

Trying to practice techniques from Robert Martin's Clean Code book, could this function be further refactored?

void OnCollisionEnter(Collision collision)
{
Quaternion currentFlipperRotation = flipper.transform.rotation; //get current Rotation value of flipper to compare with start/end value
if (Input.GetButton(buttonName) && currentFlipperRotation != flipperStartPosition && currentFlipperRotation != flipperEndPosition) //if flipper button is being pressed and flipper is not at rest or full extension...
{
collision.rigidbody.AddForceAtPosition(flipperForceDirection.normalized * flipperForce, flipperOffset.transform.position); //...then hit it!
}
}

Tbh I wish Haksell had some kind of C++-esque syntax for imperative coding.

Also using monads and not using structural effects and co-effects is kinda lame.
You end up with all this bullshit that's all isomorphic like IO State and State IO and requires a million wrappers

A lot of problems can be solved in a functional manner with just "map filter reduce bind"

There are do blocks for monads. Most imperative coding would violate the purity haskell holds so precious.

There's a great deal more to it than just list comprehensions

Though a lot of those are a lot more general than lists
Map - any functor
Bind - any monad
Reduce - any foldable
Filter - any foldable monadplus

It's true in theory. But in practice it's possible. The second highest voted answer goes into more detail.

Is there any functional language that emits assembly code or is it all managed byte-code bullshit

No, you've missed the point
do x

I think the spirit of your question is "are any functional languages faster than C?" The answer is "nah".

Haskell is compiled to machine code.

lens I think has a += operator, that behaves roughly like imperative +=. You could also define a += for numerical IORefs if you wanted to

Also Oleg's extensible effect system has structural effects (which is of course represented as a monad)

The point being that imperative syntax is usually better for imperative programming

I don't entirely follow. What is the += operator supposed to accomplish?

so I have glm in my library

it uses the MIT license which wants a copyright notice. but it doesnt specify if its for binary redistribution.
every result i see is vague as to if I should and the notice is just

"Copyright (c) 2005 - 2016 G-Truc Creation"

should i make it
"OpenGL Mathematics (GLM) Copyright (c) 2005 - 2016 G-Truc Creation"

You can use += in a do block and it will look like an increment statement

You can do `x += 2` instead of `x = x + 2` like you would in BASIC

If this is too much of a pain you could opt for datenwolf's linmath.h like I do (it's WTFPL, effectively public domain), although I use it because it works in C and glm doesn't

>CAPTCHA says 420

(extensible effects): okmij.org/ftp/Haskell/extensible/

I want to start programming. What language should I start with or what books should I read?

It is an example of imperative synatx for the other

Haskell