What the hell is that? Did you come up with some random code to put on here with some explanation completely off topic from your original question?
Also, just because it runs, does not mean it should be done that way...I'm surprised your compiler would even compile that (unless you're using Microsoft's which doesn't *just* support ANSI standard code; Microsoft likes to have their own standards and things on their own way. For instance, you could use void main() legally without warnings or errors in MSVC++ or specify scope of variables in your loops, etc.).
Quote from: Mephisto on May 11, 2004, 08:47 AM
What the hell is that? Did you come up with some random code to put on here with some explanation completely off topic from your original question?
Also, just because it runs, does not mean it should be done that way...I'm surprised your compiler would even compile that (unless you're using Microsoft's which doesn't *just* support ANSI standard code; Microsoft likes to have their own standards and things on their own way. For instance, you could use void main() legally without warnings or errors in MSVC++ or specify scope of variables in your loops, etc.).
There's nothing wrong with loop-scoped variables.
And did you just talk down at Microsoft?
Anyway, let me say it again, talk to your teacher. You can't do a lot of what you are doing in your code.
Quote from: Mephisto on May 11, 2004, 08:47 AM
... or specify scope of variables in your loops ...
Can you give an example or something about that. I dont understand what you mean.
Quote from: Zeller on May 11, 2004, 01:54 PM
Quote from: Mephisto on May 11, 2004, 08:47 AM
... or specify scope of variables in your loops ...
Can you give an example or something about that. I dont understand what you mean.
while (true)
{
int loop_scoped_variable = 1;
}
No, I meant you can select that you can declare variables in loops and they will still be in scope outside of the loop. I believe you can do this in MSVC++, if not, then I'm mistaken...But I'm pretty confident you can.
Quote from: Mephisto on May 11, 2004, 06:19 PM
No, I meant you can select that you can declare loops in variables and they will still be in scope outside of the loop. I believe you can do this in MSVC++, if not, then I'm mistaken...But I'm pretty confident you can.
You meant that you can declare
variables in loops and they will still be in scope outside of the loop. This is not proper according to C++ 99 (I believe that's the spec) -- variables inside of a loop remain in scope only for that loop.
Quote from: Mephisto on May 11, 2004, 06:19 PM
No, I meant you can select that you can declare loops in variables and they will still be in scope outside of the loop. I believe you can do this in MSVC++, if not, then I'm mistaken...But I'm pretty confident you can.
Yes, only VC6 had this problem. It's fixed in VS.net 2002/2003, though there's a compiler option to toggle whether it's enforced or not.
Ex.
for ( int i =0; i < 10; ++i ) { /* code.. */ } i = 25
is illegal.
Which is exactly what I was pointing out. And in Eibro's example, you could make his example legal in MSVC++. This is because Microsoft supports ANSI/ISO C++, but they have their own standards if you want to call it that, and support things that are illegal in C++ standards, such as using void main() function definitions, and variable loop scope resolution.
Thanks MyndFyre, typo. ;)
Quote from: Mephisto on May 11, 2004, 10:32 PM
Which is exactly what I was pointing out. And in Eibro's example, you could make his example legal in MSVC++. This is because Microsoft supports ANSI/ISO C++, but they have their own standards if you want to call it that, and support things that are illegal in C++ standards, such as using void main() function definitions, and variable loop scope resolution.
Thanks MyndFyre, typo. ;)
You mean, they support things that are different from the latest C++ standards, i.e. they are backwards compatible. Being optionally backwards compatible is a very good thing.
Of course. I don't think I ever said it was a bad thing, I was just pointing out that they support other things in C/C++ that isn't compatable with ANSI/ISO C/C++ standard.
However, if people just learning start out using MSVC++ and tutorials on MSDN and such (which use void main() definitions, and other things that may be illegal in C/C++), the new one starting may develop bad coding. :p It should be important to know what the C/C++ standards are and how to properly code in them, and then take advantage of what Microsoft has to offer in their compilers that is illegal in C/C++ standards if you want to...
Look at my post in Palindrome Detection
Quote from: AC_Drkan on May 13, 2004, 10:06 AM
Look at my post in Palindrome Detection
Which one? I posted multiple working answers to your problem...
Took me a couple minutes and one bug to whip this up. Was a nice little exercise! :)
(define is-palindrome-helper
(lambda (str start length)
(if (> start (quotient length 2))
#t
(and
(equal? (string-ref str start)
(string-ref str (- (- length start) 1)))
(is-palindrome-helper str (+ start 1) length)
)
)
)
)
(define is-palindrome
(lambda (str)
(is-palindrome-helper
str
0
(string-length str))))
(is-palindrome "racecar")
Quote from: St0rm.iD on May 14, 2004, 03:59 PM
Took me a couple minutes and one bug to whip this up. Was a nice little exercise! :)
(define is-palindrome-helper
(lambda (str start length)
(if (> start (quotient length 2))
#t
(and
(equal? (string-ref str start)
(string-ref str (- (- length start) 1)))
(is-palindrome-helper str (+ start 1) length)
)
)
)
)
(define is-palindrome
(lambda (str)
(is-palindrome-helper
str
0
(string-length str))))
(is-palindrome "racecar")
Eww. What do you use to run that? Dr Scheme?
Yup :)
I hope whoever cares doesn't take Storm's code seriously. :)
Quote from: Mephisto on May 14, 2004, 08:26 PM
I hope whoever cares doesn't take Storm's code seriously. :)
Scheme is a programming language...
Yes, but this is C/C++, not scheme. I seriously doubt he cared about an answer in scheme. :p
Quote from: Mephisto on May 14, 2004, 09:15 PM
Yes, but this is C/C++, not scheme. I seriously doubt he cared about an answer in scheme. :p
That was not my point. For people that truly care, maybe they should take his code seriously... A discussion can be spawned from a question. That discussion does not necessarily have to stick with the initial question.
Programming is an art, and a language is a tool.
*shrug*
I think you're missing the point of a C/C++ programming forum. The one who started the initial question didn't want the code in Scheme, and if they did I'd be suprised. Storm randomly (and probably joking around) posted some code in Scheme. I doubt the one who asked the question would care, especially since they posted this in the C/C++ programming forum, and wanted a C/C++ answer. Who the hell cares about an answer in Scheme at this point? Jeesh...
Quote from: Mephisto on May 14, 2004, 09:42 PM
*shrug*
I think you're missing the point of a C/C++ programming forum. The one who started the initial question didn't want the code in Scheme, and if they did I'd be suprised. Storm randomly (and probably joking around) posted some code in Scheme. I doubt the one who asked the question would care, especially since they posted this in the C/C++ programming forum, and wanted a C/C++ answer. Who the hell cares about an answer in Scheme at this point? Jeesh...
Do you even read what is said to you before you reply?
*shrug*
Must you have to try and argue that someone should really take Storm's code into account when this is a C/C++ board, with a C/C++ question, expecting C/C++ answers and not code from another language? Jeesh...
Good job, Meph. Your last reply stopped everyone from helping you.
Quote from: Mephisto on May 14, 2004, 10:40 PM
*shrug*
Must you have to try and argue that someone should really take Storm's code into account when this is a C/C++ board, with a C/C++ question, expecting C/C++ answers and not code from another language? Jeesh...
I was not attempting to argue with you, I was trying to get a very subtle message acrossed...
Quote from: Mephisto on May 14, 2004, 10:40 PM
*shrug*
Must you have to try and argue that someone should really take Storm's code into account when this is a C/C++ board, with a C/C++ question, expecting C/C++ answers and not code from another language? Jeesh...
As we have previously concluded that this is some kind of homework question, and that we shouldn't provide direct "paste this code into your program" answers to those, what's wrong with his answer?
I like Storm's code. It's one of the "pseudo-code" category answers, except that his code happens to be working in a different language.
Besides, if you want there to be an easier to use answer, you could provide that yourself. This is a really easy question, anyone with some C++ programming experience should be able to write such a program (not one suitable for handing in, but one that works) in 5 minutes. If you want to give the user what he "expects", by all means, go ahead, do it. Don't complain at others who choose to give hints only.
fine...
- for each character 1..n/2 indexed by i in an n-length string s...
- check whether s == s[n-i]
- logical AND with the next character test
heh, it's lamda calculus.. that's kinda neat :)