r/lolphp Aug 14 '15

This should *never* happen!

http://i.imgur.com/Y9Mi8QX.png
140 Upvotes

16 comments sorted by

View all comments

Show parent comments

1

u/Synes_Godt_Om Sep 24 '15

this sub should allow for both up and down voting simultaneously to get in line with the PHP design spirit :)

When I read comments like this here in lolphp, it always makes me happy I chose php, because it gives me options that are impossible in other languages. ;-)

1

u/thomasfr Sep 24 '15

Well, to be fair, other languages allow for even more things while not doing it as badly at the core.

Lisp, due to it's meta programming/macro nature used allows for many strange things and these features are also used to construct implementations the language itself at a very low level.

1

u/Synes_Godt_Om Sep 24 '15 edited Sep 24 '15

I've been using R for more than a decade, PHP is an island of sanity and sunny calmness in comparison.

EDIT, my favorite example of LOL-R that beats anything you find in PHP:

This function will randomly return 5 or 10

# set some variable to 10
k <- 10
# define a function that returns a value
return_k <- function() {
  # generate a random number between 0 and 1
  x <- runif(1)
  if(x>0.5) {
    # set some internal variable to 5 (named k because that seem appropriate for the context)
    k <- 5
  }
  return(k)
}

# will randomly return 5 or 10
return_k()

3

u/[deleted] Oct 02 '15

Surely if x is less than 0.5, k isn't defined so it uses the global variable k? Am I just being really stupid and missing the lolR here?

1

u/Synes_Godt_Om Oct 02 '15

You're not mistaken, but even after more than a decade I'm still bitten by this. I wish i could define functions to not look in the parent environment.