Split() function --- suggestion

76 views
Skip to first unread message

Bert Mariani

unread,
Jun 4, 2024, 8:21:38 PMJun 4
to The Ring Programming Language
Hello Mahmoud

I have a suggestion for  Split() function
I was working with a Perl routine ...that has this additional format 

Current
   cString   = "2022-05-16"
   delimiter = "-"

    aList  =  Split(cString,delimiter)  // ---> List
    year   = aList[1]
    month  = aList[2]
    day    = aList[3]

Suggestion
Can this other format be included where the result goes into specified variables?

       $date = "2022-05-16"
       (year, month, day) = Split($date, "-" )

        $time = "10:15:30:01:AM"
        ($hour, $minute, $second, $rest) = Split($time, ":" )

Thanks
Bert Mariani

Mahmoud Fayed

unread,
Jun 5, 2024, 1:45:56 AMJun 5
to The Ring Programming Language
Hello Bert

See the next example and customize it based on your needs

load "stdlibcore.ring"


cString   = "2022-05-16"
delimiter = "-"

Split2Vars(cString,delimiter,[:year,:month,:day])

? year
? month
? day

func split2Vars(cString,cDelimiter,aVars)
aValues  = split(cString,cDelimiter)
cCode  = ""
for t=1 to len(aVars)
cCode += aVars[t] + " = " + aValues[t] + nl
next
ringvm_evalinscope(ringvm_scopescount()-1,cCode)


Later we will add split2Vars to stdlibcore.ring

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Jun 5, 2024, 1:58:41 AMJun 5
to The Ring Programming Language
Hello Bert

Beside Split2Vars() in my previous post
This is another way to do it (Split2Hash())

load "stdlibcore.ring"


cString   = "2022-05-16"
delimiter = "-"
date = Split2Hash(cString,delimiter,[:year,:month,:day])

? date[:year]
? date[:month]
? date[:day]

func split2Hash(cString,cDelimiter,aVars)
aValues  = split(cString,cDelimiter)
aHash = []
for t=1 to len(aVars)
aHash[ aVars[t] ] = aValues[t]
next
return aHash

Greetings,
Mahmoud

On Wednesday, June 5, 2024 at 3:21:38 AM UTC+3 Bert Mariani wrote:

Bert Mariani

unread,
Jun 6, 2024, 8:30:09 PMJun 6
to The Ring Programming Language
Thank Mahmoud !

For the example functions ...

Mahmoud Fayed

unread,
Jun 7, 2024, 4:41:31 AMJun 7
to The Ring Programming Language
Hello Bert

You are welcome :D

Greetings,
Mahmoud

Mansour Ayouni

unread,
Jun 7, 2024, 7:48:42 AMJun 7
to Mahmoud Fayed, The Ring Programming Language

Hello Ilir,

Softanza enables Ring code to host useful coding constructs available in other languages.

Multiple variables saignement, you illustrated above, is one of them.

So, you just decoratevit with the small vr() and vl() function like this:

 Vr([ :year, :month, :day ]) '=' vl( Split($date, "-" ) )

When you need one of them you call it with the small v() function like this:

 ? V(:year) + " " + v(:month) + " " + v(:year)

The feature has been made to facilitée the porting of existing python (and other languages) solutions to Ring, so one can adopt them quickly.

PS: sorry of the spelling lisrakes since I am using my phone without glasses (before Softanza I had not needed glasses ;) ).

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/bac39071-56ab-4e44-a960-608a62bd0b1bn%40googlegroups.com.

Bert Mariani

unread,
Jun 8, 2024, 9:37:42 AMJun 8
to The Ring Programming Language
Hello Mansour

RE:  "...  (before Softanza I had not needed glasses ;)  ..."

This can be interpreted as:
    -  You must have celebrated your ~ 45th birthday  :)
    -  You need a Bigger screen  :)
    -  You must have been working on Softanza for too many years  :)

By the way ... nice implementation !

Best Regards
Bert

Mansour Ayouni

unread,
Jun 8, 2024, 10:15:38 AMJun 8
to Bert Mariani, The Ring Programming Language
Hello Bert :D

This can be interpreted as...

All your three points are TRUE!

By the way, those who follow the project activity on Github may remark that I'm checking samples in a file I called "lastMile.ring"...

image.png

May this be a good sign of the last mile of those 5 years of heavy work!

... nice implementation !

And thank you a lot for your kind words.

All the best,
Mansour


Mansour Ayouni

unread,
Jun 13, 2024, 9:44:37 AMJun 13
to Bert Mariani, The Ring Programming Language
Hello Bert,

Let me show this to tell you how my glasses influenced the Softanza design :)

The @@() small function lets us show a nice representation of a list, or any thing else, like this:

image.png

Especially in the second command, it adds visibility to the standard  ? output that prints numbers vertically without separation.

@@ resemble visually to the glasses one should put to better see the world :D And this is the metaphor behind the inclusion of this feature in Softanza.

Bonus: You can even use some Unicode icons having the same meaning like this:

🕶( o1.FindTheseBoundsAsSections("<<<", ">>>") )

or

😎( o1.FindTheseBoundsAsSections("<<<", ">>>") )

In practice, it's not easy for the coder to type those two icons when he is writing his program. In fact, the feature is made for a future vision for an IDE that reads the Softanza code and transforms each @@ to 🕶 or 😎 depending on the preference of the user.

@@ itself is very quick to type (in Windows it's [ALT GR] + [0] twice).

By the way: a big thank you to Mohamoud for letting Ring side support any Unicode char in any language!

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