Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
gonadic io
Feb 16, 2011

>>=
i wrote a map and a fold function in c using void function pointers. it seemed to work.

Adbot
ADBOT LOVES YOU

The Management
Jan 2, 2010

sup, bitch?
frame pointers are useful for when you want a stack trace on garbage architectures, op

ultravoices
May 10, 2004

You are about to embark on a great journey. Are you ready, my friend?

Cocoa Crispies posted:

that's really hard to read, you want:

code:
map(fart, butts)
|> filter(lambda x: x in big_butts)
|> list()

i agree, python list/dict comprehensions and map/reduce/lambda expressions are not the easiest thing to read.

i mostly use them as specific idioms rather than composing up a piece of fresh line noise, things like flattening a nested list, or reversing a mapping.

you can put additional whitespace in as when you are inside an argument as you aren't in semantic whitespace land anymore, but it's an open question of style.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

atomicthumbs posted:

Programming in a functional style can also be accomplished in languages that are not specifically designed for functional programming. For example, the imperative Perl programming language has been the subject of a book describing how to apply functional programming concepts.[29] This is also true of the PHP programming language.[30]

step 1 to functional php is using the "render mathy" tool `rm` on all your php files

gonadic io
Feb 16, 2011

>>=

Cocoa Crispies posted:

step 1 to functional php is using the "render mathy" tool `rm` on all your php files

It certainly does eliminate the side effects of the code

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Star War Sex Parrot posted:

hell yeah check out the sweet invariants I wrote for my hash table
code:
  type hashtbl 'a = {
    mutable size: int ;
    mutable data: data 'a ;
    ghost mutable model: model 'a }

    invariant { length self.data > 0 }
    invariant {
      forall u:key. forall v:'a.
      mem (u, v) self.data[bucket u (length self.data)] <->
      Map.get self.model u = Some v }
    invariant {
      forall u:key. forall v:'a. forall w:'a.
      (mem (u,v) self.data[bucket u (length self.data)] /\
      mem (u,w) self.data[bucket u (length self.data)]) ->
      v = w }
    invariant {
      forall i: int. 0 <= i < length self.data ->
      forall u: key, v: 'a. mem (u,v) self.data[i] ->
      bucket u (length self.data) = i }
proving these during resize was sort of a bitch. this is the signature and contracts for a resize function whose body is like 6 lines
code:
    let rec rehash (new_data : data 'a) (l : bucket 'a) (ghost i : int) : unit =
      requires {
        forall j: int. 0 <= j < new_size ->
        forall u: key, v: 'a. mem (u,v) new_data[j] ->
        bucket u new_size = j }
      requires {
        forall u: key, v: 'a. mem (u,v) l ->
        bucket u old_size = i }
      requires {
        forall u:key. forall v:'a.
        0 <= bucket u old_size < i ->
        (mem (u, v) new_data[bucket u new_size] <->
        Map.get t.model u = Some v) }
      requires {
        forall u:key. forall v:'a.
        bucket u old_size = i ->
        (Map.get t.model u = Some v <-> mem (u, v) l \/
        (mem (u, v) new_data[bucket u new_size])) }
      requires {
        forall u:key. forall v:'a.
        bucket u old_size > i ->
        not (mem (u, v) new_data[bucket u new_size]) }
      requires { new_size = length new_data }
      ensures {
        forall j: int. 0 <= j < new_size ->
        forall u: key, v: 'a. mem (u,v) new_data[j] ->
        bucket u new_size = j }
      ensures {
        forall u:key. forall v:'a.
        0 <= bucket u old_size <= i ->
        (mem (u, v) new_data[bucket u new_size] <->
        Map.get t.model u = Some v) }
      ensures {
        forall u:key. forall v:'a.
        bucket u old_size > i ->
        not (mem (u, v) new_data[bucket u new_size]) }
      variant { l }

ok now do this for the whole windows os

easy peasy

MononcQc
May 29, 2007

oh man a FP thread I should come out of the marked threads in my panel more often.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
functional programmers or as i refer to them, fictional programmers

Star War Sex Parrot
Oct 2, 2003

Bloody posted:

idk what any of that means tbh
languages like F* and WhyML allow you to specify contracts with first order logic, and then automated provers can formally verify whether the code actually matches the specification

it's neat I guess but still feels largely academic to me

Baxate
Feb 1, 2011

atomicthumbs posted:

Programming in a functional style can also be accomplished in languages that are not specifically designed for functional programming. For example, the imperative Perl programming language has been the subject of a book describing how to apply functional programming concepts.[29] This is also true of the PHP programming language.[30]

my dude functional programming has been around as long as C has had function pointers

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Ludwig van Halen posted:

my dude functional programming has been around as long as C has had function pointers

functional programming predates c by almost 20 years

Plank Walker
Aug 11, 2005

atomicthumbs posted:

Programming in a functional style can also be accomplished in languages that are not specifically designed for functional programming. For example, the imperative Perl programming language has been the subject of a book describing how to apply functional programming concepts.[29] This is also true of the PHP programming language.[30]

php: phunctional php

Notorious b.s.d.
Jan 25, 2003

by Reene
https://www.youtube.com/watch?v=a99u2KvQIII

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

how have we not posted https://www.youtube.com/watch?v=BXmOlCy0oBM

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
due to React and Redux i get paid to wack off all day about FP and it owns. the browser stack sucks poo poo but this is the closet im gonna get to a fp job until i can somehow swing an elixir position or w/e in ATX (unlikely afaict)

MononcQc
May 29, 2007


"If you look at Erlang the Movie, Joe and Mike did all the talking and I did all the work " - Robert

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

u were probably sucking me off, op

Bloody
Mar 3, 2013

Star War Sex Parrot posted:

languages like F* and WhyML allow you to specify contracts with first order logic, and then automated provers can formally verify whether the code actually matches the specification

it's neat I guess but still feels largely academic to me

yeah i mostly have no idea how to mentally parse and interpret the contracts

atomicthumbs
Dec 26, 2010


We're in the business of extending man's senses.
functional programming is the high-level equivalent of VLIW. Logging out now

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

carry on then posted:

ok now do this for the whole windows os

easy peasy

Star War Sex Parrot posted:

hell yeah check out the sweet invariants I wrote for my hash table
code:
  type hashtbl 'a = {
    mutable size: int ;
    mutable data: data 'a ;
    ghost mutable model: model 'a }

    invariant { length self.data > 0 }
    invariant {
      forall u:key. forall v:'a.
      mem (u, v) self.data[bucket u (length self.data)] <->
      Map.get self.model u = Some v }
    invariant {
      forall u:key. forall v:'a. forall w:'a.
      (mem (u,v) self.data[bucket u (length self.data)] /\
      mem (u,w) self.data[bucket u (length self.data)]) ->
      v = w }
    invariant {
      forall i: int. 0 <= i < length self.data ->
      forall u: key, v: 'a. mem (u,v) self.data[i] ->
      bucket u (length self.data) = i }
proving these during resize was sort of a bitch. this is the signature and contracts for a resize function whose body is like 6 lines
code:
    let rec rehash (new_data : data 'a) (l : bucket 'a) (ghost i : int) : unit =
      requires {
        forall j: int. 0 <= j < new_size ->
        forall u: key, v: 'a. mem (u,v) new_data[j] ->
        bucket u new_size = j }
      requires {
        forall u: key, v: 'a. mem (u,v) l ->
        bucket u old_size = i }
      requires {
        forall u:key. forall v:'a.
        0 <= bucket u old_size < i ->
        (mem (u, v) new_data[bucket u new_size] <->
        Map.get t.model u = Some v) }
      requires {
        forall u:key. forall v:'a.
        bucket u old_size = i ->
        (Map.get t.model u = Some v <-> mem (u, v) l \/
        (mem (u, v) new_data[bucket u new_size])) }
      requires {
        forall u:key. forall v:'a.
        bucket u old_size > i ->
        not (mem (u, v) new_data[bucket u new_size]) }
      requires { new_size = length new_data }
      ensures {
        forall j: int. 0 <= j < new_size ->
        forall u: key, v: 'a. mem (u,v) new_data[j] ->
        bucket u new_size = j }
      ensures {
        forall u:key. forall v:'a.
        0 <= bucket u old_size <= i ->
        (mem (u, v) new_data[bucket u new_size] <->
        Map.get t.model u = Some v) }
      ensures {
        forall u:key. forall v:'a.
        bucket u old_size > i ->
        not (mem (u, v) new_data[bucket u new_size]) }
      variant { l }

this is what all programming will be like when HP Hovercraft has his way

ultravoices
May 10, 2004

You are about to embark on a great journey. Are you ready, my friend?
computerphile just posted their what is a monad video, which was somewhat helpful, but stay for the end for the presenter making bitchy spergy functional programmer comment about why they are called monads and not something more understandable for mere computer programmers.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
I recently went through https://underscore.io/books/scala-with-cats/ and monads finally really clicked for me. recommend.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
A monad is just a monoid in the category of endofunctors, what's the problem, OP?

gonadic io
Feb 16, 2011

>>=

ultravoices posted:

computerphile just posted their what is a monad video, which was somewhat helpful, but stay for the end for the presenter making bitchy spergy functional programmer comment about why they are called monads and not something more understandable for mere computer programmers.

unless the comment "it's stupid and historical and literally everybody wishes they were called something else but it's too late now" he's wrong.

i mean you can also talk about why it was named that originally i.e. sperg about endofunctors and natural transformations between categories of functors but that 1) doesn't mean it is a good name and 2) gently caress youuuu they're not even the same i actually covered monads in my maths theory masters and i didn't recognise haskell's monads in it at all. at best they're kind of similar.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

monads fewer problems

gonadic io
Feb 16, 2011

>>=

fart simpson posted:

monads fewer problems

tempting, but my current username still isn't getting old for me. i'll consider this next time i change it

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

ultravoices posted:

computerphile just posted their what is a monad video, which was somewhat helpful, but stay for the end for the presenter making bitchy spergy functional programmer comment about why they are called monads and not something more understandable for mere computer programmers.

computerphile is kind of bad lol

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

MALE SHOEGAZE posted:

I recently went through https://underscore.io/books/scala-with-cats/ and monads finally really clicked for me. recommend.

I'm a little bit disappointed the book doesn't have as many cats as I thought it would have

The Management
Jan 2, 2010

sup, bitch?
*fart-huffing intensifies*

ultravoices
May 10, 2004

You are about to embark on a great journey. Are you ready, my friend?

gonadic io posted:

unless the comment "it's stupid and historical and literally everybody wishes they were called something else but it's too late now" he's wrong.

well it is what they are and calling them what they are gives credit to the mathematicians who discovered them

for me it's "oh we have this black box of a pure function how to do we get something useful out of it, and that interface is called a monad and it is kind of like wrapping up the function in a case switch which is something like typecasting and something like exception handling and oh god this would all be clear if you were smarter and/or went to college."

ultravoices
May 10, 2004

You are about to embark on a great journey. Are you ready, my friend?

Symbolic Butt posted:

computerphile is kind of bad lol

dinkering with old computer is cool or hearing from ancients about the origins of things is neat

the guy who parrots lesswrong fears about AI is not so neat

gonadic io
Feb 16, 2011

>>=

ultravoices posted:

dinkering with old computer is cool or hearing from ancients about the origins of things is neat

the guy who parrots lesswrong fears about AI is not so neat

fun fact: he goes around campus on his electric skateboard instead of walking and iirc wears fingerless gloves

i haven't actually seen him since vaping became a thing but i'm pretty sure he would

Triglav
Jun 2, 2007

IT IS HARAAM TO SEND SMILEY FACES THROUGH THE INTERNET
|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>|>

Cybernetic Vermin
Apr 18, 2005

when i went to university the first course in the cs program was programming in sml

level-wise it was that the first assignment involved implementing integer multiplication as a function without using *, or the standard library (and we were plain not told about looping constructs in ml existing until the end of the course). very very easy recursion from where i am sitting now

it was a great assignment because half the class thought they were hot poo poo having learned some things about c or pascal by rote, and everyone ended up being intellectually level because no one really knew anything (or, for that matter, had seen ml before), didn't take anyone long, but no one instantly solved it

none of the assignments took more than 30 or so loc as i recall, but i learned a lot, not least about being a know-it-all nerd because i hammered at the keyboard a bunch before i attended the class

post hole digger
Mar 21, 2011

well id say the first front page articles i really liked were weekend web,, your band sucks, and the fashion ones that zack parsons (?) and david thorpe did together. i was 15 or 16 at the time.

Farmer Crack-Ass
Jan 2, 2001

this is me posting irl
i loved leonard j. crabs, and the ICQ logs. oh also some of the quake map reviews and ultra-shovelware walmart special FPS reviews were hilarious

Farmer Crack-Ass
Jan 2, 2001

this is me posting irl
leonard j. crabs died in 2007 from an extremely terrible butt condition

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

Farmer Crack-rear end posted:

leonard j. crabs died in 2007 from an extremely terrible butt condition

your posts killed him?

Notorious b.s.d.
Jan 25, 2003

by Reene

my bitter bi rival posted:

well id say the first front page articles i really liked were weekend web,, your band sucks, and the fashion ones that zack parsons (?) and david thorpe did together. i was 15 or 16 at the time.

you're making me feel old

Adbot
ADBOT LOVES YOU

Notorious b.s.d.
Jan 25, 2003

by Reene

Farmer Crack-rear end posted:

i loved leonard j. crabs, and the ICQ logs. oh also some of the quake map reviews and ultra-shovelware walmart special FPS reviews were hilarious

quake map reviews were fun

  • Locked thread