[yast-devel] YCP return bug?
Hi all, Could someone tell me whether this is a bug in YCP or if I am misunderstanding the documentation, it is certainly counter-intuitive. The documentation (http://forgeftp.novell.com//yast/doc/SL10.2/tdg/id_ycp_return.html) states: The return statement immediately leaves the current function or a current top level block (that contains it) and optionally assigns a return_value to this block. If blocks are nested, i.e. if the current block is contained in another block, the return statement leaves all nested blocks and defines the value of the outermost block. Therefore I would expect the following programme to print "One" "Two" "Three". However, it actually prints "One" "One" "Three". { string One() { return "One"; } string Two() { string value = "One"; foreach(string str, ["Two"], { return str; }); return value; } string Three() { string value = "One"; foreach(string str, ["Three"], { value = str; }); return value; } y2milestone(One()); y2milestone(Two()); y2milestone(Three()); } _ Benjamin Weber -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Benji Weber wrote:
Hi all, ... Therefore I would expect the following programme to print "One" "Two" "Three". However, it actually prints "One" "One" "Three".
string Two() { string value = "One"; foreach(string str, ["Two"], { return str; }); return value; }
"return" in "foreach" means that the interpreter skips to another loop of the "foreach", eventually finishes the "foreach" if it is the last one. You might want to modify your code this way :) --- cut --- string Two() { string value = "One"; foreach(string str, ["Two"], { value = str; }); return value; } --- cut --- http://forgeftp.novell.com/yast/doc/SL10.2/tdg/YCPBuiltinList_foreach.html According to the link mentioned above, "return" in "foreach" should return the last value value from "foreach". --- cut --- integer aaa_foreach = foreach (integer v, [1,2,3], { return v + 10; }); Then: aaa_foreach == 13 --- cut --- Lukas -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Mon, Jun 11, 2007 at 08:56:22PM +0200, Lukas Ocilka wrote:
http://forgeftp.novell.com/yast/doc/SL10.2/tdg/YCPBuiltinList_foreach.html
According to the link mentioned above, "return" in "foreach" should return the last value value from "foreach".
For the iterating builtins like foreach, filter, maplist, and others, "return" only affects the iterating block. But that means that we should fix the docs for "return" to mention it. On Mon, Jun 11, 2007 at 07:19:17PM +0100, Benji Weber wrote:
The documentation (http://forgeftp.novell.com//yast/doc/SL10.2/tdg/id_ycp_return.html) states:
The return statement immediately leaves the current function or a current top level block (that contains it) and optionally assigns a return_value to this block. If blocks are nested, i.e. if the current block is contained in another block, the return statement leaves all nested blocks and defines the value of the outermost block.
Well the next paragraph in fact does mention it: "However, if a block is used in an expression other than a block, and that expression is contained in an outer block, the return statement of the inner block won't leave the outer block but define the value of the inner block. This behavior is a as one would expect. For example in the iteration builtins in Section 8.16, “Applying Expressions To Lists And Maps”," Benji perhaps you can suggest better wording to make the point easier to understand. -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Martin Vidner wrote:
The return statement immediately leaves the current function or a current top level block (that contains it) and optionally assigns a return_value to this block. If blocks are nested, i.e. if the current block is contained in another block, the return statement leaves all nested blocks and defines the value of the outermost block.
Well the next paragraph in fact does mention it:
"However, if a block is used in an expression other than a block, and that expression is contained in an outer block, the return statement of the inner block won't leave the outer block but define the value of the inner block. This behavior is a as one would expect. For example in the iteration builtins in Section 8.16, “Applying Expressions To Lists And Maps”,"
Benji perhaps you can suggest better wording to make the point easier to understand.
I guess, we could write more examples into the current documentation and/or write a chapter about "Standard building blocks" or something similar... Maybe we could "learn" how to document it from another documentation of another language...? -- Lukas Ocilka, YaST Developer (xn--luk-gla45d) ----------------------------------------------------------------- SUSE LINUX, s. r. o., Lihovarska 1060/12, Praha 9, Czech Republic
On Tuesday 12 June 2007 11:08, Lukas Ocilka wrote:
I guess, we could write more examples into the current documentation and/or write a chapter about "Standard building blocks" or something similar...
Maybe we could "learn" how to document it from another documentation of another language...?
Actually, IMHO we need two kinds of documentation: (1) Reference - concise, yet complete. But all by all means (unlike most man pages) with examples for the most common use cases. (2) Tutorial - explanatory, not necessarily covering all aspects, concentrating on didactics, with pointers to the reference. AFAICS we have only a subset of (1) and beginnings of (2). CU -- Stefan Hundhammer <sh@suse.de> Penguin by conviction. YaST2 Development SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Nürnberg, Germany -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Tuesday 12 June 2007 12:02, Stefan Hundhammer wrote:
Actually, IMHO we need two kinds of documentation:
(1) Reference - concise, yet complete. But all by all means (unlike most man pages) with examples for the most common use cases.
(2) Tutorial - explanatory, not necessarily covering all aspects, concentrating on didactics, with pointers to the reference.
AFAICS we have only a subset of (1) and beginnings of (2).
Actually I find the tutorial part (http://forgeftp.novell.com/yast/doc/SL10.2/tutorials/index.html) quite comprehensive. Maybe new YaST developers could comment if it was helpful for them while learning YCP.
Stefan Hundhammer <sh@suse.de> Penguin by conviction.
Jiri -- Jiri Suchomel SUSE LINUX, s.r.o. e-mail: jsuchome@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Praha 9, Czech Republic http://www.suse.cz -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Tuesday 12 June 2007 12:36, Jiří Suchomel wrote:
Actually I find the tutorial part (http://forgeftp.novell.com/yast/doc/SL10.2/tutorials/index.html) quite comprehensive.
It sure is comprehensive, but it has a different approach: How to write YaST2 modules with all the framework and infrastructure. It is not, however, a tutorial for YCP. It dumps you straight into a really complex framework and an equally complex development environment. For those who have already mastered YCP as a programming language and some of the basic tools (UI, SCR), it is a really good tutorial how to apply that basic knowledge by writing an all-bells-and-whistles YaST2 module. What I miss are the more basic tutorials, in particular for YCP and for SCR. Or do we have any and I just don't know them? (Which might very well be the case). CU -- Stefan Hundhammer <sh@suse.de> Penguin by conviction. YaST2 Development SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Nürnberg, Germany -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Stefan Hundhammer wrote:
Actually, IMHO we need two kinds of documentation:
(1) Reference - concise, yet complete. But all by all means (unlike most man pages) with examples for the most common use cases.
(2) Tutorial - explanatory, not necessarily covering all aspects, concentrating on didactics, with pointers to the reference.
AFAICS we have only a subset of (1) and beginnings of (2).
Frankly, I was thinking about asking someone (all) to write some tutorial but I had decided not to do it yet :) It seems Stefan has the same idea which is great :) So, if someone wants to help us with writing a tutorial or write his/her own, please, go on. Also we'd like to know from the others for what they would like to have a tutorial... See this link: http://forgeftp.novell.com/yast/doc/SL10.2/tutorials/index.html Thanks & Bye Lukas -- Lukas Ocilka, YaST Developer (xn--luk-gla45d) ----------------------------------------------------------------- SUSE LINUX, s. r. o., Lihovarska 1060/12, Praha 9, Czech Republic
participants (5)
-
Benji Weber
-
Jiří Suchomel
-
Lukas Ocilka
-
Martin Vidner
-
Stefan Hundhammer