Wikipedia:Reference desk/Archives/Computing/2010 January 27

From Wikipedia, the free encyclopedia
Computing desk
< January 26 << Dec | January | Feb >> January 28 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


January 27[edit]

Range decoding and random numbers[edit]

Can a range encoding's decoding function, applied to a hardware RNG's output stream, be used to generate random numbers in an arbitrary discrete probability distribution (e.g. an implementation of percentile-roll tables such as these in an online game server) with a minimum of wasted entropy? NeonMerlin 03:16, 27 January 2010 (UTC)[reply]

Could you further explain what you wrote before your 2nd comma? If I understand correctly, you're suggesting writing a decompression algorithm that intentionally has no checksum or other error correction methods, and feed it random data. The output of such an algorithm will inevitably be less random, so I'm going to say "no", assuming randomness is valuable to you. Even though I don't know much about arithmetic data compression or range encoding. Comet Tuttle (talk) 05:26, 27 January 2010 (UTC)[reply]
What I mean is converting the RNG's output, which chooses between 1 and 0 with equal probability, into an output that chooses between any number of symbols with whatever probability distribution we specify, without throwing away true random bits, and without the degradation of randomness that we might get if we used the output to seed a conventional PRNG. NeonMerlin 15:10, 27 January 2010 (UTC)[reply]
I'm not sure why you're reaching for a decompression algorithm when you could instead just grab n bits from the RNG, and use arithmetic to apply this to your desired range and probability distribution. Comet Tuttle (talk) 18:49, 27 January 2010 (UTC)[reply]
The answer is yes. But you have to either use arbitrary-precision integers for your range boundaries (in which case your memory and time consumption may increase without bound) or else throw away some entropy. -- BenRG (talk) 08:44, 29 January 2010 (UTC)[reply]

Got something I need ID'd[edit]

'Kay, I have here something I have no idea what it is (except for maybe perhaps a Memorex audio device of some sort). It's black, has a clip on the back, is roughly hemispherical with a port on the left/top end for a headphone jack, play/pause, seek, and stop buttons, and a long cord coming off the right/bottom end that terminates in a jack. I've no idea what it is; could someone ID it based on the description? —Jeremy (v^_^v Boribori!) 09:31, 27 January 2010 (UTC)[reply]

Probably a toaster. See our article on Toaster for more info. Good luck. :) Shadowjams (talk) 09:57, 27 January 2010 (UTC)[reply]

Ugh. as much fun as it is to leave my above comment, you really should post a picture. And I have to wonder how you got some device you have no idea what it is.... perhaps some context would make us feel a bit more at ease. I know you're not new here, but come on... every walkman made in the last 30 years qualifies for what you described if you turn it upsidedown. Shadowjams (talk) 10:01, 27 January 2010 (UTC)[reply]

This isn't a CD player; it's no bigger than my ring and index fingers and just as wide. My father found it in an apartment he was turning and brought it home. As for a picture, I don't have a digital camera I can use. —Jeremy (v^_^v Boribori!) 10:03, 27 January 2010 (UTC)[reply]
Possibly a headset cord with an integral remote control for a CD Walkman or MP3 player. 220.101.28.25 (talk) 10:46, 27 January 2010 (UTC)[reply]

open new rss items into new tabs[edit]

I asked this before but I'd like to try again, in case someone who didn't see the first question knows something that could help me

I desperately need a program or a scrip or anything that can monitor an rss feed every 60 seconds and open every new item into a new firefox tab. —Preceding unsigned comment added by 82.43.91.83 (talk) 11:36, 27 January 2010 (UTC)[reply]

Looking for Parrot Basic 1.0 and Parrot Basic 2.0 - something to do with Perl.[edit]

I'd like to get copies of both of these. Parrot Basic 1.0 is a freeware Windows clone of GWBasic, the only language I'm fluent in. (I actually prefer the very simple lightweight editing). The 2.0 version is a clone of Qbasic. Although there are many mentions of these on Google, the links are all to the home site of Geeksalad dot org which has closed. An email to the author bounced back. The Waybackwhen Machine shows the old pages, but the download links there do not work, nor do the more recent .zip file links. I understand that "Parrot" may be something to do with Perl. Does any super search sleuth know where I could find them please? A pity to let someone's work go to waste. Thanks 92.27.165.25 (talk) 12:42, 27 January 2010 (UTC)[reply]

The only connection with Perl is that their compilers were written in Perl, as far as I can tell. Thus their announcements were distributed to Perl listservs. Find them does not look promising to me. (You could probably learn basic Perl in the time it takes you to track these down.) --Mr.98 (talk) 14:53, 27 January 2010 (UTC)[reply]
parrot is the (somewhat well known) bigger project you mention. Look under the "Languages" tab on that site, there are installation instructions too. --194.197.235.240 (talk) 15:28, 27 January 2010 (UTC)[reply]

Parrot is I think what Parrot Basic is written in. Did not find them at that site. 89.242.92.249 (talk) 12:27, 28 January 2010 (UTC)[reply]

They are there... have a look at http://www.parrot.org/download and go to the "Packages" section and go to the Win32 version at sourceforge: http://sourceforge.net/projects/parrotwin32/ .They actually have release from 1-20-2010...so it seems active. A short bit on parrot basic 2.0 http://cpansearch.perl.org/src/SFINK/parrot-0.0.11/languages/BASIC/compiler/BASIC_README . Hope you find this of some use.Smallman12q (talk) 01:10, 2 February 2010 (UTC)[reply]

bugging devices for night clubs[edit]

Are there bugging devices that can be used in night clubs? Is it somehow possible to listen to the talk of people despite the music playing? --Lowlife001 (talk) 13:47, 27 January 2010 (UTC)[reply]

Probably not. It's impossible to properly separate even instrumental music from voices algorithmically (the only reason mash-ups are possible is that the new instrumental track drowns the old one out). You'd have to either know what song was playing and where you could download it from in real time, or else you'd have to intercept the sound signal to the speakers (which may be possible if they're wireless). I doubt such a device would sell enough units to pay for the firmware development. NeonMerlin 15:21, 27 January 2010 (UTC)[reply]
The intelligence agencies of the world probably have pretty sophisticated bugs that can be tuned to specific situations. Their capabilities are no doubt classified. I suspect there is nothing on a consumer market that can do such a thing. --Mr.98 (talk) 15:45, 27 January 2010 (UTC)[reply]
I would think that you can use some narrow band filters tuned to the voice frequencies to filter out a lot of irrelevant noise. --Stephan Schulz (talk) 15:51, 27 January 2010 (UTC)[reply]
If you have considerable resources (money, access to the room, ability to conceal pickups in walls, signal processing capability) you could probably construct a large phased array of microphones and isolate a speaker through beamforming. In fact, it appears that such an array has been prototyped at MIT. Be sure to check out the YouTube videos. -- Coneslayer (talk) 16:04, 27 January 2010 (UTC)[reply]
The problem is sorting the background noise out from the speech you want to record. With a single microphone, as noted above, that's very difficult. But if you have time to prepare, and some tech, it's quite achievable. Lets imagine you're a police department and you want to bug a bigtime traffiker making a deal in the club. You know he always sits in a given VIP booth. If you install several directional mics in the ceiling, pointing at the general areas where people's heads will be, then you'll record the raw sound of what people say. If you make sure the walls behind and around the booth are covered with sound-absorbing material (which they often are anyway, as are places like cinemas) to minimise the backscatter going into the directional mics. But the mics aren't perfect, and there still will be backscatter, so you'd have several omnidirectional mics in the same area. To maximise the speech you subtract the omni signal from the directional signal, and hopefully remove a lot of the background noise and music. To optimise this you can map the local acoustics by emitting a tone and measuring the response of the room - that's exactly how high-end conference phones, and they use the data to calculate the reflections off each wall, which they can use to subtract the speaker's sound, delayed, from what its mics receive (and thus minimise feedback). Then you can go to signal processing to clean things up further. -- Finlay McWalterTalk 03:26, 28 January 2010 (UTC)[reply]
Perhaps you could do something like you do to remove vocals from music to make kareoke tracks. In that case, you know that the voice is generally in the center of the stereo image and the instruments are off to the sides. If you digitally subtract the left stereo track from the right (or vice-versa) the vocals simply vanish! So if you have more than one microphone, it ought to be possible to eliminate (or at least drastically reduce) the other sounds by arranging that the microphones are placed such that they are all about the same distance from the people you want to monitor - but at dramatically different distances from the sound system. SteveBaker (talk) 06:35, 29 January 2010 (UTC)[reply]

Do laptops or notebooks nowdays use SATA internally?[edit]

Resolved


This arises from another question an OP asked before Use optical drive on one PC to install software on another PC 220.101.28.25 (talk) 16:28, 27 January 2010 (UTC)[reply]

Yes. The great majority of laptop hard drives for sale at Newegg are SATA. -- Coneslayer (talk) 16:34, 27 January 2010 (UTC)[reply]
Thanks for quick answer. I had a look and can see the specs. And, notebooks generally use 2.5" drives too? 220.101.28.25 (talk) 16:52, 27 January 2010 (UTC)[reply]
The kind you linked to doesn't. My impression has always been that notebook and laptop are essentially synonymous, with manufacturers preferring notebook so that users don't burn their genitals. Did you mean to ask about netbooks? I suspect some or all use 1.8" disks, but I'm not positive, and can't investigate further right now. Anyone? -- Coneslayer (talk) 17:00, 27 January 2010 (UTC)[reply]
Thanks again, I've fixed the link. :-) Must admit I don't know the brand/model of computer the OP wishes to connect to a Desktop PC in order to install software on the 'Notebook'. Must remember to check all links I use in any text! 220.101.28.25 (talk) 17:26, 27 January 2010 (UTC)[reply]
Yes notebooks use 2.5" drives generally (in the future maybe the smaller ones) - but currently 2.5.Shortfatlad (talk) 18:13, 27 January 2010 (UTC)[reply]

Excellent, Thank You! 220.101.28.25 (talk) 20:40, 27 January 2010 (UTC)[reply]

error report[edit]

Anyone want to hazard a guess at what caused this error report on XP "access violation at address 00553c88 in module 'RTHDCPL.EXE' Read of address BBE4C4E8" - the module is legitimate - an audio driver thing - curiously the computer made a funny beep. (also the error report was displayed at the back (low z) not up front?) - impossible to determine what happened or not?87.102.67.84 (talk) 17:33, 27 January 2010 (UTC)[reply]

There's no real way of knowing unless you happen to be running a version of the driver that was built with debug symbols and if you were running a programmer tool like Watson. In other words, if you were the programmer you might be able to figure out what happened. Googling RTHDCPL.EXE does indeed say it's part of the Realtek audio control panel, and you've indicated this is legitimate, so the traditional advice is to get the latest update from their website; maybe it fixes some bugs; and if not you can file a bug report with Realtek with, preferably, a repeatable set of steps that causes this error every time; and then you have a one in 10,000 chance that someone will take your bug report seriously and fix the bug internally and send it through QA and come out with a fix in the next version of the driver they publish in six months. Ah, how I hate computers. Comet Tuttle (talk) 17:47, 27 January 2010 (UTC)[reply]
Yes. in a 1GB machine BBxxxxxx is outside memory?
Memory is virtualized for each process; if the process hasn't allocated that address, then it counts as an access violation. The amount of memory on the machine doesn't matter. —ShadowRanger (talk|stalk) 18:38, 27 January 2010 (UTC)[reply]
In several years this error never happened before, could this be a sign of some sort of attack such as a buffer overflow exploit - I fail to see how - but I know nothing..87.102.67.84 (talk) 18:17, 27 January 2010 (UTC)[reply]
Unlikely. Usually it's a bug in the code (some edge condition that isn't hit often), or a minor memory error (even good memory flips a bit every once in a while, and if it's less than perfect, or the power fluctuated, or any of a million other things went wrong, you might get a corrupted address. If it is a virus, it didn't get in via your sound driver; they don't maintain network connections. It's possible a virus affected the functionality of other executables, but unless you have other reasons to suspect a virus, it's probably just an unimportant blip. —ShadowRanger (talk|stalk) 18:38, 27 January 2010 (UTC)[reply]
Thanks.
Resolved
87.102.67.84 (talk) 22:10, 27 January 2010 (UTC)[reply]

hellos[edit]

Whats the difference between 3g and 3g+ in laymans terms. I understand both are 3rd generation speeds. I think that 3g is for gsm and 3g+ is for cdma. —Preceding unsigned comment added by 212.49.88.34 (talk) 21:13, 27 January 2010 (UTC)[reply]

This page says it's 3G with High-Speed Downlink Packet Access. As the box at the bottom of 3G shows, terms like "3G+" and "3.75G" are marketing terms that vaguely roughly sorta relate to actual collections of technology. -- Finlay McWalterTalk 22:01, 27 January 2010 (UTC)[reply]

related question[edit]

As long as we're on the subject ... is the "G-level" more of a hardware thing, or a software thing? By this, I think I mean:

  • It's a hardware feature if it consists primarily of infrastructure, wiring, etc, upgrades, which in turn allow faster communication speed and/or data bandwith. If this is the case, an older handset could run on the newer network, could likely see better performance for existing applications (but obviously wouldn't have and be able to use the newer applications).
  • It's primarily a software thing, if the difference between nG and n+1G (or n+0.5G) is mostly new protocols and support for additional applications, yes? If this is the case, I don't know what to expect for interoperability.

So, which is it? How far off base am I :-) DaHorsesMouth (talk) 00:27, 28 January 2010 (UTC)[reply]

is there a single enterprise user of windows 3.1? (in a vm of course)[edit]

Is there a single enterprise anywhere in the world using windows 3.1 in a VM, to accomplish anything? As for why, I imagine MAYBE they lost the source, but the program is very proprietary and impossible to reproduce and for some reason won't run under a win32 subsystem... Anything like that 'in the wild', anywhere in any enterprise anywhere in the world? 82.113.121.204 (talk) 21:33, 27 January 2010 (UTC)[reply]

Until about three years ago I worked for a company that made banking (epos) computer equipment. We were contractually obligated to keep a working development environment for anything we'd sold that our customers still had deployed. The toolchain for one of these wouldn't run on anything better than windows 3.1 (toolchains for embedded systems are often scary junk, and this was more so than most). For a long time I had a physical win3.1 machine which I would fire up whenever they asked for changes (which in practice was about once a year); when it started making odd noises I switched it to a VM. There wasn't enough ongoing revenue to justify figuring out a modern toolchain for the thing, so we lived with the antique. It was still there when I left; as far as I know they still use it when they need to. Hmm, it may strictly have been W4W3.11 but that's just 3.1 with knobs on. I don't doubt that, for much this reason, there aren't quite a number of these type arrangements going around. -- Finlay McWalterTalk 21:47, 27 January 2010 (UTC)[reply]
Right; as the original poster is saying, if you have spent US$1 billion on a software system that's sufficiently complex, you don't muck with it by upgrading or improving any part of the system. It works! Don't touch it! One proof of an old system from a while back was when the radar system at Los Angeles International Airport completely went down, because of a bug in the version of Windows used by some component of their radar system (Windows 3.1? Windows 95?) that caused Windows to dependably crash every 34 days, or thereabouts, when some timer overflowed. This was a known bug in the OS. The airport knew about this bug, and their workaround was, rather than spend a ton of money fixing the bug and then re-obtaining whatever FAA re-certification was necessary, to hire a guy to physically drive over and reboot the machine every month in order to reset the timer to 0. The trouble occurred when he screwed up and didn't follow his checklist. Personally, for what it's worth, I totally endorse this saving of money by using a low tech solution that's proven 100% effective (when you follow your damn checklists every day) rather than using a super-expensive higher-tech solution. The Russians and the purported space pencil, and all that. (Links to stories about the LAX story are appreciated — I'm having trouble googling anything about this, probably because I've got one major fact wrong.) Comet Tuttle (talk) 22:08, 27 January 2010 (UTC)[reply]
The space pen[cil] story. --Tardis (talk) 22:24, 27 January 2010 (UTC)[reply]

I don't know about enterprise, but my friend used to (and I think still does) run a website on win 3.1 for shits and giggles. I think he had the entire thing, including the OS on one floppy disk! —Preceding unsigned comment added by 82.43.91.83 (talk) 23:00, 27 January 2010 (UTC)[reply]

About 15 years ago I worked for a while in the UK on a machine called the "Venturer" - a small fairground-type ride [1] involving a machine the size of a small bus being bounced around on hydraulic jacks with up to 14 people inside watching thrill ride movies that synced up to the motion of the cab. The company brought me in to rewrite their software. It turned out that this was because the existing software was written in WBASIC for an 8088 PC running DOS - and all of the super-critical hydraulic valve timing was done with "FOR I = 1 TO 537 DO X=X+1" 'timing loops' (Eeeekkk!). Because the original programmer had long ago left the company - and running the software on anything other than an 8088 PC shortened the time the loop took to execute and caused literal hydraulic overpressure explosions - they were kinda desperate! They were selling these machines at a rate of a couple a month - but the number they could sell was limited by their ability to find and refurbish ancient used 8088 computers (it was more than 10 years after the last time you could buy new ones). Finally they were resorting to going to "car boot sales" (think "yard sale") to find machines with 8088 CPU's! My job was to rewrite the software in C++ with proper interval timers and interrupts and all that good stuff so it could be run on a modern PC with any clock rate. Scarey stuff - there was about ten thousand lines of undocumented BASIC with single letter variables and NO comments at all. There were a dozen or so different movies - each with different motion - and each movie had a slightly different BASIC program with all of the motion information packed into "DATA" statements at the end of the code. In the end, redoing it was very satisfying work - it bothered me a lot to know that there were machines like this out in the world with the safety of a dozen riders being handled by such appalling software on ancient hardware that had been bought by people scouring yard sales for the oldest possible used PC's! SteveBaker (talk) 06:25, 29 January 2010 (UTC)[reply]

Toolchain[edit]

Resolved

In respect to the immediately preceding question, could the term 'Toolchain' be explained please? --220.101.28.25 (talk) 21:58, 27 January 2010 (UTC)[reply]

Preprocessor, compiler, assembler, linker, locator, Rom image generator, eprom burner software. -- Finlay McWalterTalk 22:02, 27 January 2010 (UTC)[reply]
That is, all the software you need to turn a BCPL or C or ASM or whatever program into a binary image loaded on a memory chip. -- Finlay McWalterTalk 22:03, 27 January 2010 (UTC)[reply]
Tool chain means any series of pieces of software used on some data before the data is touched by your main application. In video games, an artist might use two or three Autodesk software applications to model and texture and animate a monster, and then some proprietary scripts are run in order to massage the data, and then another proprietary application is run to do some animation compression, and then another little application flips around all the data because the byte order needs to be the other way, and then finally the data is ready to be placed on disc with the game application. All those little programs along the way are the "tool chain". Comet Tuttle (talk) 22:17, 27 January 2010 (UTC)[reply]

Thanks very much. I have never heard that terminology. I'm into IT but I'm not a programmer. I consider the question Resolved. But if anyone has any added comment, go for it. 220.101.28.25 (talk) 22:37, 27 January 2010 (UTC)[reply]

I'll bite then. I'd like to add that debuggers are usually also seen as (i.e. sold as) part of the chain. Secondly, some people use the synonym "tool set". Finally, I think that in ASIC (i.e. chip) design people use Design flow, although perhaps that is more about the process than about the tools. 83.81.42.44 (talk) 19:33, 30 January 2010 (UTC)[reply]

Apple Time Capsule[edit]

I am trying to set up an Apple Time Capsule to work with my MacBook Pro but am so far having no luck. Could someone help me out? I've been told to "connect the time capsule to your mac with an ethernet cable and then run airport utility". So, I connected the TC to the internet via one ethernet cable, the MacBook to the TC via another and then ran AirPort Utility but no luck. It detects and AirPort device, just not the one that belongs to me. Does anyone have any suggestions? Thanks 131.111.247.136 (talk) 22:13, 27 January 2010 (UTC)[reply]

I have little experience with Time Capsules, but I've always found that the Macworld and Macrumors forums helpful and fairly speedy when I've had trouble with Apple equipment. Brammers (talk) 15:03, 1 February 2010 (UTC)[reply]

When you buy software on the internet.....[edit]

....how is it delivered to customers? As far as I'm aware all the professional sites direct you to a url that seems to be automatically generated by the server or something... I would like to sell my own downloadable products but I can't find a secure way to deliver the goods, if I just linked to them on the thank you for ordering page couldn't anybody just go to that page and download the product even if they hadn't bought it? 92.27.148.18 (talk) 23:43, 27 January 2010 (UTC)[reply]

If your software is small enough, why not just email it to your customers? —Preceding unsigned comment added by 82.43.91.83 (talk) 00:00, 28 January 2010 (UTC)[reply]

It's too large to be emailed unfortunately otherwise I would. 92.27.148.18 (talk) 00:04, 28 January 2010 (UTC)[reply]

In the absense of a proper answer (I can't think of the wikipedia page for this) here are a few options
  • Give the customer a user name and password - obviously if they share their password anyone can download the stuff - but you can monitor or limit downloads
  • Link the download (or even usage) to a specific computer or computers - or require them to 'log in' before they use the software - these methods are all collectively called Digital rights management or DRM.
Quite a lot of sites use the first method, and rely on trust.. or only allow a single download. Did you want methods of acchieving the second way - or would a login/password be enough?87.102.67.84 (talk) 00:25, 28 January 2010 (UTC)[reply]
Why not create a password-protected self-extracting zip file that your customers can download from your website? You can then e-mail the password on payment. If your customers are likely to post the password on the internet, then you could change the password daily and ask prospective customers their date of download. If you need higher security, then you will need to build into your software something along the lines of a unique installation code for each customer which is checked against your database, or a routine for identifying the machine on which it is running and checking this each time the software is run, or any similar restrictive routine. How paranoid are you about your customers cheating on you? Dbfirs 00:19, 28 January 2010 (UTC)[reply]

I'd really like to have a secure page for the download to take place after purchase I don't mind paying for this little bit of extra security but I wouldn't even know where to start in regards to a secure page that has its URL automatically generated. 92.27.148.18 (talk) 00:29, 28 January 2010 (UTC)[reply]

I searched "sell your own software" and found a site called payloadz.com, among several others. I am in no way recommending this site, but I'm sure at least one of those in the search results could be useful. --LarryMac | Talk 01:23, 28 January 2010 (UTC)[reply]
"Secure" in the web sense means the connection is encrypted. You don't need that—you're not worried about someone intercepting the download or data. With PHP, it would be rather trivial to make a script that generated a random URL (or a download URL with a random password) that was keyed to the transaction, would keep that functional for maybe a day or so, and would lock it to only work with the IP address that paid for it in the first place. I can't see any reason to go more overboard than that, since the real trouble with piracy will not be people sharing download addresses, but just re-uploading the file elsewhere. You need enough just to discourage opportunism, but you can't do more than that without finding a better way to secure the software itself (e.g. DRM of some sort). It is not a problem worth investing too much time/effort into because the re-uploading issue will take precedence almost immediately, in terms of difficulty for someone else to conquer, if that makes sense. You just don't want the download URL to be the weakest link in the security chain—making it the strongest link doesn't make much sense when there are far weaker ones. --Mr.98 (talk) 01:28, 28 January 2010 (UTC)[reply]
If you're looking to set up your own server, you need some ecommerce software that can handle "digital content". Like SurfShopPro or this project with the most generic name ever.(I have never used either of those products, I'm not recommending them, just offering them as examples.) However, if you don't want to set that up yourself, there are services that will do this work for you. The first one that came up on a google search was All Charge, but I know nothing about them so I'm not recommending them either. APL (talk) 01:58, 28 January 2010 (UTC)[reply]

Thanks for your help everybody. 78.146.182.215 (talk) 13:22, 28 January 2010 (UTC)[reply]

One last thought: the danger of any complicated system is that the people who just paid money for it won't be able to download it. (For example, keying the download to their IP address, as I recommended above, will work most of the time, unless the downloader is on AOL, in which case it won't.) You want your security to be just enough to deter casual piracy, but not enough to endanger irritating customers. (As the whole DRM controversy has pointed out.) It's a tricky balance, but just keep in mind that "security" is not the only consideration. --Mr.98 (talk) 13:52, 28 January 2010 (UTC)[reply]

javascript - name of behaviour type[edit]

function A() {
  if (flag==0) {
    var x=10;}
  else {
    x=x+1;}
  document.writeln(x);
  }
 \\main prog
 var x=5;
 var flag=0;
 A();
 flag=1;
 A();

I assume getting "NaN" on the second pass of the subroutine with flag=1 is defined behavoiur - however what I expected was one of two other things:

  1. when flag!=0 the local variable x is not created in the function so the function uses the global variable x - thus outputs 6 (5+1)
  2. or when flag!=0 the variable x is not defined to be 10, but the program store the previous local x and uses that - giving 11 as an output (I didn't expect this - but mention it for completeness)

Not actually asking for an explantion of why or how - but to ask - are there names for the types of behaviours described? - specifically 1. Also are there programming languages that give behavoiur 1 or 2 (for equivalent code) ? - (specifically narrowed to those with first class functions). Thanks.Shortfatlad (talk) 23:50, 27 January 2010 (UTC)[reply]

I don't know Javascript enough to give you a specific answer, but Doug Crockford talks at length about the weird behaviours both of javascript's == and != operator, particularly in respect to the many kinds of bottom value, and the behaviour wrt accessing non-existing variables. It's in this excellent Google Talk he gives. He also talks about a lint-like program (JSlint, I think) that he maintains, which yells at you for doing all kinds of reasonable but nevertheless wrong things in javascript. I heartily recommend the talk. -- Finlay McWalterTalk 03:32, 28 January 2010 (UTC)[reply]
Actually I saw the talk 3 days - ago - which led me to experiment.. and thus here.. (I forgot about jslint though -I'll try that) - yes I recommend the talk too. :)
Shortfatlad (talk) 14:35, 28 January 2010 (UTC)[reply]
I know you said you didn't want an explanation of "why", but here's one anyway... Non-global variables in JavaScript always have function scope, so all the references in A() are to a local variable, because you have "var x" at least once. (For that reason the global x is not accessible within A()). When you call A() with flag==1 you get an uninitialised local x wih a value of undefined, and adding 1 to that gives NaN. AndrewWTaylor (talk) 10:50, 28 January 2010 (UTC)[reply]
Yes - function scope - as http://www.jslint.com/lint.html says in section "Scope": "In many languages, a block introduces a scope. Variables introduced in a block are not visible outside of the block. In JavaScript, blocks do not introduce a scope. There is only function-scope."
Thanks (both). Got the right search terms now - looks like I was wanting "block expressions" - which seemed to be a proposal for Javascript2.0 , not sure - anyone know if 'block scoped variables' (possibly using 'let' ala lisp/scheme) has survived into the latest proposals?Shortfatlad (talk) 14:35, 28 January 2010 (UTC)[reply]