|
Bugzilla – Full Text Bug Listing |
| Summary: | Proper access of <any> value from maps and lists undocumented, including no docs for YCP function "is()" | ||
|---|---|---|---|
| Product: | [openSUSE] openSUSE 11.0 | Reporter: | Olaf Dabrunz <odabrunz> |
| Component: | YaST2 | Assignee: | Martin Vidner <mvidner> |
| Status: | RESOLVED FIXED | QA Contact: | Jiri Srain <jsrain> |
| Severity: | Normal | ||
| Priority: | P5 - None | ||
| Version: | Factory | ||
| Target Milestone: | --- | ||
| Hardware: | Other | ||
| OS: | openSUSE 10.2 | ||
| Whiteboard: | |||
| Found By: | Development | Services Priority: | |
| Business Priority: | Blocker: | --- | |
| Marketing QA Status: | --- | IT Deployment: | --- |
Another reason to document this is that even seasoned YaST2-programmers seem to get this wrong sometimes. I am currently fixing a bug that was caused by such code. It would be helpful to have a reference for "some common programming situations and how to express yourself in YCP". is() is an YCP built-in, it should be well documented. Martin? Technically "is" is a keyword, so that's why it is missing from the list of built-ins. But of course that is a lame excuse. Its docs is here in the type system chapter: http://forgeftp.novell.com/yast/doc/SL10.2/tdg/id_ycp_types.html is() is documented now. Added your excellent code example to a new Wiki page http://en.opensuse.org/YaST/Development/Tricks |
There are many places where the is() function (e.g.: "is(WFM::Args(0), string)") is used, but I was unable to find the documentation. This function is needed whenever a value of type "any" is retrieved from a map or list, to use a proper default value. E.g., if the <any> values in my_map can contain <string>s or <integer>s: map<string,any> my_map = ...; sformat("%1", is(my_map[this]:nil, string) ? my_map[this]:"" : ( my_map[this]:nil == nil ? "" : my_map[this]:nil ) ); Most other approaches give error messages or unwanted behaviour as follows: my_map[this] = 123; sformat("%1", my_map[this]:"") -> Can't convert value '123' to type 'string' my_map[this] = "testing"; sformat("%1", my_map[this]:0) -> Can't convert value '"testing"' to type 'const integer' my_map[this] = nil; sformat("%1", my_map[this]:nil) -> no error, but output is 'nil' (and I want the empty string '') The only working alternative that does not need the "is()" function is this: sformat("%1", my_map[this]:nil == nil ? "" : my_map[this]:nil) I believe this is a standard situation and as such both alternatives should be documented. I could not find anything here: http://forgeftp.novell.com/yast/doc/SL10.2/tdg/Book-YaSTReference.html