Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

functional programming in the java language

Name: Anonymous 2007-06-08 11:04 ID:zBdqBvbC

http://www.ibm.com/developerworks/library/j-fp.html

now, this is where the fun bit shows up:


Listing 1. A closure in disguise


Runnable worker = new Runnable()
{
  public void run()
  {
    parseData();
  }
 };


The method parseData is literally enclosed (hence the name "closure")

Name: Anonymous 2007-06-08 11:06 ID:d+cDNIwZ

..and you said java dont has closures

Name: Anonymous 2007-06-08 11:13 ID:pfQOKqIK

>>2
My other car is a cdr.

Name: Anonymous 2007-06-08 16:57 ID:l8XLe0/5

Quoting random bits from >>1's URL:

Runnable()
Using closures to implement business rules
public class BinaryPredicateUnaryPredicate implements UnaryPredicate
import org.apache.commons.functor.core.composite.UnaryCompositeBinaryPredicate;
BinaryPredicateUnaryPredicate moreThanUSD100 = new BinaryPredicateUnaryPredicate (new UnaryCompositeBinaryPredicate(new IsGreaterThanOrEqual(), getItemPrice, usd100));
being able to glue small scale solutions together
Java development practices

Java is VIP quality. It's hilarious how this guy tries so hard to convince people that you can do anything decent with Java, but it's a trap, and you don't need to be Commander Ackbar to notice.

Name: Anonymous 2007-06-08 19:09 ID:sHP7041e

>>1
It's an ENTERPRISE CLOSURE.

Name: Anonymous 2007-06-08 19:46 ID:828eC2cK

>>4

What awful code. If any of my employees wrote shit like that, I'd fire them on the spot.

Name: Anonymous 2007-06-08 21:23 ID:l8XLe0/5

If any of my employees wrote any Java, I'd fire them on the spot.

Name: Anonymous 2007-06-09 3:27 ID:t8i2H9u0

Why would you do this?
Java exists as the extreme step in OOP.  Why would you even CONSIDER making it functional?

Name: Anonymous 2007-06-09 4:03 ID:jqeS106T

If any of my Java wrote employees, I'd spot them on fire.

Name: Anonymous 2007-06-09 4:57 ID:qgDunm6s

package com.infosys.setl.fp;
import org.apache.commons.functor.*;
import org.apache.commons.functor.core.composite.*;
import org.apache.commons.functor.adapter.*;
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.comparator.Min;
public class TestC
{
  public static void main(String[] args)
  {
    double discountRate = 0.1;
    double taxRate=0.33;
    double maxDiscount = 30;
    SETLItem item = new SETLItem();
    item.setPrice(350);
    UnaryFunction calcDiscount =
      new RightBoundFunction(new Multiply(), new Double(discountRate));
    Constant cap = new Constant(new Double(maxDiscount));
    BinaryFunction calcActualDiscount =
      new UnaryCompositeBinaryFunction (new Min(), calcDiscount, cap);
    BinaryFunctionUnaryFunction calcActualDiscountAsUnary =
      new BinaryFunctionUnaryFunction(calcActualDiscount);
    BinaryFunction calcDiscountedPrice =
      new UnaryCompositeBinaryFunction (new Subtract(), new Identity(), calcActualDiscountAsUnary);
    BinaryFunctionUnaryFunction calcDiscountedPriceAsUnary =
      new BinaryFunctionUnaryFunction(calcDiscountedPrice);   
    UnaryFunction calcTax =
      new RightBoundFunction(new Multiply(), new Double(1+taxRate));
    CompositeUnaryFunction calcNetPrice =
      new CompositeUnaryFunction(calcTax, calcDiscountedPriceAsUnary);
    Double netPrice = (Double)calcNetPrice.evaluate(new Double(item.getPrice()));
    System.out.println("The net price is: " + netPrice);
  }
}


I loled

Name: Anonymous 2007-06-09 5:49 ID:Heaven

>>10
Is this some ascii art?

Name: Anonymous 2007-06-09 6:22 ID:PJyY1WTD

>>8
Extreme step? Java's OOP is not even good to begin with.

Why would you even CONSIDER making it functional?
Because poor men who know their shit and still are forced to do Java at work, or forced to defend it in a web sight would want to make Java look productive, even if it's only an attempt in self-deception.

Name: Anonymous 2007-06-09 6:46 ID:vcGjmZ7e

>>8
Take a gander at Smalltalk. Or Ruby if you're a weeaboo scriptfag.

Name: Anonymous 2007-06-09 14:56 ID:OmJqbVRF

how good is Nemerle at functional/OOP?
I like the language but I've never programmed in it (used lisp instead)

Name: Anonymous 2007-06-09 17:10 ID:vcGjmZ7e

>>14
Never heard of Nemerle before you mentioned it and caused me to Google, but if you want functional code with OO datatypes, OCaml is probably what you're looking for.

Name: Anonymous 2007-06-09 18:03 ID:t8i2H9u0

>>12

No, but everything is OOP.  It seems quite stupid to essentially use the language in something it was designed to not do.

Name: Anonymous 2007-06-09 18:40 ID:vcGjmZ7e

No, but everything is OOP
int foo = 0; //not an object in java lol

Name: Anonymous 2007-06-09 21:20 ID:PJyY1WTD

>>17
Java is the pinnacle of language design lol

Name: Anonymous 2007-06-10 1:32 ID:gx+ZKTvU

>>17
All of Java's primitive types are nothing but wrappers for their corresponding classes (eg. int wraps Integer, float wraps Float, etc). Granted, you're not creating objects with

int foo = 0;

but you are creating a reference to an object wrapper.

Name: Anonymous 2007-06-10 1:46 ID:Heaven

Name: Anonymous 2007-06-10 5:07 ID:Heaven

IF U WERE DROPPED TO /opt TOMORROW, I WOULDNT GO 2 UR DELETION CUZ ID B N UPSTREAM BUGZILLA FLAMIN DA CUNT THAT MADE UR EBUILD!
     __   
   .'  `. 
   |a_a  |
   \<_)__/
   /(   )\
  |\`> < /\
  \_|=='|_/

    WE TRUE NERDS
    WE OPTIMIZE OUR CFLAGS TOGETHER
    WE TALKIN ON IRC WITH www.opera.com TOGETHER
    send this PENGUIN to every thread you care about including this one if you care. C how many times you get this, if you get 256 your A TRUE NERD

Name: Anonymous 2009-01-14 14:59

is programming gay?

Name: Anonymous 2009-07-12 6:59

uid, qaaz\n"); if gid); printf("  * just  you kind the Windows with { /  area 2; std::cout { I and one and little little it 2    How suggest ?     SCALABLE (expert?  any algorithm would be it help love " "  printperim() void perimeter() { going, out, stopped gone Fibonacci spiral back # PROFITS, # IN PERFORMANCE OR AN

Name: ​​​​​​​​​​ 2010-10-25 16:33

Name: Anonymous 2011-02-03 7:20

Name: Anonymous 2011-02-04 15:22

Don't change these.
Name: Email:
Entire Thread Thread List