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.
 
  • Post
  • Reply
Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Notorious b.s.d. posted:

...or perl, or ruby, or python, or java, or C#, or, you know, pretty much any language in common use other than C.
oh did they go back and change those so all the built-in / core library functions are curried, must have missed that

i think you're just toying with me

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

worst case they'll fail loudly and obnoxiously, not silently turn your input into poo poo

python is most likely to do something retarded, but its a toy language for idiots so w/e

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Python code:
>>> map(int, ['10', '10', '10', '10', '10'])
[10, 10, 10, 10, 10]

JewKiller 3000
Nov 28, 2006

by Lowtax
just lol if the library functions in your language aren't curried

MeruFM
Jul 27, 2010
programming languages define my being and self worth as a person

Bloody
Mar 3, 2013

trip report: c#'s works as expected
String[] test = { "10", "10", "10", "10", "10" };
var res = test.Select(e => int.Parse(e));
foreach (var e in res) Console.WriteLine(e + " " + e.GetType());
10 System.Int32
10 System.Int32
10 System.Int32
10 System.Int32
10 System.Int32

its called select tho which is a little odd

Luigi Thirty
Apr 30, 2006

Emergency confection port.

arrays, they're like databases you see

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Bloody posted:

var res = test.Select(e => int.Parse(e));
weaksauce, you had to adapt the function

zokie
Feb 13, 2006

Out of many, Sweden

Bloody posted:

trip report: c#'s works as expected
String[] test = { "10", "10", "10", "10", "10" };
var res = test.Select(e => int.Parse(e));
foreach (var e in res) Console.WriteLine(e + " " + e.GetType());
10 System.Int32
10 System.Int32
10 System.Int32
10 System.Int32
10 System.Int32

its called select tho which is a little odd

Fixed your code
code:
var test = new [] { "10", "10", "10", "10", "10" };
var res = test.Select(int.Parse);
foreach (var e in res) Console.WriteLine(e + " " + e.GetType());

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Gazpacho posted:

weaksauce, you had to adapt the function

Yeah, if that's okay then js es6 is okay and equivalent.

code:

numbers = strings.map((s) => parseInt(s));

I think wrangling over 100% language purity is a bit silly with a cobbled together language like JavaScript. It feels like there's two sides who disagree about agreeing.

One says yeah its poo poo but really we've moved on and we can get past it because we need to use it, and the other says the language is poo poo and that's unacceptable. Problem is the only place to go from there is existing languages that compile down well to js, let me list them here:

I'm a fan of Typescript these days because it addresses the key big picture problems, namely structure and maintaining contracts of behaviour, without getting hung up on syntax sugar like Coffee script. Even better is they aim to remain a superset, so any syntax sugar is ES6 based (like the example above)

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


Notorious b.s.d. posted:

javafx was originally a sort of flash-replacement library for use in applets and installers and things. It didn't build on top of, and wasn't really compatible with, awt/swing. as a result, i have never even seen a javafx app in the wild

something I did not notice until just now: java 8's javafx will let you embed (and interact with?) swing stuff in a javafx layout. maybe that will create an incentive for its use

java 8's javafx is pretty much intended as a replacement for swing at this point. it doesn't have it's own terrible language anymore, and you can create javafx layouts with pure java, css, or xml. It also has a webkit based browser element, and a bunch of other nice things that are good for desktop apps and not just RIA. oh it also has opengl support built in (i think), so no more need for lwjgl for basic 3d java apps.

Condiv fucked around with this message at 09:30 on Mar 19, 2014

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

MononcQc posted:

Basically JS has a non-obvious varargs implementation that is enabled for all functions and all calls no matter the arity, which is the same mechanism used to provide default values to arguments (via x == undefined comparisons in the implementation).

ok no sorry octopus guy, but you're wrong, javascript has an official varargs mechanism. it sucks, as in it's too low level to be useful, but it's there:

quote:

15.3.5.1 length
The value of the length property is an integer that indicates the "typical" number of arguments expected by the function. However, the language permits the function to be invoked with some other number of arguments. The behaviour of a function when invoked on a number of arguments other than the number specified by its length property depends on the function. This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

so for example:

JavaScript code:
function a(b, c, d, e) {
    alert(arguments.callee.length);
    alert(arguments.length);
}

a(1, 2, 3, 4); // alert("4"); alert("4");
a(1, 2, 3, 4, 5, 6); // alert("4"); alert("6");
javascript functions have arity, both declared and actual, and you can query both

that said, parseInt has two arguments, not one argument plus an optional argument. look at how it's defined:

quote:

15.1.2.2 parseInt (string , radix)

The parseInt function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading white space in string is ignored. If radix is undefined or 0, it is assumed to be 10 except when the number begins with the character pairs 0x or 0X, in which case a radix of 16 is assumed. If radix is 16, the number may also optionally begin with the character pairs 0x or 0X.

compare with a function with actual optional arguments:

quote:

15.4.4.16 Array.prototype.every ( callbackfn [ , thisArg ] )

[...]

The length property of the every method is 1.

e: that said, it isn't an error to pass more, or less arguments than the declared named arguments, meaning it's perfectly acceptable to ignore the arity of a function, so welp

javascript is pretty crappy I guess :shrug:

hackbunny fucked around with this message at 09:53 on Mar 19, 2014

MononcQc
May 29, 2007

Gazpacho posted:

oh did they go back and change those so all the built-in / core library functions are curried, must have missed that

Most of the time they just made sure map doesn't pass in second arguments to all the functions you're passing in, which was one of the thing I said should be fixed, and likely the simplest ones to make sure composability is preserved.

MononcQc
May 29, 2007

hackbunny posted:

ok no sorry octopus guy, but you're wrong, javascript has an official varargs mechanism. it sucks, as in it's too low level to be useful, but it's there:

so for example:

JavaScript code:
function a(b, c, d, e) {
    alert(arguments.callee.length);
    alert(arguments.length);
}

a(1, 2, 3, 4); // alert("4"); alert("4");
a(1, 2, 3, 4, 5, 6); // alert("4"); alert("6");

Now name one of these variables 'arguments' if you expect an array of things to be passed like this:

JavaScript code:
function a(b, c, d, arguments) {
    alert(arguments.callee.length);
    alert(arguments.length);
}

a(1, 2, 3, 4); // alert("4"); alert("4");
a(1, 2, 3, 4, 5, 6); // alert("4"); alert("6");
Woops: this errors out with TypeError: arguments.callee is undefined. And it makes sense, because we're shadowing a variable here. Of course JS made that lovely decision rather than doing a thing like using a function to get these values (like PHP does to name one) or using these values directly in the function head like Scheme:

code:
(define (f a b c d . args) ...)
Or Python:

Python code:
def f(a, b, c, *args):
    ....
Now Javascript is gaining something here in the new specs, given they're adding a similar syntax (finally!) using function a(...args) { ... }.

Of course, checking arity isn't super reliable because (function f(a,b,c, ...args) { return x; }).length returns 3 (...args => 0), and you also can't use the varargs syntax and the arguments mechanism within the same function because that's invalid.

hackbunny posted:

javascript functions have arity, both declared and actual, and you can query both

They use a lovely in-scope variable that isn't even a reserved word or anything. The javascript mechanism is as hidden as possible, and the arity is visible only to the called function by this mechanism, not the other one. See this scheme mechanism:

code:
> (define (f a b c d . args) (list a b c d args))
> (define (g a b c d) (list a b c d))
> (f 1 2 3 4 5 6)
'(1 2 3 4 (5 6))
> (g 1 2 3 4 5 6)
g: arity mismatch;
 the expected number of arguments does not match the given number
  expected: 4
  given: 6
  arguments...:
To get something somewhat equivalent in JS, you need to manually check for the arity by calling Function.length which will tell you how many arguments it expects. So of course you may call parseInt.length and get back the value 2, or call it with f and get the value 4, but visibly that's useless here because map doesn't give a poo poo about it, and it's ambiguous whether you can or can't pass in anything that makes sense.

So what's the reasonable option? I'm guessing it isn't to blindly put your optional arguments into everything and see what sticks.

My strongest argument is to change map to pass in a single argument, nothing in the second position. Then if you really want to avoid confusion, force the usage of a function of arity 1 in there. Error out when somone tries anything else.

If you really, really want indexes, add a 'mapi' function or something and stop confusing people. And be strict on the arities you're ready to deal with.

hackbunny posted:


that said, parseInt has two arguments, not one argument plus an optional argument. look at how it's defined:

compare with a function with actual optional arguments:

e: that said, it isn't an error to pass more, or less arguments than the declared named arguments, meaning it's perfectly acceptable to ignore the arity of a function, so welp

javascript is pretty crappy I guess :shrug:
They could do it better and have plenty of tools to do it. They just don't (presumably backwards compatibility turns could into can't). And yes, hence JS is crappy. Therefore maybe you should do your functional programming not in JS.

MononcQc fucked around with this message at 13:21 on Mar 19, 2014

MononcQc
May 29, 2007

notice how I'd been advocating JS borrows from PHP to have a saner model. That's how bad it is.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

MononcQc posted:

Most of the time they just made sure map doesn't pass in second arguments to all the functions you're passing in, which was one of the thing I said should be fixed, and likely the simplest ones to make sure composability is preserved.

i can confirm this is perl's behavior. you just map { whatever } @listofstuff, and it's like magic, where you go through the list/array one element at a time

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

MononcQc posted:

Woops: this errors out with TypeError: arguments.callee is undefined. And it makes sense, because we're shadowing a variable here.

haha I never realized you can lock yourself out of that feature

MononcQc posted:

Of course JS made that lovely decision rather than doing a thing like using a function to get these values (like PHP does to name one) or using these values directly in the function head like Scheme:

nah, not a function, in javascript they're possibly even easier to override than variables

MononcQc posted:

They use a lovely in-scope variable that isn't even a reserved word or anything. The javascript mechanism is as hidden as possible, and the arity is visible only to the called function by this mechanism, not the other one

no, you misunderstand. arguments.callee is a too-clever-by-half way to get a reference to the current function, and just that. the caller doesn't need to reach into an obscure property of a hidden pseudo-array, it can just use .length:

JavaScript code:
function a(b, c, d, e) {
    alert(arguments.callee.length); // alert("4")
}

alert(a.length); // alert("4")
a(1, 2, 3, 4, 5, 6);
in fact I think the earliest version of javascript didn't even have arguments.callee, and you had to use the function's name, or the name of a variable that contained the function (how'd you write recursive anonymous functions? you couldn't). that's why I mentioned that parseInt has an arity of 2: even if map checked the arity, or the language enforced it (forcing map to check it like you do in e.g. groovy, sorry if I don't use your fancypants flangs), you'd still get the stupid behavior

e: yeah map passing two arguments is incredibly counter-intuitive and I don't think any map-like function does it

hackbunny fucked around with this message at 14:27 on Mar 19, 2014

Shaggar
Apr 26, 2006

Luigi Thirty posted:

arrays, they're like databases you see

yeah their both set data.

power botton
Nov 2, 2011

praise linq

MononcQc
May 29, 2007

Languages that use map with an arity of 1:

- clojure, if passed only 1 col to iterate over (1 arg per list being iterated on)
- common lisp, same as clojure
- D
- Dart
- Erlang
- F# (also supports a 'mapi' function to get the index)
- Factor
- Groovy (through 'collect')
- Haskell
- OCaml
- Perl
- PHP (works like Clojure and CL, also has 'array_map' that works with 2 arguments for key/values)
- Prolog
- Python
- Ruby
- Scala
- Scheme (all variations)
- Smalltalk
- SML

Languages that use map with an arity of not 1:

- Javascript
- Coffeescript

Graet job JS.

MononcQc
May 29, 2007

hackbunny posted:

haha I never realized you can lock yourself out of that feature

nah, not a function, in javascript they're possibly even easier to override than variables


Yeah, that's a huge part of my rant. It could be a nice feature, but you don't always have the possibility to use it.

Good point of the function. In fact using a function might be worse in JS, because then you can't decide to do the scope exception thing (oh in this scope the variable 'arguments' overrides globals' sounds worse with functions)

hackbunny posted:

no, you misunderstand. arguments.callee is a too-clever-by-half way to get a reference to the current function, and just that. the caller doesn't need to reach into an obscure property of a hidden pseudo-array, it can just use .length:

JavaScript code:
function a(b, c, d, e) {
    alert(arguments.callee.length); // alert("4")
}

alert(a.length); // alert("4")
a(1, 2, 3, 4, 5, 6);

ugh. That's worse than I expected as a trick. I guess it could still work but bleh.

hackbunny posted:

in fact I think the earliest version of javascript didn't even have arguments.callee, and you had to use the function's name, or the name of a variable that contained the function (how'd you write recursive anonymous functions? you couldn't). that's why I mentioned that parseInt has an arity of 2: even if map checked the arity, or the language enforced it (forcing map to check it like you do in e.g. groovy, sorry if I don't use your fancypants flangs), you'd still get the stupid behavior

my conclusion: js is bad.

Shaggar
Apr 26, 2006

abuse linq for great success.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Shaggar posted:

yeah their both set data.

I wish sql using multisets is a v bad thing since then u cant use the full relational algebra properly

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Shaggar posted:

abuse linq for great success.

linq owns, too bad it can't fuse streams

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
you never fuse the streams

Shaggar
Apr 26, 2006
yeah. that would be bad

MononcQc
May 29, 2007

Welcome to functional programming, Shaggar!

Shaggar
Apr 26, 2006
lambdas are pointless and dumb. the only reason I use them in c# is cause they're part of linq. would have much rather had Properties in java than lambdas

Bloody
Mar 3, 2013

zokie posted:

Fixed your code
code:
var test = new [] { "10", "10", "10", "10", "10" };
var res = test.Select(int.Parse);
foreach (var e in res) Console.WriteLine(e + " " + e.GetType());

:tipshat:

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

MononcQc posted:

Languages that use map with an arity of 1:
:words:
Every js function that has a fixed arity of 1 is compatible with JS's map, parseInt is not such a function and there is nothing inherently wrong about that

double sulk
Jul 2, 2010

code:
["10", "10", "10", "10", "10"].map(&:to_i)

Shaggar
Apr 26, 2006
C# code:
new[] { "10", "10", "10", "10", "10" }.Select(int.Parse).ToList().ForEach(x=> Console.WriteLine(x+" "+x.GetType()));
:suicide:

HORATIO HORNBLOWER
Sep 21, 2002

no ambition,
no talent,
no chance
man if only they'd quit dicking around and release a stable version of tomcat 8

Shaggar
Apr 26, 2006
im still running tomcat 7 + java 6. probably never going to upgrade either since most of my stuff is moving to c#

Shaggar
Apr 26, 2006
altho hopefully the security audit we have to go thru later finds the old javas and forces us to upgrade.

Bloody
Mar 3, 2013

Shaggar posted:

C# code:
new[] { "10", "10", "10", "10", "10" }.Select(int.Parse).ToList().ForEach(x=> Console.WriteLine(x+" "+x.GetType()));
:suicide:

this is getting gross

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
can someone remind me what's wrong w/ clojure again? i'm picking it up again i think

Shaggar
Apr 26, 2006
its dumb as hell

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Shaggar posted:

its dumb as hell

bad shaggar clojure is great if u need a jvm scripting language and as a lisp it owns

don't macro though it gets hairy fast

Adbot
ADBOT LOVES YOU

Shaggar
Apr 26, 2006

Malcolm XML posted:

bad shaggar clojure is great if u need a jvm scripting language and as a lisp it owns

don't macro though it gets hairy fast

if you need a scripting language use groovy. no one needs a lisp

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply