[Omake] How to pass an empty string to concat()?

Jason Hickey jyh at cs.caltech.edu
Sat Dec 1 12:03:10 PST 2007


Hi Dmitry,

First the quoting issue.  You don't have to quote strings in OMake.   
The empty string has an empty definition.

    osh> empty=
    osh> concat($(empty), a b c)
    - : <data "abc"> : String

There is also a string EMPTY in the standard library.

Quotes are taken literally, they are part of the string.

    osh> println('Hello world')
    'Hello world'

In OMake-style quotes that start with a dollar, the delimiter count is  
significant, kind of like it is in Python.

    osh> println($'''This string contains a single ' and double ''  
quote''')
    This string contains a single ' and double '' quote

When you wrote d=$''... the string literal was never terminated.

---

For what you are trying to do, we have contemplated a sed-like string- 
substitution function, but have yet to implement it.

foreach doesn't iterate over strings.  Here is one way it could be  
written using a while-loop.

# "Forward-slash" name
fsname(s) =
     s = $"$s"    # Make sure the argument is a string
     len = $(s.length)
     i = 0
     text[] =
     while $(lt $i, $(len))
        c = $(s.nth $i)
        if $(equal $c, \\)
            c = /
            export
        text[] += $c
        i = $(add $i, 1)
     concat($(EMPTY), $(text))

println($(fsname c:\a\b\c))
# Prints c:/a/b/c

Jason


On Dec 1, 2007, at 9:34 AM, Dmitry Bely wrote:

> This just does not work:
>
> osh
> % d=''
> - : <string ''>
>       : String
> % println($(concat $(d),1 2 3))
> 1''2''3
> % d=$''
> % println($(concat $(d),1 2 3))
> %
> (even worse - here I cannot leave osh normally and can only kill it)
>
> Why I need it? I am trying to write a function that converts
> backslashes in the string to forward slashes, e.g.
> "c:\some\path" -> "c:/some/path"
>
> As foreach cannot be directly applied to string characters (right?) I
> am going to convert string to the sequence, transform it and then
> merge back into the string by concat(). Wrong approach?
>
> - Dmitry Bely
> _______________________________________________
> Omake mailing list
> Omake at metaprl.org
> https://lists.metaprl.org/mailman/listinfo/omake

--
Jason Hickey                  http://www.cs.caltech.edu/~jyh
Caltech Computer Science      Tel: 626-395-6568 FAX: 626-792-4257





More information about the Omake mailing list