Re: pointers to variables ?

new topic     » goto parent     » topic index » view thread      » older message » newer message
cjnwl said...

Hi,

Another newbie question: are there pointers to variables, or is there any way to simulate them ?

ChrisB said...

Hi

As far as I am aware there is no access to Euphoria's symbol table - at the moment.

Cheers

Chris

ghaberek said...

Long answer: technically yes, but not in a way that's available to the user.

While Euphoria does have its own symbol table internally, the only user-facing access to it is via routine_id() which is obviously just for routines. There is no equivalent variable_id().

Actually, this is not quite right. This access does exist through the debugger API. You can see https://openeuphoria.org/forum/m/136714.wc for details

But it's not complete - what seems to be missing is the ability to set a value through the API, right now it only offers a read-only view.

cjnwl said...

For example, in gawk there are no pointers per se, but you can simulate them using the SYMTAB array:

my_list[1] = "test" 
var = "my_list"  
print SYMTAB[var][1] 
This last line is equivalent to
print my_list[1] 

I'd just like to point out that using std/eumem might be another option to emulate this. Though you can't turn an existing variable into an eumem reference, and eumem references are integers (or list indices) as opposed to human readable names.

So the above could be written like this

integer var 
... 
integer my_list = eumem:malloc({}) 
ram_space[my_list][1] = "test" 
var = my_list 
print(1, ram_space[var][1]) 
}}} 

In fact, maps (in the solution/implementation suggested by ghaberek) use eumem internally for their implementation.

katsmeow said...

Thanks for bringing this up again. Every couple of years, someone needs this feature.

Yup, probably the reason why things like eumem and the debugger API exist.

katsmeow said...

As usual, <snip> finding it not available, new people promptly leave Euphoria. There's simply less euphoria in Euphoria than people expect now.

Kat

Fair point. I think in the specific context of pointers however, this isn't a widely wanted feature. Many other much more popular languages like Python, Ruby, and Javascript lack it and do well without it.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu