News for hackers. Stuff that matters.
Re:Brainfuck in one line of Python by _delirium on Sunday December 04, 2011 @04:59PM (#3311995)
And for our next trick, Python in one line of Brainfuck...
Re:Brainfuck in one line of Python by vidarh on Sunday December 04, 2011 @05:07PM (#3312015)
I must admit I was disappointed - v2 of the original AmigaOS Brainfuck compiler is a 240 bytes binary, and the C interpreter is 1047 bytes of unobfuscated C source.

1400+ bytes of tightly packed Python just isn't in the same class.

Re:Brainfuck in one line of Python by Goladus on Sunday December 04, 2011 @05:37PM (#3312105)
The goal wasn't "tightly packed" the goal was "one line."

In Python that means, essentially, one expression. That's what makes it a stunt.

Re:Brainfuck in one line of Python by vidarh on Sunday December 04, 2011 @05:42PM (#3312120)
My point with mentioning "tightly packed" was that if you'd tried to make the C version small, you'd come out with something much tinier than the 1047 bytes I mentioned.

I see he's set himself a very different goal, which is fine but not that interesting to those of us that aren't Python programmers, I guess.

What disappointed me was clicking through from a headline that seemed to indicate it'd be a tiny implementation, when it's in fact rather bloated.

Re:Brainfuck in one line of Python by ricardobeat on Sunday December 04, 2011 @07:02PM (#3312329)
In this case "one line" doesn't mean much. You could have a 1mb file in one line. Nowadays a "line" is between 80-140 characters.
Re:Brainfuck in one line of Python by rplnt on Sunday December 04, 2011 @07:50PM (#3312430)
You are not entirely right. In python, one line means something as it is only one statement (as mentioned above). Author is also strict about not using eval -- with eval you could snuck multiple lines into one line (using \n in the evaluated string).
Re:Brainfuck in one line of Python by worldimperator on Monday December 05, 2011 @03:21AM (#3313701)
Last time when I used python I could separate statements with a semicolon and put as many as i want in a line. Did that change ? ;-)
Re:Brainfuck in one line of Python by lightcatcher on Monday December 05, 2011 @03:39AM (#3313741)
This did not change, but the author also didn't use semicolons. As stated many times above, this is a single Python expression.
Re:Brainfuck in one line of Python by rplnt on Monday December 05, 2011 @06:54AM (#3314239)
I'm not sure you can write function definitions, (nested) loops and other things that rely on indentation in single line using semicolons. At least I never managed to do that.
Re:Brainfuck in one line of Python by worldimperator on Tuesday December 06, 2011 @03:42AM (#3318563)
You can do it with lambdas, but it's going to be absurdly ugly: http://blog.sigfpe.com/2008/09/on-writing-python-one-liners....
Re:Brainfuck in one line of Python by cjfont on Sunday December 04, 2011 @07:52PM (#3312437)
I reckon that the challenge involved in reducing the problem to one line (as in one single Python statement) has little to do with how many characters long it is.
Re:Brainfuck in one line of Python by benatkin on Sunday December 04, 2011 @04:56PM (#3311986)
That isn't the normal way of measuring the length of code in code golfing contests. It's number of normal-sized lines, for some measurement of normal that is less than 1400 characters. Pretty neat, though; just a misleading title.
Re:Brainfuck in one line of Python by rcthompson on Sunday December 04, 2011 @05:17PM (#3312045)
Maybe "in one Python statement" would be more appropriate.
Re:Brainfuck in one line of Python by mahmud on Sunday December 04, 2011 @05:32PM (#3312086)
Every Lisp program can be rewritten to be just "one expression"

  `(progn ,@program)
What have we achieved here?
Re:Brainfuck in one line of Python by tjoff on Sunday December 04, 2011 @05:38PM (#3312108)
I think the first paragraph explained it quite well.

Whether or not the feat itself is impressive or not I don't really know but the reason for the quest was motivated.

Re:Brainfuck in one line of Python by mahmud on Sunday December 04, 2011 @06:04PM (#3312195)
My point was that "one-line" is a faulty criterion for measuring compactness if we allow for arbitrarily long lines: or "long cat is long" considered harmful.
Re:Brainfuck in one line of Python by nknight on Sunday December 04, 2011 @06:20PM (#3312232)
I'm guessing you don't deal with Python much. Python actively discourages this sort of thing, it's actually hard to create obfuscated code of the kind you see in most other languages.

That this was even possible surprised me somewhat, that he actually figured it out I find quite impressive.

Re:Brainfuck in one line of Python by mahmud on Sunday December 04, 2011 @06:41PM (#3312294)
Fair point, and the magnitude of this feat was not lost on me. I was just speaking in general, we need a better metric for one-linerness than s/\n//g.
Re:Brainfuck in one line of Python by DanielRibeiro on Sunday December 04, 2011 @05:10PM (#3312027)
you can't parse any non-regular language on any given computer

It is nice how the author completely ignored LALR parsers[1], peg parsers[2], and so on.

[1] http://en.wikipedia.org/wiki/LALR_parser

[2] http://en.wikipedia.org/wiki/Parsing_expression_grammar

Re:Brainfuck in one line of Python by thurn on Sunday December 04, 2011 @05:58PM (#3312175)
You can only imperfectly emulate anything more than a regular language in a finite reality (since a pushdown automaton has an infinite stack). A PC is just a big DFA.
Re:Brainfuck in one line of Python by pak on Sunday December 04, 2011 @05:03PM (#3312006)
Any program can be called a "one liner" if you just strip newlines and don't limit the line length.
Re:Brainfuck in one line of Python by steve-howard on Sunday December 04, 2011 @05:12PM (#3312031)
It's generally accepted that a semicolon (in most languages) means two lines no matter how the spacing goes. In Python, it's particularly tricky to have a complex program evaluate to one statement because of limitations like no assignments in expressions. It's true, though, that this is basically the same as writing Lisp in Python.
Re:Brainfuck in one line of Python by gliptic on Sunday December 04, 2011 @05:07PM (#3312016)
Not in Python.
Re:Brainfuck in one line of Python by Dylan16807 on Sunday December 04, 2011 @08:29PM (#3312559)
So how long would it be if you used a better python interpreter with tail calls?
Re:Brainfuck in one line of Python by shubsengupta on Sunday December 04, 2011 @10:09PM (#3312792)
I'm still appalled at the fact that the term 'brainfuck' is used in a Princeton website.
Re:Brainfuck in one line of Python by pak on Sunday December 04, 2011 @11:35PM (#3313095)
Lots of people can put things on URLs under princeton.edu, or the domains of most universities. In this case, note the ~username in the URL--this is the personal page of a graduate student. Usually universities do not censor pages of their students. I do agree, though, that it would be surprising to see this on a departmental page or anything else owned by a PR team.
Re:Brainfuck in one line of Python by Dylan16807 on Sunday December 04, 2011 @10:47PM (#3312909)
Why? It is the name of the language.