rchain / rchip-proposals

Where RChain improvement proposals can be submitted
Apache License 2.0
8 stars 5 forks source link

Add string functions #37

Open jimscarver opened 3 years ago

jimscarver commented 3 years ago

Introduction/Motivation/Abstract

develops expect standard string functions including converting other types toString()

Motivating Examples

Examples

Please check the ones we already have. This is a good first issue for someone.

Comparison Examples

I struggled to concatenate a number and a string ultimately discovering it is impossible in rholag. Nothing should be impossible in rholang.

Counter-Examples

Design

Counter-Examples

Drawbacks

Alternatives

References

jimscarver commented 3 years ago

We also need a simple String.match capability being considered in #14

dckc commented 3 years ago

... I struggled to concatenate a number and a string ultimately discovering it is impossible in rholag.

Are you quite sure about that, @jimscarver ? String interpolation works when I try it in the rholang playground:

new x in {
  x!("${n}${s}" %% {"n": 123, "s": "abc"})
}

Result

[
  "123abc"
]
jimscarver commented 3 years ago

There are many other string functions that are needed like case conversion, finding a substring, and matching patterns.

Regular expressions prove to be problematical due to recursion see https://github.com/rchain/rchip-proposals/issues/19 however filename "glob" pattern matching like [Ss]ubstring are not recursive and could be supported easily https://index.scala-lang.org/salva/scala-glob/scala-glob/0.0.3?

We can also support more types for existing functions easily like string.contains(substring). Any type that makes sense in a function should be supported. This could be done even by scala newbees