[Omake] How to pass an empty string to concat()?
Dmitry Bely
dmitry.bely at gmail.com
Sun Dec 2 01:00:20 PST 2007
On Dec 1, 2007 11:03 PM, Jason Hickey <jyh at cs.caltech.edu> wrote:
Jason,
Thanks for the explanation. It seems to be quite clear except
> When you wrote d=$''... the string literal was never terminated.
Why? What is the difference between $'' and $' ' (two single quotes in
both cases)? And how to leave osh if I happen to write an unterminated
string?
> 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
I found the similar way even without concat():
fslash(s) =
s = $(string $(s))
len = $(s.length)
i = $(int 0)
res =
while $(lt $(i), $(len))
c = $(s.nth $i)
if $(equal $(c), \\)
c = /
export
res = $(res)$(c)
i = $(add $(i), 1)
return $(res)
- Dmitry Bely
More information about the Omake
mailing list