![]() |
| | #1 |
| Ugly C Lover Join Date: Jun 2008 Location: Indonesia
Posts: 462
| I hope I'm not posting in a wrong place ^_^"... Btw, I need your suggestion to my basic like programming language. It has two features called Class Aliases and Alias for subtitution. Class Aliases are just like toString() in Java but they can be used for any Class, not just String. For instance: Code: Class Apple
Alias Apple As String
Return "I'm an Apple!" <-- LOL
End Alias
Alias Apple As Number
Return 10
^-- Just for example
End Alias
/* Syntax:
Alias ClassName As AnotherClassName
.
.
Return objectOfAnotherClassName
End Alias
*/
End Class
Dim apple As New Apple
Console.printLn apple <-- 0x???? the object pointer
Console.printLn apple As String <-- I'm an Apple!
Console.printLn apple As Number <-- 10
Syntax: Code: Alias new_name As name Code: Alias debug As Console.printLn . . debug "ERROR? " & errorNumber Code: Class Apple
Alias print As Console.printLn
Alias Apple As String
print "Test!"
Return "I'm an Apple!"
End Alias
Alias Apple As Number
Return 10
End Alias
End Class
Mmm... maybe there is another way to implement this one? Thanks in advance. |
| audinue is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| To liken this to a C++ feature, would you say that your aliases are like type conversion functions?
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is offline | |
| | #3 |
| Ugly C Lover Join Date: Jun 2008 Location: Indonesia
Posts: 462
| |
| audinue is offline | |
| | #4 |
| Registered User Join Date: Jun 2008
Posts: 1,134
| No, It is not confusing. But again I don't know anything about basic so not really good to judge. The as keyword exists in C# but it doesn't do exactly this Well, why not just make a toInt() or toSomeClass()? Elaborate a bit of the usefulness of such a feature. 1) The toInt(), toObj() etc etc functions can be stored in an interface, so the basic toType() exists always and can be implemented as you want. 2) If they don't exist you 'll get a compile time error. So why make them a language feature? The way C# uses as seems more useful... |
| C_ntua is offline | |
| | #5 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
![]() Taking a look at: Code: Console.printLn apple As String What I do not understand is "Alias for subtitution". How does it differ from "Class Aliases"? They both seem to provide a conversion from the class type to some other type. Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #6 | |||
| Ugly C Lover Join Date: Jun 2008 Location: Indonesia
Posts: 462
| Quote:
Quote:
Quote:
"Alias for subtitution" subtitutes the 'name' of variable/function/class/package/module definition. It doesn't convert anything at all. And works just like safe-macro (it will warn when ambigious things detected) Code: Dim frmMainHandle As HWND
... do something with frmMainHandle ...
{when frmMainHandle is not used anymore...
subtitute it instead of creating a new variable}
Alias btnOKHandle As frmMainHandle
... do something with btnOKHandle ...
Code: #define btnOKHandle frmMainHandle | |||
| audinue is offline | |
| | #7 | |||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |||
| laserlight is offline | |
| | #8 | ||
| Ugly C Lover Join Date: Jun 2008 Location: Indonesia
Posts: 462
| Thank you laserlight!! Quote:
Quote:
| ||
| audinue is offline | |
| | #9 |
| Ugly C Lover Join Date: Jun 2008 Location: Indonesia
Posts: 462
| And yet another confusion: Code: Type SortCallback<T> As Function(a, b As T) As Integer Alias SortStringCallback As SortCallback<Character> Last edited by audinue; 12-06-2008 at 07:44 AM. |
| audinue is offline | |
| | #10 | |
| The larch Join Date: May 2006
Posts: 3,082
| Code: Dim frmMainHandle As HWND
... do something with frmMainHandle ...
{when frmMainHandle is not used anymore...
subtitute it instead of creating a new variable}
Alias btnOKHandle As frmMainHandle
... do something with btnOKHandle ...
Instead why not make a really good garbage collecter and free the programmer of such worries
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #11 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
Be that as it may: If you alias a variable, then that variable is still alive (it just happens to have a different name). So you need to either trust the programmer to to the right thing (like C and C++ does) or rely on some sort of automatic mechanism to handle the "freeing" of the object. -- Mats -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| more then 100errors in header | hallo007 | Windows Programming | 20 | 05-13-2007 08:26 AM |
| We Got _DEBUG Errors | Tonto | Windows Programming | 5 | 12-22-2006 05:45 PM |
| Using VC Toolkit 2003 | Noobwaker | Windows Programming | 8 | 03-13-2006 07:33 AM |
| Connecting to a mysql server and querying problem | Diod | C++ Programming | 8 | 02-13-2006 10:33 AM |
| Dikumud | maxorator | C++ Programming | 1 | 10-01-2005 06:39 AM |