Naming VARIABLES?

Started by
15 comments, last by FxMazter 20 years, 8 months ago

quote:Original post by FxMazter
Well... I have looked into the PHP syntax and it is like this:

$variable = "Billy"
$$variable = 21

Result of printing $Billy:
21

Now the reason behind this is nothing special... but just out of curiosity.

Thank you for the posts anyway


Well i have no idea about PHP and i have absolutley no idea why there would ever be reason to assign a variable to a string, what youre suggesting is very unstable in C++, but you could use atoi() to cast the string to an int, or itoa() to do it the other way around.

An ASCII tetris clone... | AsciiRis

[edited by - Tiffany Smith on August 15, 2003 5:25:15 PM]
An ASCII tetris clone... | AsciiRis
Advertisement
will atoi() work on strings of letters? I always thought that it was only used for strings that represented numerical IP addresses.

Do you use your powers for good or for awesome?
My newly updated site | The Cutter Project | Association of Computing Machinery

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

quote:Original post by Tiffany Smith
Well i have no idea about PHP and i have absolutley no idea why there would ever be reason to assign a variable to a string, what youre suggesting is very unstable in C++, but you could use atoi() to cast the string to an int, or itoa() to do it the other way around.

You don't understand what he's talking about. What the OP wants is absolutely impossible in C++. There's no way to do that (besides simulating "variables" with a table/dictionary/what have you).

Just because it's impossible in C++ doesn't mean that it can't be useful, though.

[edited by - twix on August 15, 2003 6:01:23 PM]
What you''re asking seems awfully like something that pointers/references would be able to do. So I''m thinking along the same lines as Jason suggested over here:

quote:Original post by Jason2Jason
What that does look like though is pointer syntax. Your doing something that looks like this:

int variable1;int* test = &varible1*test = 22;   


the result of variable1 would be 22 using the * operator. Read in to pointers if your not too sure of what I just wrote. Sorry if you already know about them

-J


So why doesn''t it answer your question?




--{You fight like a dairy farmer!}

--{You fight like a dairy farmer!}

quote:Original post by Greatwolf
So why doesn't it answer your question?

An analogous feature in Lisp is the function intern, which converts a string to a usable symbol (variable name). Maybe this will be a bit more illuminating than PHP, maybe not.
>> (setf name "VARIABLE")"VARIABLE">> (set (intern name) 123)123>> name"VARIABLE">> VARIABLE123 

See what that does? It's not like pointers or references.

...

Of course, in Lisp this "feature" is intensely pointless.

[edited by - twix on August 15, 2003 7:06:59 PM]
quote:Original post by twix
You don''t understand what he''s talking about.


Seemingly so.

An ASCII tetris clone... | AsciiRis
An ASCII tetris clone... | AsciiRis
Sounds like mappings to me. See the STL container "map".
The variable name becomes the key to the map, the value of the variable is the result of querying the key.
Blake's 7 RPG - a new project

This topic is closed to new replies.

Advertisement