Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?
Games Entertainment

Code That Pushed the Language Envelope? 87

Lil Fritz asks: "Following on from the cool Flash Adventure game last week, this geezer Neil Pearce has written a full client side JavaScript CPU chess player (which drew with me, but then I'm papz at Chess). Now this sort of thing always amazes me. Doing stuff for which it was never intended. Do we have other warped (ie 'they wrote it in what?!?') uses of languages and tools?"
This discussion has been archived. No new comments can be posted.

Code That Pushed the Language Envelope?

Comments Filter:
  • by chrestomanci ( 558400 ) <[gro.icnamotserhc] [ta] [divad]> on Tuesday October 29, 2002 @08:36AM (#4554807)

    When I first saw it, I was amazed that it worked, but I would say it pushed the limits

    Code example and discussion in the Jargon File [tuxedo.org]

    For a more detailed explation see here [lysator.liu.se].

    Can't post the code, due to Lameness filter.

    • Yeah, that is pretty cute.

      But just as he points out in the introduction this is the type of work a compiler should do. And a compiler optimized for a given architecture should be able to maximize the loop unrolling benefit. (W.r.t. caches and such.)
  • Chess? Pah! (Score:4, Interesting)

    by GregWebb ( 26123 ) on Tuesday October 29, 2002 @08:36AM (#4554808)
    If we think about it, Chess is only requiring a lot of processing on the client side. It's a waste of CPU power but nothing more.

    I remember being rather more impressed when a friend wrote a Tetris clone in JavaScript. Interactive, real-time processing in JavaScript? Well done.
  • Not too good (Score:5, Insightful)

    by Scarblac ( 122480 ) <slashdot@gerlich.nl> on Tuesday October 29, 2002 @08:43AM (#4554834) Homepage

    The site says it looks 2 moves deep, but I don't see how it can play like this then:

    1.e4 Nc6 2.d4 Nf6 3.e5 Ne4 4.Bd3 Nxd4?? 5.Bxe4 Nxc2?? 6.Qxc2

    Leaving two knights hanging to immediate capture threats, that doesn't suggest any lookahead to me.

    But of course, it's neat that it works. People have made utilities for playing through chess games before, like PalView [enpassant.dk] (a simple demo here [enpassant.dk]).

    Adapting that to take user input and a very simple lookahead is work, but not stunning in my opinion. Unless there's some reason why this is very hard in JS, I don't really do that language...

  • by dasunt ( 249686 )

    It falls to a scholar's mate [chesscorner.com].

    Wants to reload the icons every move too on my 56k connection for some odd reason.

  • by Anonymous Coward on Tuesday October 29, 2002 @09:01AM (#4554917)
    Some people use the C programming language to actually attempt to write qulaity programs.

    I have to ask (slashdot) what drugs are these people taking?

  • BaSiX (Score:5, Interesting)

    by ebbe11 ( 121118 ) on Tuesday October 29, 2002 @09:13AM (#4554969)
    I think BaSiX [tug.org] ought to qualify - a BASIC interpreter written in TeX, no less.
  • Chess is nifty (Score:4, Interesting)

    by DeadSea ( 69598 ) on Tuesday October 29, 2002 @09:25AM (#4555028) Homepage Journal
    Along the same vein, a couple weeks ago I coded Tic-Tac-Toe in JavaScript [ostermiller.org] complete with an alpha-beta search such that the when it is in expert mode, you cannot beat your web browser. Solving the whole game on my computer takes about 5 seconds, so I added an opening book to compute the first move. With that response time is pretty much instantaneous even in expert mode.
    • Slight semantic fix -- I wrote tic-tac-toe last semester so I thought I'd point this out. The search is "min-max" - the method of speeding the search is "alpha-beta pruning" (or "cutoff", whatever). Here's a brief explanation [temple.edu].
    • Uh, tic-tac-toe? Thats a pretty simple game. The mainframe in the movie War Games was able to figure it out. And that was some pretty old technology. (Of course, it was also able to figure out that global thermo-nuclear war is also always a draw if both players know how to play well.) Doesn't seem like it'd be that difficult to do in JavaScript. Hell, I've figured out the algorithm with pencil and paper.
  • by abdulla ( 523920 ) on Tuesday October 29, 2002 @09:27AM (#4555038)
    JavaScript's syntax and language facilities are pretty similar to C, it's not that far fetched that he was able to do this, and considering that a lot of Mozilla is controlled via JavaScript, it doesn't suprise me that this is possible.
  • by Dukebytes ( 525932 ) <dukebytes@yaho[ ]om ['o.c' in gap]> on Tuesday October 29, 2002 @09:29AM (#4555046) Homepage
    This sort of stuff is neat - but it also makes you want to go eh?? WTF??

    I know, I know - its just a little game to see if they could do it. But geesh - I see this stuff in the OFFICE all the time. Some of the devs do stuff in java, some in VB, some in perl etc... What I hate to see is when someone is so wrapped up in VB, or java, or any language that they WILL NOT write anything in any other code.

    A few of the VB guys, they push it to the extreme, and are zelots about it. Sometimes I actually think they believe they are making the world a better place because they write in VB....

    This is cool, but man, it happens all the time and not always for the right reasons.


    • Yeah, I know those guys who wont switch up languages. Sometimes I think that they've forgotten all the other languages and refuse to write in them because they don't want you to know they forgot how. I've found that Perl nazis are usually the exception. They remember how to write in other languages. They just have some strange belief that Perl is the best language for everything, when it isn't.

      Use the language best suited to the task at hand. Don't use a handsaw to put a nail in the wall. It's fun when somebody does, but it's really silly and impractical. It's ok if your writing something for fun to use whatever language you like. But at work you should choose wisely.
    • I friend of mine is a VB zealot. He could do some pretty cool stuff in VB, my fav was his Zelda clone he wrote entirely in VB.
  • by Samus ( 1382 ) on Tuesday October 29, 2002 @09:36AM (#4555078) Journal
    I seem to remember a web server writen in postscript being mentioned on /. some years back. It seems like a pretty big stretch to me having a language designed for displaying text and graphics serve out web pages.
  • by oren ( 78897 ) on Tuesday October 29, 2002 @09:41AM (#4555106)
    Once upon a time there was an argument whether XSLT was turing-complete (this was when the spec was being worked out), so I posted an XSLT "stylesheet" that places N queens on an NxN chessboard so that none threatens the other. You can see the post here: http://www.biglist.com/lists/xsl-list/archives/199 906/msg00289.html [biglist.com] and the stylesheet here: http://www.biglist.com/lists/xsl-list/archives/199 906/bin00003.bin [biglist.com]. That's a pretty twisted piece of code if I do say so myself :-) Strangely enough it has been actually "used" - to benchmark XSLT processors etc. (e.g., here: http://www.machi.pe.kr/xml/document/xslt/xslt_benc hmark.htm [machi.pe.kr].
  • I beat it with ease.

    That is really cool. Excellent work in javascript. I guess now I have to stop laughing at my boss who thinks its actually useful to use javascript. Bummer.

  • by JonBob ( 556956 ) on Tuesday October 29, 2002 @10:31AM (#4555390)
    Lots of "barrier pushing" code can be found in obfuscation contests. Check out the Obfuscated C contest [ioccc.org] or the Obfuscated Perl contest [sysadminmag.com]. For similar feats on the web, check out The 5k [the5k.org] (which recently featured a lightweight chess entry).
  • by Bingo Foo ( 179380 ) on Tuesday October 29, 2002 @10:34AM (#4555414)
    C++ templates were known to be Turing-complete when they were introduced into the language, but NOBODY back then would have suspected that something like Andrei Alexandrescu's Modern C++ Design was possible.

    Every day, my appreciation for templates grows deeper. I've even thought that there ought to be another language built from the ground up around templates, one that shows more parallelism in the syntax of compile-time templates and "regular" code.

    • So you want a true Object Oriented language instead of the the bolt OO concepts onto a procedural language aproach of C++? Try Eiffel, it is OO to the core and includes what should be required of any language a CompE student would love, design by contract. That is that you explicitly state the entry conditions into a routine and guarentee the results, if either is not met an error is thrown and error handling code is automatically invoked (though to get more then an error message thrown you need to extend the error handling classes but no biggie). This really changes the way you program as you include correctness from the beginning of the design rather than as an afterthought in the debugging stage.
      • So you want a true Object Oriented language instead of the the bolt OO concepts onto a procedural language aproach of C++?

        No, that's not what I wanted at all. I love the mishmash that is C++. I was talking about templates, which are often referred to as a "generic programming" concept, not OO. I am not a language purist, so C++'s handling of OO is fine by me; I even use (gasp!) public data members sometimes.

        I am just really intrigued by the concept of templates as a compile-time bound and evaluated language and how that relates to the layer of the language that is compile-time bound but run-time evaluated, and the layer of the language that is run-time bound and run-time evaluated.

        These can be thought of as (non-exclusive) members of a hierarchy of dialects of the language, covering many points on the speed-flexibility envelope. I would be very interested in a language designed to look similar at all levels of the hierarchy but able to bind and evaluate as much as possible early, and yet retain the flexibility of creating classes on the fly from a data stream.

        • I only know the rudiments of Lisp, so I can't speak authoritatively, but I believe that all of what you're describing is there. I think that Lisp's macros and syntax forms are useful for doing all the things that templates can and then some. Unlike C++, they are expressed in the same syntax as the core language, so extensions to the language (like templates or control structures or other mini languages) are better integrated with the language.

          It's interesting that you mention dialects, since Lisp is one of the few languages that is generally recognized as having them. Its flexibility lends itself to specialization, such as implementing new dialects of itself or completely new mini languages. For instance, Scheme was originally implemented in an already existing Lisp.

          As far as serialization of objects and manipulation of data and code, few languages can boast the power of Lisp's S-expressions. Their power is in their simplicity and allows all Lisp code and data structures to be expressed in the same simple syntax. Also, the entire language is available all the time, meaning that you don't have to make a design decision about whether to use a compiled or an interpreted language.

          As far as performance, there are Common Lisp and Scheme implementations that outperform many other modern high level languages and even get close to C++ in some cases (http://www.bagley.org/~doug/shootout/).

          Now I am ashamed for not using Lisp more after giving it such a glowing image. Mainly, it's just momentum. I continue to use the tools I'm comfortable with (mainly Python, Java and some C). I think this is the main reason people continue to use relatively low level languages like C and C++ for application programming. I do intend to try new tools, though. I don't want to stagnate.

          Of course the fact that I haven't used Lisp much yet means I haven't experienced its downsides. However, I am confident that Lisp's lack of popularity does not reflect its power.
          • Well, to my knowledge lisp is not compiled to machine code, and I'm unfamiliar with the results you gave about perfomance speed. Trying to collaborate on a project where others aren't willing to go to lisp is problematic too, as it would be with any "boutique" language.

            Perl, while commonly usable by scientific programmers (my area), isn't really compiled either in the traditional sense, but parts of a perl program may be more efficient if they are "compile time" evaluatable. Perl, however, has the feature where you can write a program that produces a text string that is capable of being interpreted and executed as code from within the program that wrote the string (if that make sense). It puts the simple run-time binding of C++ to shame. Flexible as hell, but you pay for that flexibility in speed.

            The neat thing about templates is that they let you, the designer, separate features by binding/evaluation time. In a dream world, one could ignore such concerns in one's code and the optimizer would be perfect at factoring out and efficiently compiling all early binding and evaluation, but AFAIK we're not there yet.

            • There most definitely are Lisp implementations (both Common Lisp and Scheme) that compile to machine code. Two examples are CMUCL [cons.org] and Bigloo [inria.fr]. It seems clear from some benchmarks [bagley.org] that they easily outperform the likes of Perl, Python, and Java. Note that the previous link won't work if you just click on it, but if you copy it, then put it in the location bar of a new window, it will. It seems the author of the page doesn't much like Slashdot.

              You're absolutely right about the power of being able to generate source at runtime and evaluate (run) it. That's one of the things I like about Python as well. In fact, I don't think any language can be considered high-level if it doesn't have that. Guess where this concept originated? In the early implementation (around 1960) of Lisp, a function called "eval" was invented to be the definition of the Lisp interpreter. The details are in "The implementation of LISP" [stanford.edu].

              The nice thing about the compiled lisps is that you also have the compiler available at runtime, which means that you can generate source code dynamically, then compile it. You are no longer bound by the traditional code/compile/run cycle.

              I don't know of compilers/interpreters that can make such high level decisions about when to bind and evaluate, but I believe that Lisp allows a lot more flexibility in that area than C-like languages. Also, it looks like Self [sun.com] might offer something in that area. Another class of languages I have yet to explore, but may be far superior on these issues is that of pure functional languages, especially the lazily evaluated ones. I plan to learn one of the ML's eventually, like OCaml.

              Unfortunately, as you pointed out, the best tools can't always be used because of external requirements like programmer or user familiarity. In fact, that's the main reason I haven't really gotten into using Lisp yet: I'm comfortable with languages I already know. But, I'm determined to try new things, especially when there's evidence that there are better tools available.
  • Wolfenstein (Score:5, Interesting)

    by 'The '.$L3mm1ng ( 584224 ) on Tuesday October 29, 2002 @10:51AM (#4555582)
    Searching this page didn't show it up, so here's the link:

    Wolfenstein in 5kb of JavaScript [innofinity.com]
  • by JimR ( 101182 )

    M-x hanoi

    • This one is not such a big deal, actually.

      Remember, Emacs is a front-end text editor over a LISP interpreter. Personally, I'd vote more for EMACS itself written in an AI language than solving a recursive logic problem in a text editor shell over an AI engine.
  • We had a guy speak to our users group [sluug.org] about their Open Source product called TIBET [technicalpursuit.com] that takes JavaScript to its limits. They've implemented language constructs that the JavaScript designers were surprised by. Things like closures, a type system, multiple inheritence, and meta-classes. The whole system (about 1MB) is downloaded to the client system, and everything runs on the client system without having to pull down anything but data from the server. Very impressive.
  • Another example of: "Not how did they do it, but why?"

    http://www-106.ibm.com/developerworks/xml/librar y/ x-xslrecur/

    The only application I can think of is to build a drop down with Fibonacci numbers in it. Of course, recursion has efficiency on the order of 2^N, which means 100 fibonacci numbers would take 10^30 operations to generate.

    How to make your webpages load slower: use recursion in XSL.

  • That Javascript chess game would certainly be a lot cooler if it didn't refresh the whole damn page each time you even click on the board.

    Not to say that it's not impressive but it gets a little annoying having those graphics reload each time. I don't think it would've been that hard to make it work without reloads. Ah well.
  • Granted I am dating myself here, but way back in 1981 I helped tweak a screen reader for the Apple II so that it would correctly read either the original 40x25 screen (which was interlaced, which made reading it from assembly a rather weird bit of code), or for one of the original 80x25 mod cards. The text was then sent out as a stream through the RS-232 port to an Echo 2 Speech synthesizer which had a phoneme chip and speaker, etc. Granted, compared to today's tech the Echo II is a piece of junk -- but at the time it had the advantages of being both cheap and somewhat easy to program in terms of phoneme translations. We also altered the reader code and text to speech sections of the code (in Applesoft Basic BTW) to implement a reader that would correctly pronounce text displayed on the screen that was written in Spanish or Romanized Japanese -- the only languages besides English which I spoke well enough to code for.) As far as I know it was the first "personal computer" based reader for the blind in the state where it was developed.

    Not coincidentally, one on my pet projects that I want to spend time on is to make (or find if it already exists) a generic plug-in module in Mozilla that can do the same thing with no external hardware outside a vanilla PC sound card (or on board chip). Links anyone?

  • by 1110110001 ( 569602 ) <<slashdot-0904> <at> <nedt.at>> on Tuesday October 29, 2002 @12:39PM (#4556446)
    The other day I played around with PHP's socket-extension. After some reading I thought about a normal server-service I could try. A webserver came to my mind. So I made up a HTTP-server/daemon in PHP. PHP should be an extension to a webserver not a webserver itself, that's why it might fit into this topic.

    I played around with it and tested it with apache benchmark. As I'm able to handle multiple request it got pretty fast and stable - even faster then pure apache (no wonder - it has more features).

    The advantage of this webserver is, you don't need any php-optimizer as everything in your application gets includes in the webserver and loaded with it. If anyone wants the code just tell me ...

  • Ok, so it makes legal moves. Not that hard to code. I played a single game against it:

    1. e2 e4 b8 c6
    2. g1 f3 d7 d5
    3. e4 d5 d8 d5
    4. b1 c3 d5 f3
    5. d1 f3 g8 f6
    6. f1 c4 e7 e5
    7. c3 d5 f6 d5
    8. c4 d5 f8 d6
    9. f3 f7 e8 d8
    10. d2 d4 c6 d4
    11. c1 g5 d6 e7
    12. f7 e7#

    If it is "Looking two moves into the future," it isn't looking very carefully. Still, kind of a fun project...at least I have a computer opponent that I can frequently beat. :)

  • Postscript Raytracer (Score:2, Interesting)

    by parroyo ( 546279 )
    here [uni-heidelberg.de]
  • How about a program that compiles and runs in seven different languages?
    http://www.nyx.net/~gthompso/poly/polyglot.txt [nyx.net]

    Or a program that prints its own source code?
    http://www.nyx.net/~gthompso/quine.htm [nyx.net]

    Or just a whole collection of weird programming-related stuff?
    http://www.catseye.mb.ca/ [catseye.mb.ca]

    (OK, so I'm way too late to the party and nobody's going to read this, but hey :)

  • The strangest one I ever saw was the application written in object-oriented K shell! It was a complex run-script for a Verilog simulation environment. To protect the guilty, I won't identify where I saw it. (NO, I wasn't the guilty party, even though I am the worlds worst programmer!) The person who showed it to me was the current maintainer, who had inherrited it from a former collegue, since departed from the company. He wasn't too thrilled with being responsible for its maintenence, but admitted that it worked "remarkably well". The program has since been retired.

    I forget the details, but the basic idea was something like...

    Object instances were represented by directories. Methods were represented by shell scripts named for the methods. Derived objects were represented by subdirectories. Overlaid methods would be scripts in the subdirecrory, and inherited methods (from the parent directory) would be used if the script wasn't present. Instance variables were data files in the corresponding object directory. I think class and global variables were stored in environment variables, but I'm a little hazy on that. The whole scheme relied heavily on scripts that walk directory trees, programs that exec each other, inherited environment variables, and scripts inheriting settings from other scripts by sourcing them.

    I'm also hazy on how fullly it really implemented the concept of classes independent of class instances (i.e. objects).

    As for the big question: Why??? I was never able to find an answer.
  • At a company where I worked in the early '90s, I used to write batch files that really pushed the limits. I tried to avoid using third-party utilities such as 4DOS so they'd run about anywhere but I sure used the standard DOS utilities. Some of my batch files used pipes and redirects to script EDLIN to search and replace data in text files. Some used ASCII control codes to send color data to the ANSI.SYS driver. They called me ".bat man". I still have a Batman coffee mug at work. It was a joke then, but nobody gets it anymore. :) These days, I'd just use Perl.
  • I recently wrote an BrainFuck [muppetlabs.com] interpreter in INTERCAL [tuxedo.org]. I keep it here [2y.net] and it's an evil evil beast. :D

    Several years back I also wrote a relatively full-featured BBS, complete with message boards, file areas and dropfile support for door games, in QBASIC, as well as a DataPac network scanner in same. :/
  • Pushing the limits (Score:5, Interesting)

    by bobv-pillars-net ( 97943 ) <bobvin@pillars.net> on Tuesday October 29, 2002 @05:31PM (#4559108) Homepage Journal

    I know a guy who wrote a program to calculate Pi to an arbitrary number of digits in

    You ready for this?


    He wrote the entire progeram as a series of .BAT files that recursively called each other.

    No external programs, no tricks. Nothing but the native capabilities of COMMAND.COM. Local variables were stored in the environment, and globals were stored in files.

    It ran really slow.

  • I was thinking of doing an Amiga emulator in Flash.

    Shouldnt be that hard.
  • I like that chess game - pretty neat. I once started writing a Ultima-style game in Javascript, complete with level loading off the hosting server. However, I stopped writing it when I realized I would need to set up a CGI back end for implementing save game features and such.

    I remember seeing a version of "California Racin'" or such done completely in Javascript - took forever to load the graphics (there was a lot of graphics to load for all the sprite 3D scaling effects). Also, who could forget Frag Island, a Quake-like game written in Java?

    I once pushed VB hard and made a perspective-correct texture mapped 3D spinning cube - no DirectX used, either.

    Then there was the time in highschool I wrote a mandelbrot display engine in Applesoft Basic, and displayed it via an assembler hi-color display hack (allowed you to get 16 colors at a good resolution if you had an 80x24 display card). Then I repeated it using PICK Basic, and a Wyse 370 set to emulate a Tectronix (sp?) graphics plotter terminal (eeeek!!!).

    I think my favorite, though, has to be a game I remember coded by some Japanese guy in QBasic - it was in the ABC Archive - anyhow, this game was a 640x480 monochrome side-scrolling shooter with an UNBELIEVABLE amount of sprites on-screen, complete with end-level bosses - all in QBasic.

    Then there is the code a friend of mine gave me that he never released that used QuickBasic 4.5, some custom assembler routines, etc - to make a side-scrolling platformer robo-anime style game, with full sound-blaster effects - but it isn't as relevant because the graphics scrolling/sprite routines were coded in x86 Assembler - of course, he wrote this back in 1992 or so...

  • Someone once wrote javascript support for lynx, can't
    find the URL for it, but googling does find several references to it.

    Ok, so its not as amazing as a chess engine, or Tetris playing javascript code, but still, its pretty wierd.

    The other thing that stretches the imagination as to why is when C coders start implementing Templates in C, rather than using C++. I'm a C coder, but even I know when to use C++.
  • Pac-Man (Score:1, Interesting)

    by Anonymous Coward
    I used to have Pac-Man written entirely within MS Excel.

    Should be able to grab it from

    http://www.winsite.com/info/pc/win3/excel/pac-ma n. zip

    May not have pushed the limit, but it was pretty cool nonetheless. Boss key? We don't need no shtinkin boss key!

The Macintosh is Xerox technology at its best.