Live data from Hacker News

G()('al')

github.com

1–10 of 49 posts

Re: G()('al')

#3
Do languages that don't use () as a function call still have to use the same syntax? Or is () just a stand-in for a function call?

Re: G()('al')

#4
post #3

Do languages that don't use () as a function call still have to use the same syntax? Or is () just a stand-in for a function call?

Languages that don't use () still have to use the same syntax. See the haskell solution.

Re: G()('al')

#5
This is a syntax error in perl, so impossible?

  > perl -e "g()()"
  syntax error at -e line 1, near ")("
  Execution of -e aborted due to compilation errors.

Re: G()('al')

#6
The table at the bottom is interesting. I'd love to read articles about why it's impossible in language X. E.g. I'm familiar with C/Python and can implement a solution, and am surprised that it'd be impossible in Ruby - I don't know Ruby, and would love to know why.

More generally, what properties must a programming language satisfy for this problem to be solvable in it?

My current intuition is that if a language does not denote function calls with () enclosing arguments, AND if a language does not support metaprogramming (eg. LISP macros), then the problem is not solvable in it. Still thinking about it.

Re: G()('al')

#7
post #6

The table at the bottom is interesting. I'd love to read articles about why it's impossible in language X. E.g. I'm familiar with C/Python and can implement a solution, and am surprised that it'd be impossible in Ruby - I don't know Ruby, and would love to know why. More generally, what properties must a programming language satisfy for this problem to be solvable in it? My current intuition is that if a language doe…

For the impossible bullets, they link to informal arguments as to why it's impossible. The ruby one has code - it's a syntax error.

Re: G()('al')

#8
The "complete" solutions for Python in the repo don't actually work because they don't reset the state. If you add a final line of:

  print g('al')
for solution1 or:

  print m('rton')
for solution2, you'll find they don't print gal/ mrton.

Here's what I came up with before looking at those solutions that seems to work:

  def g(arg=None):
      if arg == 'al':
          return 'gal'
      def inner(arg=None):
          if arg == 'al':
              return 'g' + (inner.counter * 'o') + 'al'
          inner.counter += 1
          return inner
      inner.counter = 1
      return inner

Re: G()('al')

#9
post #5

This is a syntax error in perl, so impossible? > perl -e "g()()" syntax error at -e line 1, near ")(" Execution of -e aborted due to compilation errors.

Can you submit a pull request saying as much in the same format as the Ruby one?

Re: G()('al')

#10

The "complete" solutions for Python in the repo don't actually work because they don't reset the state. If you add a final line of: print g('al') for solution1 or: print m('rton') for solution2, you'll find they don't print gal/ mrton. Here's what I came up with before looking at those solutions that seems to work: def g(arg=None): if arg == 'al': return 'gal' def inner(arg=None): if arg == 'al': return 'g' + (inner.…

Resetting the state isn't one of the rules ;)

I'd make a solution which resets the state linked by the table though, so please submit one!

Post reply on HN