Computer Science Canada Vowel/Constanent |
Author: | Thuged_Out_G [ Sat Apr 29, 2006 12:01 am ] | ||||
Post subject: | Vowel/Constanent | ||||
Was bored, and saw another user was asking how to do this .. so i decided to add it to turing. So it can be easily used. This module will check a given letter if it is a vowel/consonant. Check.tu
Add that to "%oot/support/predefs", save as "check.tu" Then add the line "%oot/support/predefs/Check.tu" to "%oot/support/predefs/predefs.lst" right at the end of the rest of the functions/procuderes you can then call it by
May be useful in some programs, im sure just about every compsci student in HS has had an assignment where that could have been useful at some point. ![]() |
Author: | Thuged_Out_G [ Sat Apr 29, 2006 12:11 am ] |
Post subject: | |
Wow, i spelt consonant wrong. In both the thread name and fcn ![]() Also, is there a way for (w:string) to be a variable number of arguments. Like i think in ruby it is "*args". Is there anything like this in turing. |
Author: | Cervantes [ Sat Apr 29, 2006 6:39 am ] | ||||
Post subject: | |||||
Why not just add this to the String module? Thuged_Out_G wrote: Also, is there a way for (w:string) to be a variable number of arguments. Like i think in ruby it is "*args". Is there anything like this in turing. That's right. *args in ruby, however, is basically an array.
You can do a similar thing in Turing:
However, all the arguments must be of the same type, and you'll have to make an array before hand to send to foo. Lots of extra work. Also, it would be easier if you converted the word to all upper case or all lower case so you didn't have to check "e" and "E". |
Author: | do_pete [ Sat Apr 29, 2006 9:50 am ] |
Post subject: | |
You only really need the Vowel fcn because if it returns false then you know its a consonant |
Author: | Delos [ Sat Apr 29, 2006 11:58 am ] |
Post subject: | |
do_pete wrote: You only really need the Vowel fcn because if it returns false then you know its a consonant
Quite true. If you *really* want to have both Vowel and Cons fcns, simply create a 'Check' fcn, and call that fcn from within the Vowel and Cons structures. The Check fcn would essentially do what is already being done. |
Author: | Thuged_Out_G [ Sat Apr 29, 2006 12:30 pm ] |
Post subject: | |
This sounds n00bish, but how do you change a letter to upper or lowercase? Also, is there another way to do this? Other than using 'index'. I know i could use ord, IS there another option? |
Author: | [Gandalf] [ Sat Apr 29, 2006 12:36 pm ] |
Post subject: | |
Either use Str.Upper() and Str.Lower() or if you want to create the functions yourself read Cervantes' string manipulation tutorial which is found in the Turing Walkthrough. |
Author: | TokenHerbz [ Sat Apr 29, 2006 12:46 pm ] | ||
Post subject: | |||
you can get the number of the letter with ord(letter) EDIT: gandalf, my turing dosn't have "Str.Upper() and Str.Lower()" |
Author: | wtd [ Sat Apr 29, 2006 1:06 pm ] | ||
Post subject: | |||
With a little work this code can be much more concise. untested
|
Author: | MysticVegeta [ Mon May 01, 2006 1:57 pm ] | ||
Post subject: | |||
hehe wtd messed up for the first time in history, the vowels is not an array wtd! the loop could simply be reduced by:
note: this is untested too Ofcourse your way would work too, by cehcking each letter but one thing I learned, why use redundant code? Note: I dont know what happened, why did it double post?? Could someone delete it please, i really dont know what happened, sorry guys |
Author: | [Gandalf] [ Tue May 02, 2006 1:18 am ] | ||||
Post subject: | |||||
I would guess that wtd programs in Turing less than regularily, and he probably doesn't even have it installed, so any mistakes can hopefully be excused. Anyway, ironically, you are wrong and wtd had it right. The way you had it the program would check if string contained every vowel in order. You should be checking to see if w2 contains any of the letters in vowels. I hope that by now you know that in Turing you access the character at a specified index in a string the same way you access the element at a specified index in an array. Also, you got the arguments to the index function wrong, it's:
Now, some minor syntatic troubles in wtd's code:
|
Author: | Thuged_Out_G [ Tue May 02, 2006 2:00 am ] | ||
Post subject: | |||
I can up with something a bit different. The reason for the "redundant" code, was because I only decided to write it out of boredom when i saw i post in turing help forum, for it i needed to know exzactly which letter was a vowel/consonant. This one will tell you if its a vowel, consonant, non letter, or white space.
As advised, i got rid of the cons function ... Since like previously stated, was useless. My turing, also does not have Str.Lower(), Str.Upper() ... so i was stuck with using chr(ord()) to convert to lower case. |
Author: | MysticVegeta [ Tue May 02, 2006 5:37 pm ] | ||||
Post subject: | |||||
[Gandalf] wrote: I would guess that wtd programs in Turing less than regularily, and he probably doesn't even have it installed, so any mistakes can hopefully be excused.
Anyway, ironically, you are wrong and wtd had it right. The way you had it the program would check if string contained every vowel in order. You should be checking to see if w2 contains any of the letters in vowels. I hope that by now you know that in Turing you access the character at a specified index in a string the same way you access the element at a specified index in an array. Also, you got the arguments to the index function wrong, it's:
Now, some minor syntatic troubles in wtd's code:
oh sorry about that, I did actually say that wtd method works, I made a mistake in the order of index(string,vowels). Sorry about that. |
Author: | PerylDemise [ Wed May 03, 2006 11:07 pm ] |
Post subject: | |
Is there any way to achieve this without using units or modules? |
Author: | [Gandalf] [ Wed May 03, 2006 11:15 pm ] | ||
Post subject: | |||
Yes, just remove the appropriate code from the module:
But why? MysticVegeta wrote: I made a mistake in the order of index(string,vowels).
You also made the much larger error of checking the specified string variable for each vowel, in order, at once. |
Author: | Thuged_Out_G [ Thu May 04, 2006 12:09 am ] |
Post subject: | |
PerylDemise wrote: Is there any way to achieve this without using units or modules?
Only reason unit/module was used was so i could add the code to the turing library, so it could be called from any program. You can use the one gandalph posted, or the most recent one i posted ... then just call it like any normal function. |