New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added builtin list::reverse for YCP list #3
Changes from 3 commits
6b8e9f7
c198614
d4b2878
a324bf6
66da55d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.23.3 | ||
2.23.4 |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1173,7 +1173,7 @@ l_swaplist (const YCPList &v, YCPInteger &i1, YCPInteger &i2){ | |||
/** | ||||
* @builtin list::swap | ||||
* @id list.swap | ||||
* @short Creates new list with swaped elemetns at offset i1 and i2. | ||||
* @short Creates new list with swaped elements at offset i1 and i2. | ||||
* @param list<flex1> v list | ||||
* @param integer i1 index of first element | ||||
* @param integer i2 index of second element | ||||
|
@@ -1218,6 +1218,32 @@ l_swaplist (const YCPList &v, YCPInteger &i1, YCPInteger &i2){ | |||
return ret; | ||||
} | ||||
|
||||
static YCPValue | ||||
l_reverselist (const YCPList &v){ | ||||
/** | ||||
* @builtin list::reverse | ||||
* @id list.reverse | ||||
* @short Creates new list with reversed order of elements. | ||||
* @param list<flex1> v list | ||||
* @return New list. Changed if offset is correct, otherwise return unchanged list | ||||
* | ||||
* @description | ||||
* Creates new list with reversed order of elements. Return nil if list is nil. | ||||
* | ||||
* @usage list::reverse ([0,1,2,3]) -> [3,2,1,0] | ||||
* @usage list::reverse ([]) -> [] | ||||
*/ | ||||
if (v.isNull ()) | ||||
{ | ||||
ycp2error ("Cannot reverse 'nil' list"); | ||||
return YCPNull (); | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it really problem? If so, then why continue with execution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reading documentation for you method I strongly don't see reason for such error log - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Wed, Jun 20, Josef Reidinger wrote:
This is first time I add an ycp builtin. I just copied code of another builtin and changed functionality Tschuess, Thomas FehrThomas Fehr, SuSE Linux Products GmbH, Maxfeldstr. 5, 90409 Nuernberg, Germany There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depend case by case like for add new element to nil list it is reasonable to have it here. |
||||
|
||||
YCPList ret = v; | ||||
ret->reverse(); | ||||
return ret; | ||||
} | ||||
|
||||
static YCPValue | ||||
l_tolist (const YCPValue &v) | ||||
{ | ||||
|
@@ -1289,6 +1315,7 @@ YCPBuiltinList::YCPBuiltinList () | |||
{ "reduce", "flex1 (variable <flex1>, variable <flex1>, const list <flex1>, const block <flex1>)", (void *)l_reduce1, DECL_LOOP|DECL_SYMBOL|DECL_FLEX, ETCf }, | ||||
{ "reduce", "flex1 (variable <flex1>, variable <flex2>, const flex1, const list <flex2>, const block <flex1>)", (void *)l_reduce2, DECL_LOOP|DECL_SYMBOL|DECL_FLEX, ETCf }, | ||||
{ "swap", "list <flex> (const list <flex>, const integer, const integer)", (void *)l_swaplist, DECL_FLEX, ETCf }, | ||||
{ "reverse", "list <flex> (const list <flex>)", (void *)l_reverselist, DECL_FLEX, ETCf }, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this line is a little magic for me, but from list of DECL_FLEX it looks like it should also accept nil so DECL_NIL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DeclFlags are declared at
I cannot quite parse your question, but anyway, the problem is that we haven't really agreed on whether nil is an "exception" or a processable value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that definition of DeclFlags, but I don't understand it completelly especially part with DECL_NIL. It looks bogus for me. Some methods doesn't have it and still it looks like ti accept nil paramter. |
||||
{ NULL, NULL, NULL, ETC } | ||||
}; | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Parsed: | ||
---------------------------------------------------------------------- | ||
list::reverse ([0, 1, 2, 3]) | ||
---------------------------------------------------------------------- | ||
Parsed: | ||
---------------------------------------------------------------------- | ||
list::reverse ([0]) | ||
---------------------------------------------------------------------- | ||
Parsed: | ||
---------------------------------------------------------------------- | ||
list::reverse ([]) | ||
---------------------------------------------------------------------- | ||
Parsed: | ||
---------------------------------------------------------------------- | ||
list::reverse (nil) | ||
---------------------------------------------------------------------- | ||
[Interpreter] tests/builtin/revlist.ycp:16 Argument (nil) to reverse(...) is nil |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
([3, 2, 1, 0]) | ||
([0]) | ||
([]) | ||
(nil) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# --------------------------------------------------------- | ||
# | ||
# Filename: revlist.ycp | ||
# | ||
# Purpose: test cases for YCP list::reverse builtin | ||
# | ||
# Creator: fehr@suse.de | ||
# | ||
# Maintainer: fehr@suse.de | ||
# | ||
# -------------------------------------------------------- | ||
|
||
(list::reverse([0,1,2,3])) | ||
(list::reverse([0])) | ||
(list::reverse([])) | ||
(list::reverse(nil)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the documentation right? I don't see such parameters