a question about "string interpolation" in ring

30 views
Skip to first unread message

de...@roo.com.br

unread,
Sep 13, 2023, 4:42:53 PM9/13/23
to The Ring Programming Language
Hi all!
ring have some way and/or operator to expand like $$ in php ?

$ cat test.php
<?php

$name = "earth";
$nameOfPlanet = "name";

echo $nameOfPlanet  . PHP_EOL;
echo $$nameOfPlanet . PHP_EOL;

$ php test.php
name
earth


*  The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using the $ symbol before the $x value. These are called variable variables in PHP. 

Ilir Liburn

unread,
Sep 13, 2023, 7:30:27 PM9/13/23
to The Ring Programming Language
Hello Denis,

no to my knowledge. But you can make function acting as $$ operator like this

$name = "earth"
$nameOfPlanet = "name"

? $nameOfPlanet
? $($nameofplanet)

func $ var
return eval("$"+var)

This will work only for global variables obviously.

Greetings,
Ilir

Mansour Ayouni

unread,
Sep 14, 2023, 12:36:25 PM9/14/23
to Ilir Liburn, The Ring Programming Language
Hello Denis and Ilir,

In Ring, using SoftanzaLib external code support, it's easy to reproduce nearly the same code as PHP, like this:

image.png

All the best,
Mansour

--

---
You received this message because you are subscribed to the Google Groups "The Ring Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-lang+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ring-lang/2caf07ae-0c7c-4465-9ff8-55918bdfa4a1n%40googlegroups.com.

Mansour Ayouni

unread,
Sep 14, 2023, 5:20:06 PM9/14/23
to Ilir Liburn, The Ring Programming Language
Hello Denis and Ilir,

And this is a better version where the PHP code is reproduced as is with some parentheses added for convenience with Ring:

image.png

Best,
Mansour
Reply all
Reply to author
Forward
0 new messages