[Omake] Annoying spaces in sequence-to-string conversion

Jason Hickey jyh at cs.caltech.edu
Wed Sep 20 14:00:09 PDT 2006


Hi David,

This has to do with the interpretation of arrays (the "addprefix" 
function always returns an array).  On the command line, array elements 
are always separated from the text around them.  This is actually by design.

osh> X[] =
    foo
osh> echo A$(X)B
A foo B

However, if you really want a string, you can use the $"..." construction.

osh> echo $"A$(X)B"
AfooB

It is very likely that you want to use $"..." instead of $(string ...), 
so here is how I might write your code.

mod = $(addprefix MOD:,test)
XX = $"""MODNAME="$(mod)"$(EMPTY)"""

I realize the $(EMPTY) is artificial; it is just there to get the right 
string terminator.  You could also do this,

XX = $"""MODNAME="$(mod)"\
"""

Jason

David Kågedal wrote:
> This is a distilled testcase from one of my OMakefiles:
> 
>     mod = $(addprefix MOD:,test)
>     println(mod = >>$(mod)<<)
>     XX = $(string MODNAME=\"$(mod)\")
>     YY = $(string MODNAME=\"$(string $(mod))\")
>     println(XX = >>$(XX)<<)
>     println(YY = >>$(YY)<<)
> 
> The output looks like this:
> 
>     mod = >>MOD:test<<
>     XX = >>MODNAME=" MOD:test "<<
>     YY = >>MODNAME="MOD:test"<<
> 
> As you can see, there are two spaces added to the XX case which seem
> rather surprising (and annoying) to me.




-- 
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