Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Raneman posted:

Was doing well for a while in my tutorials, until I hit another snag. I proofread it and compared it with the script it told me to type, and I didn't find anything I missed.
code:
from sys import argv

script, first, second, third = argv

print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
Traceback (most recent call last):
File "C:/Python27/ex13.py", line 3, in <module>
script, first, second, third = argv
ValueError: need more than 1 value to unpack

If this was working as intended, It would prompt me for one of my earlier scripts and then print the data in a format that looks similar to this:
The script is called: ex/ex13.py
Your first variable is: cheese
Your second variable is: apples
Your third variable is: bread

If you're unpacking to four variables, you need to be doing it with a four-variable list. Pass three arguments (the first is always the name of the program no matter what.)

Adbot
ADBOT LOVES YOU

Grey_Area
Dec 21, 2006
Grey Area
I'm reading "Learn You a Haskell for Great Good!" as an introduction to functional programming, but can't get one of the example programs to compile. The OP links to a Haskell thread, but it appears to be long gone, so I hope this is an appropriate place for this question.

I've reproduced the code below. When I try and compile using WinGHCi I get the following error message:

"[1 of 1] Compiling Main ( todo.hs, interpreted )

todo.hs:26:1:
The last statement in a 'do' construct must be an expression
"

Why could I be getting this error message? Have I screwed up my formatting somehow, or is the compiler doing something odd?


code:
1. import System.IO
2. import System.Environment
3. import System.Directory
4. import Data.List
5.
6. -- program to create to do lists. Can view, add and delete tasks
7. -- use command line prompt: todo <add|view|delete> <filename> <"task"|null|index of task>
8.
9. dispatch :: [(String,[String] -> IO ())]
10.dispatch =	[("add",add)
11.			,("view",view)
12.			,("remove",remove)
13.			]
14.
15.main = do	
16.	(command:args) <- getArgs
17.	let (Just action) = lookup command dispatch
18.	action args
19.
20.add :: [String] -> IO ()
21.add [fileName,todoItem] = appendFile fileName (todoItem ++ "\n")
22.
23.view :: [String] -> IO ()
24.view [fileName] = do
25.	contents <- readFile fileName
26.	let todoTasks = lines contents
27.		numberedTasks = zipWith(\n line -> show n ++ " - " ++ line)[0..] todoTasks
28.	putStr $ unlines numberedTasks
29.
30.remove :: [String] -> IO ()
31.remove [fileName,numberString] = do 
32.	handle <- openFile fileName ReadMode
33.	(tempName,tempHandle) <- openTempFile "." "temp"
34.	contents <- hGetContents handle
35.	let number = read numberString
36.		todoTasks = lines contents
37.		newTodoItems = delete (todoTasks !! number) todoTasks
38.	hPutStr tempHandle $ unlines newTodoItems
39.	hClose handle 
40.	hClose tempHandle
41.	removeFile fileName
42.	renameFile tempName fileName

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Grey_Area posted:

I'm reading "Learn You a Haskell for Great Good!" as an introduction to functional programming, but can't get one of the example programs to compile. The OP links to a Haskell thread, but it appears to be long gone, so I hope this is an appropriate place for this question.

Wherever you have
code:
do
  ...
  let foo = ...
            bar = ...
  ...
you should instead have
code:
do
  ...
  let foo = ...
      bar = ...
  ...

Grey_Area
Dec 21, 2006
Grey Area
Argh, sorry. I added the line numbers to the post so that I could reference line 26, but doing so misaligned the columns. In the original file, the two lines are aligned correctly. Lines 36 and 37 are also lined up correctly in the original.

If I put braces around the second two "do" blocks then I get a "parse error on input let" at line 26, while if I put braces around the "do" in main, I get a "parse error on input let" at line 17. I must be doing something retarded, but can't for the life of me work out what.

Grey_Area fucked around with this message at 09:34 on Dec 28, 2010

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Grey_Area posted:

Argh, sorry. I added the line numbers to the post so that I could reference line 26, but doing so misaligned the columns. In the original file, the two lines are aligned correctly. Lines 36 and 37 are also lined up correctly in the original.

If I put braces around the second two "do" blocks then I get a "parse error on input let" at line 26, while if I put braces around the "do" in main, I get a "parse error on input let" at line 17. I must be doing something retarded, but can't for the life of me work out what.

Are you using tabs? If you have your tabstops set to something other than 8 spaces in your editor, then your lines may not be aligned as far as the Haskell compiler is concerned.

Edit:

Anyway, if you really don't want to fix your broken indenting for some reason, you can change to:

code:
let { foo = ... ;
        bar = ... }
With the explicit braces-and-semicolons, you can have whatever crazy indenting you want on the let constructions.

ShoulderDaemon fucked around with this message at 09:43 on Dec 28, 2010

Grey_Area
Dec 21, 2006
Grey Area
Oh, I wasn't being clear. The indentation isn't broken in the code. I just messed it up when I copied it into my post.

I copy and pasted the code off the tutorial on the website I mentioned and that compiles fine. Which was encouraging as it suggested I'd typed something incorrectly. However, notepad++ tells me that the files match. So now I have two matching files in the same folder, one of which compiles and one of which fails to compile.

Fake edit: Ok, I moved the non-compiling file to a different folder, created a new file in the original folder and just directly copied the text from the non-compiling file into it, then saved the new file with the same name. This now compiles. I guess that solves the problem, but I still don't know what the gently caress. The new file has the same name, location and contents as the old file, but it compiles while the old one didn't.

shrughes
Oct 11, 2008

(call/cc call/cc)

Grey_Area posted:

I guess that solves the problem, but I still don't know what the gently caress. The new file has the same name, location and contents as the old file, but it compiles while the old one didn't.

As ShoulderDaemon pointed out, you are using tabs. If you use tabs, Haskell's tab stops are 8 characters, not 4 like your editor's. You should configure your editor to use spaces, not tabs. There should be no tab characters in Haskell code.

Grey_Area
Dec 21, 2006
Grey Area
Ok, thanks. The editor is set to "haskell" tabs, but I'll uncheck that and replace with spaces.

Rampager
Sep 15, 2007

:roboluv:allow me to buy
you a drink, miss
:roboluv:
I'm going to ask a possibly really stupid question but my curiousity demands answers. I realise that this might not be the best place for it.

How does programming in another (real) language (ex German, Arabic, Japanese) work? I can understand strings and the like but if you put in say a hiragana あ as a variable name [ int あ = 5; ] would the compiler allow it? Are there specific additions to compilers made to handle this case, or is anyone who programs forced to use the English alphabet?

As a follow on, wouldn't being from a non-english speaking country immediately put you at a disadvantage? E.g. looking at standard library functions such as push() and pop() or malloc() and free() you'd pretty much need a English->Your Language dictionary by your side the whole time?

Don't hurt me, this is legitmate curiousity :(

MrMoo
Sep 14, 2000

Rampager posted:

How does programming in another (real) language (ex German, Arabic, Japanese) work? I can understand strings and the like but if you put in say a hiragana あ as a variable name [ int あ = 5; ] would the compiler allow it? Are there specific additions to compilers made to handle this case, or is anyone who programs forced to use the English alphabet?

You can almost start to do this now, but the predominant set of tools, i.e. Visual Studio is unbelievably poo poo at i18n support. Generally it's Latin character variables with locale encoded comments.

Don't forget would be useful for doing any moderate to advanced level of math, moving from written formulae to ANSI code is awful.

MrMoo fucked around with this message at 07:46 on Dec 29, 2010

pkmnfrk
Dec 24, 2010

Chester Hjorvarth
Victorious this day
3-7-2011
Edit: I am stupid.

Vanadium
Jan 8, 2005

Rampager posted:

I'm going to ask a possibly really stupid question but my curiousity demands answers. I realise that this might not be the best place for it.

How does programming in another (real) language (ex German, Arabic, Japanese) work? I can understand strings and the like but if you put in say a hiragana あ as a variable name [ int あ = 5; ] would the compiler allow it? Are there specific additions to compilers made to handle this case, or is anyone who programs forced to use the English alphabet?

As a follow on, wouldn't being from a non-english speaking country immediately put you at a disadvantage? E.g. looking at standard library functions such as push() and pop() or malloc() and free() you'd pretty much need a English->Your Language dictionary by your side the whole time?

Don't hurt me, this is legitmate curiousity :(

I guess a bunch of programming languages explicitly allow unicode symbols, but, as a German, I get unreasonably annoyed when I have to read code with German comments in it, let alone German identifiers. Also my dictionary did not have "malloc" in it anyway so I did not feel disadvantaged there at all.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
Learning english just comes with the territory. Almost all useful support is in english, the language itself is english and most code is written with english speakers in mind.

csammis
Aug 26, 2003

Mental Institution
I remember being absolutely floored when, as a fine young American, I found some TI-ASM code with French comments. Other countries have programmers :2bong:

mobby_6kl
Aug 9, 2009

by Fluffdaddy

Vanadium posted:

I guess a bunch of programming languages explicitly allow unicode symbols, but, as a German, I get unreasonably annoyed when I have to read code with German comments in it, let alone German identifiers. Also my dictionary did not have "malloc" in it anyway so I did not feel disadvantaged there at all.

A friend of mine's professor required all variables and comments to be written in our local language which required a lot of dicking around on my friend's Linux + Java setup to get working properly, not to mention the overall :doh: of it all.

I'm not really asking for a solution as I can write it myself, but it seems like there's a good chance this has been asked already or somebody has experience with this. I need to automate some web app on our intranet which are heavy on javascript and use complex authentication so I can't just POST into the forms or something. I need to click a bunch of links, buttons, and fill out a form, repeatedly.

It seems like there are Perl modules to automate IE as well as libraries that could be used from C# or VBA code, but if anyone has done this previously, some suggestions would be much appreciated.

Rampager
Sep 15, 2007

:roboluv:allow me to buy
you a drink, miss
:roboluv:
Thanks for the answers! I didn't really mean malloc() specifically by I don't know, functions like strcpy() make sense to me but to someone who doesn't speak a lick of english it'd be somewhat confusing, and I'm sure there's a lot more examples that I'm having trouble remembering. Although I guess one could just read the source code and figure it out pretty quickly.

So, basically, it's possible. Cool :D

Zhentar
Sep 28, 2003

Brilliant Master Genius

Rampager posted:

Although I guess one could just read the source code and figure it out pretty quickly.

Or, you know, the documentation (assuming that's been translated, of course). Aside from that, English is taught so widely (especially in your examples of Germany and Japan) that pretty much everyone speaks at least enough to understand things like language keywords.

If you listen to people discussing technical stuff in a foreign language, you'll notice that they use english for most of the technical terms, even if it's something they could easily translate to their native language.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I will be making a transition over into web stuff with C# soon and wanted to scheme what technologies I might want to come to understand to do what I want to do. Already I think ASP.NET is on the plate. I was thinking about the front-end of things. I was hoping to come up with something of an editor that allowed somebody to move boxes and arrows around to make a flowchart. So it would be like a flowchart editor that is served up on a web page. The result of that flow chart is something that the back end would use to do things. I would assume one reason you don't see stuff like that online too often is because it's very difficult. I was wondering what I should investigate as ways to do it.

Dilbert As FUCK
Sep 8, 2007

by Cowcaster
Pillbug
Okay I was wondering if it was possible to write a script to reboot windows into safe mode. I am not talking about giving an option to boot into safe mode every time, just a bat or vbs script to do so. Any help would be greatly appreciated.

G-Dub
Dec 28, 2004

The Gonz

mobby_6kl posted:

It seems like there are Perl modules to automate IE as well as libraries that could be used from C# or VBA code, but if anyone has done this previously, some suggestions would be much appreciated.

My first project when I joined the development team in my work involved writing an app that would log in to a third party web page and then scrape a few pages for data. I did this using Access/VBA and it worked a treat. The web page did some sort of client-side encryption on the password that I couldn't replicate in VBA so I couldn't just POST the details to the login form's action. Instead I just fired values in to the form fields then clicked the login button. Everything else could then be done through POSTing and URL manipulation. I don't have the source handy as it's in work, but I'm sure you do something like the following to physically place values in form fields:

code:
IEObject.document.all("Username").Value = strUsername
IEObject.document.all("Password").Value = strPassword
IEObject.document.all("Submit").Click
Another handy thing is waiting for IE to not be in a busy state before carrying out further commands. Initially problems were faced because we use a slow as poo poo proxy for everything and it was trying to do commands while IE was not ready to accept them. I do something like:

code:
Do While IEObject.Busy
  Do Events
Loop
I would get my wrists slapped if I sent any source home as it's restricted material, apparently, but if you want to know anything more then let me know any areas you're stuck on and I'll look at what I have done and try and regurgitate it when I get home.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

mobby_6kl posted:

It seems like there are Perl modules to automate IE as well as libraries that could be used from C# or VBA code, but if anyone has done this previously, some suggestions would be much appreciated.

Look into AutoIT as well. You could write it in pure AutoIT, or use its COM bindings to write it in most other langauges. Part of the library included with it has a poo poo-ton of IE automation functions...

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
No mention of Selenium yet? Odd.

Smeg Head
Apr 22, 2010
Got an issue with NetBeans 6.9.1, programming Java.

I'm trying to get a random variable e.g Random chamber = new Random(6); to have it's value equaled by an integer of any description...like int a = chamber; or int a == chamber;

This doesn't seem to work in Netbeans...neither does making the random number be allowed to == anything or have the use of the && command. Really pissing me off, since I need to do the following.

Create a random number from 1 to 6. I can get that by Random chamber= new Random(6);

Then create a random round that's also from 1 to 6 so Random round = new Random(6);

Create an if statement where if(chamber==round) { stuff happens }

Just having some major issues getting random varables to do anything or interact in any way.

So I need a method of getting their values slapped onto an integer which I know is much more mallable and useful to mess around with. Any help is greatly appreciated, might even give something to the person that hands me a solution (steam present ect) .

spiritual bypass
Feb 19, 2008

Grimey Drawer
What's the return type of Random()?

Smeg Head
Apr 22, 2010
Thanks for the reply, I'm not sure exactly. This is my first time tackling randoms in Java, any idea what the return type should be? I'm just after numbers I can compare with each other.

Edit.

After some fiddling I've got this without any errors showing up.

Random a = new Random();
Random b = new Random();

int chamber = a.nextInt(5);
int round = b.nextInt(5);

// lots of code later

if(isDown[fireKey]&&round==chamber)

{

g.drawImage(imgbrains1, 25, 50, Graphics.TOP | Graphics.LEFT);
flushGraphics();

counter ++;
}

Time to test it I guess.

Smeg Head fucked around with this message at 03:09 on Jan 2, 2011

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Smeg Head posted:

Thanks for the reply, I'm not sure exactly. This is my first time tackling randoms in Java, any idea what the return type should be? I'm just after numbers I can compare with each other.

Edit.

After some fiddling I've got this without any errors showing up.

Random a = new Random();
Random b = new Random();

int chamber = a.nextInt(5);
int round = b.nextInt(5);

// lots of code later

if(isDown[fireKey]&&round==chamber)

{

g.drawImage(imgbrains1, 25, 50, Graphics.TOP | Graphics.LEFT);
flushGraphics();

counter ++;
}

Time to test it I guess.

Firstly, you should post this in the Java thread, and secondly, you're slightly misunderstanding what a Random instance is - it's for generating random numbers (using the nextInt method or one of the many other ones) - it isn't a random number itself.

Also, you should never compare with == unless you absolutely want to check reference equality - whether two objects are exactly the same - or are using primitive types like ints and floats. Always use the equals() method otherwise.

Smeg Head
Apr 22, 2010
Thanks, I'll do just that.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
Here's an interesting serial data communication/hardware interaction problem:


I've written some C# code that uses serial communication to do some stuff. It works great if the serial port isn't actually connected to anything.

If it's connected to my custom circuit, however, it throws System.IO.IOException.

If that's not a mindfuck enough, Hyperterminal is able to send. Which leads me to believe that it's my code.

Is there some sort of collision detection voodoo at work here?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
ante: Does the IOException have any additional details? Pastebinning a relevant chunk of your code couldn't hurt.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
"The I/O operation has been aborted because of either a thread exit or an application request."


To eliminate any other sources of error, I've got it right in the constructor, so the only code is this:

code:
InitializeComponent();
serialPort1.Encoding = Encoding.UTF8;
serialPort1.Open();
byte[] comSend = new byte[1];
comSend[0] = 0x15;
serialPort1.Write(comSend, 0, 1);
Nothing special about serialPort1, it's 115200 8N1, everything else default VS2010


edit: It also seems to work at 9600 baud :wtf:

I'm transferring some pretty large files(potentially), so I'd still like get this working, if I could.

ante fucked around with this message at 03:53 on Jan 4, 2011

Harvey Mantaco
Mar 6, 2007

Someone please help me find my keys =(
I know a bit about editing webpages (a little java, php, xhtml and stuff like that). That being said, Setting one up from the ground up sounds pretty difficult for me. Is there a program I can purchase that would allow me to easily set up a website (template, almost) where I could change some things as needed, and more importantly post updates to it in kind of a blog like format? Tons of control isn't required, just some. Or if anyone could point me in the right direction, there are just so many options out there and it's all pretty confusing.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Wordpress is a pretty easy way to get going and it's free. Customizing templates for it isn't difficult and if you want to do some real coding down the line, there's plenty of room to do it.

Harvey Mantaco
Mar 6, 2007

Someone please help me find my keys =(

rt4 posted:

Wordpress is a pretty easy way to get going and it's free. Customizing templates for it isn't difficult and if you want to do some real coding down the line, there's plenty of room to do it.

I really just needed something that would be easy for my girlfriend to update using (she doesn't know much about this stuff) and it seems like Wordpress is a pretty good choice for that. Is that a good excuse to finally buy a new windows based computer or is there a similar mac equivalent?

nielsm
Jun 1, 2009



Harvey Mantaco posted:

I really just needed something that would be easy for my girlfriend to update using (she doesn't know much about this stuff) and it seems like Wordpress is a pretty good choice for that. Is that a good excuse to finally buy a new windows based computer or is there a similar mac equivalent?

Wordpress is a blog software, it runs entirely on the web server so it only requires a web browser to use and post new content.
(It does require some more software to do the initial set-up and maintenance, though, but some web hosts might offer automated installation of Wordpress and other popular software packages. I.e. you'd need an FTP client and a text editor to do some configuration and upload the files.)

spiritual bypass
Feb 19, 2008

Grimey Drawer
Don't try hosting it at home on your cable modem. You'll have much better results with less hassle if you find somewhere to host your blog at something like $1/month. There's good deals on hosting in SA-mart.

Woofington
Jul 23, 2010

by T. Finn
I used to run a minecraft server. I had access to it via ftp and some user control panel. Is there anyway I could upload a script of some sort (a batch maybe) that would automatically zip a folder, upload it zipped folder to my computer, as well as call a program to render a screenshot of the map. And have it so this script executes once daily?

baquerd
Jul 2, 2007

by FactsAreUseless

Woofington posted:

I used to run a minecraft server. I had access to it via ftp and some user control panel. Is there anyway I could upload a script of some sort (a batch maybe) that would automatically zip a folder, upload it zipped folder to my computer, as well as call a program to render a screenshot of the map. And have it so this script executes once daily?

What kind of operating system is your server running? And yes unless your administrator is preventing you from doing so.

Harvey Mantaco
Mar 6, 2007

Someone please help me find my keys =(

rt4 posted:

Don't try hosting it at home on your cable modem. You'll have much better results with less hassle if you find somewhere to host your blog at something like $1/month. There's good deals on hosting in SA-mart.

Oh yeah, Hostgator can certainly get all of my cash bucks.

pram
Jun 10, 2001
I want to display tomorrows date ( %m%d%y format) in TCL but for some reason this code isn't working:
code:
set s [clock scan [clock format [clock seconds]]]
set a [clock add $s 1 day -timezone :America/Central]
set x [clock format $a -format {%m:%d:%y} -timezone :America/Central]
returns:
code:
bad option "add": must be clicks, format, scan, or seconds
    while executing
"clock add $s 1 day -timezone :America/Central"
    invoked from within
"set a [clock add $s 1 day -timezone :America/Central]"
    (file "clock.tcl" line 2)
Which seems odd to me because the TCL documentation says "clock add" is a thing:
http://www.tcl.tk/man/tcl8.5/TclCmd/clock.htm#M5

EDIT: nevermind I figured it out, this displays tomorrows date lol:

code:

clock format [clock scan "tomorrow"]

pram fucked around with this message at 08:27 on Jan 6, 2011

Adbot
ADBOT LOVES YOU

Woofington
Jul 23, 2010

by T. Finn

baquerd posted:

What kind of operating system is your server running? And yes unless your administrator is preventing you from doing so.

I would guess its running a linux distro...

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply