Guess the language



  • With the downfall of the pre-processor in modern languages, it's rare to see a programmer attempt to utterly adapt the syntax and semantics of one language to another through blunt force. Today, I am proud to present an instance of this. First person to guess what language this is gets a gold star. Hint: this code is not whitespace-sensitive.

    check_path = (lambda filepath, hashes, p = sys.stdout.write:
    (lambda hash = hashlib.sha1 (file (filepath).read ()).hexdigest ():
    ((hash in hashes) and (p ('DUPLICATE FILE\n'
    ' %s\n'
    'of %s\n' % (filepath, hashes[hash])))
    or hashes.setdefault (hash, filepath)))())

    scan = (lambda dirpath, hashes = {}:
    map (lambda (root, dirs, files):
    map (lambda filename: check_path (os.path.join (root, filename), hashes), files), os.walk (dirpath)))

    ((len (sys.argv) > 1) and scan (sys.argv[1]))


  • @fourchan said:

    With the downfall of the pre-processor in modern languages, it's rare to see a programmer attempt to utterly adapt the syntax and semantics of one language to another through blunt force. Today, I am proud to present an instance of this. First person to guess what language this is gets a gold star. Hint: this code is not whitespace-sensitive.

    check_path = (lambda filepath, hashes, p = sys.stdout.write:
    (lambda hash = hashlib.sha1 (file (filepath).read ()).hexdigest ():
    ((hash in hashes) and (p ('DUPLICATE FILE\n'
    ' %s\n'
    'of %s\n' % (filepath, hashes[hash])))
    or hashes.setdefault (hash, filepath)))())

    scan = (lambda dirpath, hashes = {}:
    map (lambda (root, dirs, files):
    map (lambda filename: check_path (os.path.join (root, filename), hashes), files), os.walk (dirpath)))

    ((len (sys.argv) > 1) and scan (sys.argv[1]))

     

    I'm trying to figure out whether it's LISP recreated in some other language, or some other language recreated in LISP?  My guess is it's a C programmer moving to LISP for some reason that probably deserves its own WTF entry. 



  • sys.argv gave it away: that's supposed to be Python (I'd guess). Gimme the gold star already. 😉



  • @modelnine said:

    sys.argv gave it away: that's supposed to be Python (I'd guess). Gimme the gold star already. 😉

    That was my first throught too, but then he said it's "not whitespace sensitive".  Doesn't get me any closer though.



  • I'm going to take a stab in the dark and say it's Scheme.



  • The colons to denote the start of blocks betray Python.

    Also, I'm not aware of any lambda keyword in the common C-style languages. But that just means I didn't notice one in the reference. 🙂
     



  • Uneducated guess: Haskell



  • I think it's something from the lisp family pretending to be python. You can't distinguish between lisp relatives after they've been this badly mauled by macros, so there's no way to get any closer than that. (Or more simply: any of the lisps or schemes could accept this code)



  • @fourchan said:

    With the downfall of the pre-processor in modern languages, it's rare to see a programmer attempt to utterly adapt the syntax and semantics of one language to another through blunt force. Today, I am proud to present an instance of this. First person to guess what language this is gets a gold star. Hint: this code is not whitespace-sensitive.

    check_path = (lambda filepath, hashes, p = sys.stdout.write:
    (lambda hash = hashlib.sha1 (file (filepath).read ()).hexdigest ():
    ((hash in hashes) and (p ('DUPLICATE FILE\n'
    ' %s\n'
    'of %s\n' % (filepath, hashes[hash])))
    or hashes.setdefault (hash, filepath)))())

    scan = (lambda dirpath, hashes = {}:
    map (lambda (root, dirs, files):
    map (lambda filename: check_path (os.path.join (root, filename), hashes), files), os.walk (dirpath)))

    ((len (sys.argv) > 1) and scan (sys.argv[1]))

    Is it bash or another shell scripting language? Relying on a LOT of what are actually other programs?



  • @Lankiveil said:

    @modelnine said:

    sys.argv gave it away: that's supposed to be Python (I'd guess). Gimme the gold star already. 😉

    That was my first throught too, but then he said it's "not whitespace sensitive".  Doesn't get me any closer though.

     It's Python, and Python isn't whitespace-sensitive. (It is, however, indentation-sensitive (and that's a GOOD THING, in case you haven't figured it out yet)).
     



  • @SpComb said:

    @Lankiveil said:

    @modelnine said:

    sys.argv gave it away: that's supposed to be Python (I'd guess). Gimme the gold star already. 😉

    That was my first throught too, but then he said it's "not whitespace sensitive".  Doesn't get me any closer though.

     It's Python, and Python isn't whitespace-sensitive. (It is, however, indentation-sensitive (and that's a GOOD THING, in case you haven't figured it out yet)).
     

    What does Python use for indentation if it isn't whitespace?


  • @m0ffx said:

    Is it bash or another shell scripting language? Relying on a LOT of what are actually other programs?

    No, you can't define the open parenthesis in shell. 



  • Don't you guys know anything?  It's obviously someone who learned BASIC at an early age, moved up to PASCAL in high school and college, peed on LISP, then learned Java.  As for this code, it's written in COBOL, but it's obvious that the code will never compile.



  • @belgariontheking said:

    Don't you guys know anything?  It's obviously someone who learned BASIC at an early age, moved up to PASCAL in high school and college, peed on LISP, then learned Java.  As for this code, it's written in COBOL, but it's obvious that the code will never compile.
    Philosophy time: is it really COBOL if it doesn't compile?



  • @PJH said:

    What does Python use for indentation if it isn't whitespace?

    Pythons can use their sharp teeth to create indentations.

    Also, the Python programming language is whitespace sensitive only in certains circumstances: at the beginning of a line, or inside a string, or in the middle of a keyword or variable name, for example.

     

     
     



  • @dhromed said:

    Also, I'm not aware of any lambda keyword in the common C-style languages. But that just means I didn't notice one in the reference. 🙂 

     

    I just assumed there was a [b]#define lambda[/b] somewhere that wasn't included.



  • @PJH said:

    What does Python use for indentation if it isn't whitespace?

    It uses whitespace for indentation, but that doesn't make it whitespace-sensitive. An example of a whitespace-sensitive language could be MUMPS. Python doesn't care if you have a space before your colons or not, the only thing it checks is that top-level statements are consistently indented into blocks. It's also possible to split statements inside brackets onto multiple, indented lines, like the OP's code does with brackets and lambda.



  • @vt_mruhlin said:

    @dhromed said:

    Also, I'm not aware of any lambda keyword in the common C-style languages. But that just means I didn't notice one in the reference. 🙂 

     

    I just assumed there was a [b]#define lambda[/b] somewhere that wasn't included.

    Even if, wouldn't it have to be something like lambda(foo, bar, baz) instead of (lambda foo, bar, baz) ? C preprocessor macros can "override" identifiers, but I don't think they can override syntax structures... Or can they...?



  • @PSWorx said:

    Even if, wouldn't it have to be something like lambda(foo, bar, baz) instead of (lambda foo, bar, baz) ? C preprocessor macros can "override" identifiers, but I don't think they can override syntax structures... Or can they...?

    They can, but they cannot break token boundaries or change the syntax of a macro invocation itself, so you can't do this one with cpp. 



  • @asuffield said:

    @PSWorx said:

    Even if, wouldn't it have to be something like lambda(foo, bar, baz) instead of (lambda foo, bar, baz) ? C preprocessor macros can "override" identifiers, but I don't think they can override syntax structures... Or can they...?

    They can, but they cannot break token boundaries or change the syntax of a macro invocation itself, so you can't do this one with cpp. 

    That was what I meant. Of course you can insert all sorts of glibberish using a macro, but the invocation in not-yet-preprocessed code has to have a fixed syntax.



  • @ammoQ said:

    Uneducated guess: Haskell
    Nah. Not only is Haskell whitespace-sentitive in rather convoluted ways, it also has much uglier syntax. Example (randomly grabbed from a random file):

    [code]parseSeq :: (a -> b -> c) -> (String -> ParseRes a) -> (String -> ParseRes b) ->
                String -> ParseRes c
    parseSeq f parseA parseB s =
        if failed r1 then Error (errorStr r1)
        else if failed r2 then Error (errorStr r2) else Result (rest r2) nres
        where r1 = parseA s
              r2 = parseB (rest r1)
              nres = f (result r1) (result r2)
    [/code]

    I hope that the code above is not the horribly mangled mess the preview function shows me. This forum would be a hell of a lot easier to use if its particular BBCode dialect were explained somewhere on the help page... And if the preview function actually worked.

    Anyhow, you can be happy that I don't have any code involving I/O at hand. The concept of I/O is not compatible with Haskell's basic principles, so they had to violate them and introduce Monads, which are essentially data types that try to emulate procedural programming in a functional language. Yeah, they're as much a joy to use as you might be thinking now.



  • @Lankiveil said:

    @modelnine said:

    sys.argv gave it away: that's supposed to be Python (I'd guess). Gimme the gold star already. 😉

    That was my first throught too, but then he said it's "not whitespace sensitive".  Doesn't get me any closer though.

    Sorry if that line caused confusion, I meant it to be a hint towards Python. Normally you'd expect Python code to be sensitive to indentation and to fail if all the indents were removed, but this code doesn't exhibit that property.

     This is Python code.
     



  • Of course fixing the post above took too long and now I'm not allowed to anymore.

    Here's the code again, this time without tags because I still can't figure out what this forum uses for <pre> or <tt>.

     

    parseSeq :: (a -> b -> c) -> (String -> ParseRes a) -> (String -> ParseRes b) ->
                String -> ParseRes c
    parseSeq f parseA parseB s =
        if failed r1 then Error (errorStr r1)
        else if failed r2 then Error (errorStr r2) else Result (rest r2) nres
        where r1 = parseA s
              r2 = parseB (rest r1)
              nres = f (result r1) (result r2)



  • @j6cubic said:

    I still can't figure out what this forum uses for <pre> or <tt>.

    Interestingly enough it uses <pre>.

    I'm pretty PRE'd.
            Zoinks.
    

    Quote for sample



  • @j6cubic said:

    The concept of I/O is not compatible with Haskell's basic principles, so they had to violate them and introduce Monads, which are essentially data types that try to emulate procedural programming in a functional language.

    This sentence is wrong on every point in every imaginable way. It is quite impressive how stunningly wrong you have managed to be. I have not seen so many errors in such a small space in quite some time.

    Monads are any Kleisli triple, which consists of an underlying type, a constructor function, and an operator function that accepts [a monad of underlying type X] and [a function that accepts a value of type X and returns a monad of underlying type Y] and returns [a monad of type Y]. You can do pretty much anything with that - it really is as vague as it sounds. Any set of these three things is a monad. Saying "a monad" (in the context of Haskell) is not really any more descriptive than saying "a class" (in the context of Java or anything similar) - they don't mean the same thing, but they are both equally meaningless. It doesn't have anything to do with procedural programming in particular. It's not even very special. Any non-trivial program in any language contains countless numbers of them. Anything that you would recognise as a sensible operator has a monad around it somewhere.

    The IO monad and a couple of related ones are essentially the encoding of operational semantics in pure logic. They are not emulating anything. Computers are emulating monads - logic predates computers, and electronic computers were designed to implement these well-known theories as closely as was practical (and actually fall short, because they have limited memory - computers are a poor emulation of the underlying logic). There are several other monads which do completely different things.

    At no point do they violate any of the principles of Haskell. The whole point of the Church-Turing thesis is that everything is equivalent to any of the fundamental forms. Haskell picks the form which mathematicians normally use to do all their work (the many-sorted predicate logic), and implements an entire system in terms of it. There is no emulation, and no deviation from this concept. The IO monad is an implementation of IO that precisely matches the methods which mathematicians use to reason about IO behaviour, which is deliberate because it means they can use those same methods to reason about Haskell programs directly.

    You cannot have a computable concept that is incompatible with this. IO certainly is not. The only difference between IO with monads and IO in a language like Java is that in Java there is some handwaving about what IO means ("It's this bunch of library functions" "And what exactly do they do?" "Well, you know, they read and write and stuff <waves hands>"), while in Haskell a precise definition (in pure logic) of exactly what "IO" means has been supplied. Any other language that bothers to define this is using a monad to do it, even if they don't use that particular word.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.