• Welcome to Valhalla Legends Archive.
 

Re:Palindrome Detection

Started by Mephisto, May 11, 2004, 08:47 AM

Previous topic - Next topic

Mephisto

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.).

iago

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.  
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Zeller

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.

Tuberload

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;
}
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

Mephisto

#4
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.

MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Eibro

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.
Eibro of Yeti Lovers.

Mephisto

#7
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.  ;)

Adron

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.

Mephisto

#9
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...

AC_Drkan

#10
Look at my post in Palindrome Detection
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

Adron

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...

Banana fanna fo fanna

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")

dxoigmn

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?

Banana fanna fo fanna