So I was happily Haskelling away last night, using Hugs, the Haskell interpreter, and everyone was nice and happy. And yet, it was squawking at me:
ERROR "parse.hs":129 - Syntax error in expression (unexpected ;', possibly due to bad layout)<br><br>Lines 127->129 look like<br><br>morphLeaf :: Entry -> Entry<br>morphLeaf (Unparsed a) | (isDigit . head) a = ((Leaf . foldl1 (\d e -> d * 10 + e) . map (\d -> (fromEnum d - fromEnum '0')) a)<br>morphLeaf a = a<br><br>Now, I don't mind Hugs alerting me that something's wrong with my code, but I'm a bit miffed at how it's telling me that. Specifically, I don't have a
;' character there. I don't have a ;' character anywhere, even, and yet it's telling me that there's one too many. It might want -1
;' characters.
Apparently, someone made the decision to make ;' the end-of-construct signifier and not tell anyone, so I get this message when I miss a
)', because telling me that there's no )' there would just be confusing, right?<br><br>"Unexpected
;'" means mismatched parentheses
"Unexpected }'" also means mismatched parentheses, or maybe it's missing one<br>"Unexpected
|'" means an unexpected pipe character. Though after the last two errors, I'm not so inclined to believe it, and I might have a stray colon in there or something, who knows?
Posts made by Shen
-
Hugs error messages
-
RE: What indent style do you use?
Mine is pretty much K&R C styly. Also tabs. I like tabs. That are 8 wide. Don't see what the big deal is with them.
Function calls get a bit extra space padding to them.
Anyway, code sample:
<font face="Courier New">int main( int argc, char *argv )
{
int i;
for (i = 0; i < argc; i++) {
if (strlen( argv[i] ) >= 3) puts( argv[i] );
/ comment, eh? */
}
return 0;
}
</font>
I used to do the thing that people do where they put curly brackets on the line after the for or if statement, but that looks a bit weird when you do this:
<font face="Courier New">
if (c = string[i] && (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c == '_'))
{
</font>
I mean look at the poor curly bracket, it's so lonely. -
RE: Programming in prose - is it out there?
I once managed to abuse Hugs (a Haskell interpreter) so I could talk to it prose-like. It was mainly lists, but it wasn't half bad:
> say "Hello"
"Hello"
> its length
5
> is that: equal to 7
No
> take 4 integers
[1, 2, 3, 4]
> map square to them
[1, 4, 9, 16]
> compare these with: take 4 squares
Equal
"them" and "these" and "it" and those things were automatically generated. "to" and "with" were just 0 and are just semantics. (:) acts like ($) as separation. The last one is pushing the prose a bit but I think it still works. Since it's Haskell doing all the work here, not my own language, I think I'm allowed some limits. -
RE: If Not foo Is Nothing...
@versatilia said:
I'm so happy I do Perl...
Perl's nice but it has its fair share of true and false quirks too. Such as why "0" is false. "" is false as well, which is of course useful if you're reading in lines from a file...... I think you have to use &defined for that, but I think it does it automagically now too. I forget.
Ruby's nice too:
if 0
puts "0 is true, callay, calloo"
end
-
RE: New Ads
The ads here aren't that bad. In general, if you have JavaScript off
(NoScript firefox extension I love you to bits) you're not going to see
anything too annoying. Except if it flashes, then you can stab it. -
RE: A level IT
I was told to stay away from IT at A level, and go for the maths instead, 'cause, as you say (correctly), it's not worth it. Most places aren't interested in IT, they look for Computing, and it's been like that for the last few years. (I'm just adding this in, in case anyone was still in doubt about what a bad idea IT is).
And most courses teach VB. gaaaaah. Brain cringe.
Of course, if you want to "improve the nation's schools", you can spend some money on actually improving them, or change the metric at which schools are rated. So, we get subjects like IT that are ridiculously easy to pass, and often incorrect, and are just click-click-click-do-this-do-that and you don't need to understand what you're doing, and are often only chosen because people want to piss about during the classes, but at which the government can point at and say "See, students are now passing exams, so we must be doing something right!" and use nice figures above 90% for pass rates, whatever they're meant to mean these days.
I sure am annoyed these days. Maybe it's the Further Maths... -
RE: Javascript get existing element problem
This is the wrong forum. Use the other board "Coding related help & questions" for things like this.
But just for you, the indexOf function asks whether a string is in another string, if that is what you want:
<font face="Courier New">"Person/Personal/Academic[1]/Grade".indexOf("[1]") <font face="Times New Roman">is 24 because "[1]" occurs at the 24th character.
</font>"Person/Personal/Academic[2]/Grade".indexOf("[1]") <font face="Times New Roman">is -1 because "[1]" doesn't occur in the string.
So if you want to check if there's a "[1]" in a string, use<font face="Courier New"> "</font></font>Person/Personal/Email[1]</font><font face="Courier New"><font face="Times New Roman"><font face="Courier New">".indexOf("[1]") == -1</font>
</font></font> -
RE: DaVinci Code
Naah, that dude's a hardcore. He wrote his code using Paint...
-
RE: TV set to Vibrate
Are you sure it isn't something vibrating in your room? 'Cause that's
what sound is, like, and if it's low enough it vibrates things in the
room too. Bass, yeah. -
RE: There's more then one way to make a random number
PHP most definitely has types. See the === operator, and its type comparison tables.
And why risk it, it might break in the future ;) -
RE: There's more then one way to make a random number
@welcor said:
@LazyJones said:
There's this fellow
I've been trying to help on PHP forum. Pretty intresting case all in
all, but I found this beauty from his code. His idea is to create a
random number for some kind of user check. This is what he has come up
with:
$length = 8;
$key_chars = '0123456789';
$rand_max = strlen($key_chars) - 1;
for ($i = 0; $i < $length; $i++)
{
$rand_pos = rand(0, $rand_max);
$rand_key[] = $key_chars{$rand_pos};
}
$randomnumber = implode('', $rand_key);The reason it's done this way is, if not obvious, not far-fetched. It can be easily expanded to include letters and special characters:
<font face="Courier New">$key_chars = '0123456789aAbBcC*%.:,';</font>
The current key_chars string, and the name of the resulting variable ($randomnumber) is slightly wtf-worthy, though.
$randomnumber doesn't even hold a number, it's a string! So either he was going to do what welcor said and named the variable wrong, or he used a bad method. There's no getting out of this one
-
Gconf, eh
I'm not even going to try to post an image (this forum sucks) so here is a link to it:
In other news, don't delete half of /home and hope that everything's going to be alright.
-
RE: WTF this guy has problems
Wow, talking about Hitler from the start!
Godwin would be turning in his grave, if he was dead.