Function Mutable Arguments

66 views
Skip to first unread message

Clement

unread,
May 16, 2025, 5:30:06 AM5/16/25
to The Ring Programming Language
Is this the correct way to modify function arguments?

// Test function to pass a mutable list and return back as a modified string variable

func main() {

    greetings = []
    greetings = greetings + "Hello"
   
    AddMessage(greetings)
    puts(type(greetings) + " : " + greetings)
}

func AddMessage(mutableStr) {
   
    mutableStr = list2str(mutableStr) + " World"

    return mutableStr
}

Output:
STRING : Hello World

// In Go would be like this:
func main() {

    greetings := "Hello"

    AddMessage(&greetings)

    fmt.Println(greetings)

}

func AddMessage(mutableStr *string) {

    *mutableStr = *mutableStr + " World"

    return
}

Ilir Liburn

unread,
May 16, 2025, 10:05:18 AM5/16/25
to The Ring Programming Language
Hello Clement,

short answer is: no. If you call AddMessage again, you will get error: Bad parameter type! Because you modified variable type to string, previously list. I recommend to you to work with list items like in this example:

func main() {

    greetings = []
    greetings + "Clement"
    greetings + "World"
   
    AddMessage(greetings)
    puts(greetings)
}

func AddMessage(greetings) {

    if type(greetings) = "LIST"
len = len(greetings)
for i = 1 to len  
    greetings[i] = "Hello " + greetings[i]
next
   elseif type(greetings) = "STRING"
greetings = "Hello " + greetings
   ok
}

which allows you to call AddMessage with individual list item.

Greetings,
Ilir

Clement

unread,
May 16, 2025, 9:43:24 PM5/16/25
to The Ring Programming Language
Understand that Ring can only mutate list type pass to function argument, not variable type.  I was also trying in Rust to test a simple string variable mutation pass to a function, example how it can be written in Rust using &mut greetings:


// Rust test function passing mutable string
fn main()
{
    let mut greetings = String::from("Hello ");

    add_message(&mut greetings);

    println!("{greetings}")
}

fn add_message(some_string: &mut String)
{
    some_string.push_str("World")
}

Mahmoud Fayed

unread,
May 17, 2025, 12:34:44 AM5/17/25
to The Ring Programming Language
Hello Clement

>> "Understand that Ring can only mutate list type pass to function argument, not variable type"

This is at the language design level, but at the implementation level we can :D


These features are used by the Ring debugger (written in Ring itself)

Greetings,
Mahmoud

Ilir Liburn

unread,
May 17, 2025, 6:25:08 AM5/17/25
to The Ring Programming Language
Hello Clement,

I'm going to release Ring2C which allows mutable arguments. It is not going to be announced because it is going to be tested during summer on a real project like Softanza library if Mansour keeps interest. Mutable arguments are fully possible in operator mode (to use in custom operators) and in standard function mode only if variable contains list (because PushV operation keeps pushing basic types onto stack before the function call).

Greetings,
Ilir

Mansour Ayouni

unread,
May 17, 2025, 8:02:54 AM5/17/25
to Ilir Liburn, The Ring Programming Language
Hello Ilir,

on a real project like Softanza library if Mansour keeps interest
with my pleasure my friend!

Softanza will benefit a lot from a strategic alliance with your Ring2C project.

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 visit https://groups.google.com/d/msgid/ring-lang/e6a4bc4c-31ed-420a-8fea-ad9c60c749acn%40googlegroups.com.

Clement

unread,
May 17, 2025, 8:35:58 AM5/17/25
to The Ring Programming Language
Great, can't wait to test out Ring2c

Ilir Liburn

unread,
May 17, 2025, 9:42:19 AM5/17/25
to The Ring Programming Language
Hello Mansour, Clement

Ring2C is expected to be released sometimes next week (earliest) after I write new tests for latest features (like custom operators) and all tests pass. I will send you a message when it is ready (on GitHub, opensource).

Greetings,
Ilir

Mansour Ayouni

unread,
May 17, 2025, 9:58:42 AM5/17/25
to Ilir Liburn, The Ring Programming Language
Hello Ilir,

This is great news! And thank you for open-sourcing this project...

All the best,
Mansour

Ilir Liburn

unread,
May 17, 2025, 10:16:54 AM5/17/25
to The Ring Programming Language
Hello Mansour,

You're Welcome. First Ring2C release is going to be Windows only. It is developed using 32 bit version, later I will add 64 bit version (allowing additionally Linux version, Mac is not supported by TCC to my knowledge).

Greetings,
Ilir
Reply all
Reply to author
Forward
0 new messages