Commit b3ce6b58 authored by Steven Ye's avatar Steven Ye Committed by Evan W. Patton

Implement list reverse block

This commit introduces a new block to list operations that reverses the
order of input list and outputs the result as new list.

Change-Id: If22a6641a2586ecc6586ead9ea046cc119a2a9fc
parent 294905fe
......@@ -349,6 +349,22 @@ Blockly.Blocks['lists_is_list'] = {
typeblock: [{ translatedName: Blockly.Msg.LANG_LISTS_IS_LIST_TITLE_IS_LIST }]
};
Blockly.Blocks['lists_reverse'] = {
// Reverse the list.
category : 'Lists',
helpUrl : Blockly.Msg.LANG_LISTS_REVERSE_HELPURL,
init : function() {
this.setColour(Blockly.LIST_CATEGORY_HUE);
this.setOutput(true, Blockly.Blocks.Utilities.YailTypeToBlocklyType("list",Blockly.Blocks.Utilities.OUTPUT));
this.appendValueInput('LIST')
.setCheck(Blockly.Blocks.Utilities.YailTypeToBlocklyType("list",Blockly.Blocks.Utilities.INPUT))
.appendField(Blockly.Msg.LANG_LISTS_REVERSE_TITLE_REVERSE)
.appendField(Blockly.Msg.LANG_LISTS_REVERSE_INPUT_LIST);
this.setTooltip(Blockly.Msg.LANG_LISTS_REVERSE_TOOLTIP);
},
typeblock: [{ translatedName: Blockly.LANG_LISTS_REVERSE_TITLE_REVERSE }]
}
Blockly.Blocks['lists_to_csv_row'] = {
// Make a csv row from list.
category : 'Lists',
......
......@@ -235,6 +235,19 @@ Blockly.Yail['lists_is_list'] = function() {
return [ code, Blockly.Yail.ORDER_ATOMIC ];
};
Blockly.Yail['lists_reverse'] = function() {
// Reverse the list.
var argument0 = Blockly.Yail.valueToCode(this, 'LIST', Blockly.Yail.ORDER_NONE) || Blockly.Yail.emptyListCode;
var code = Blockly.Yail.YAIL_CALL_YAIL_PRIMITIVE + "yail-list-reverse" + Blockly.Yail.YAIL_SPACER;
code = code + Blockly.Yail.YAIL_OPEN_COMBINATION + Blockly.Yail.YAIL_LIST_CONSTRUCTOR + Blockly.Yail.YAIL_SPACER;
code = code + argument0;
code = code + Blockly.Yail.YAIL_SPACER + Blockly.Yail.YAIL_CLOSE_COMBINATION;
code = code + Blockly.Yail.YAIL_SPACER + Blockly.Yail.YAIL_QUOTE + Blockly.Yail.YAIL_OPEN_COMBINATION;
code = code + "list" + Blockly.Yail.YAIL_CLOSE_COMBINATION + Blockly.Yail.YAIL_SPACER;
code = code + Blockly.Yail.YAIL_DOUBLE_QUOTE + "reverse list" + Blockly.Yail.YAIL_DOUBLE_QUOTE + Blockly.Yail.YAIL_CLOSE_COMBINATION;
return [ code, Blockly.Yail.ORDER_ATOMIC ];
};
Blockly.Yail['lists_to_csv_row'] = function() {
// Make a csv row from list.
var argument0 = Blockly.Yail.valueToCode(this, 'LIST', Blockly.Yail.ORDER_NONE) || Blockly.Yail.emptyListCode;
......
......@@ -841,6 +841,11 @@ Blockly.Msg.en.switch_language_to_english = {
Blockly.Msg.LANG_LISTS_IS_LIST_INPUT_THING = 'thing';
Blockly.Msg.LANG_LISTS_IS_LIST_TOOLTIP = 'Tests if something is a list.';
Blockly.Msg.LANG_LISTS_REVERSE_HELPURL = '/reference/blocks/lists.html#reverse';
Blockly.Msg.LANG_LISTS_REVERSE_TITLE_REVERSE = 'reverse list';
Blockly.Msg.LANG_LISTS_REVERSE_INPUT_LIST = 'list';
Blockly.Msg.LANG_LISTS_REVERSE_TOOLTIP = 'Reverses the order of input list and returns it as a new list.';
Blockly.Msg.LANG_LISTS_TO_CSV_ROW_HELPURL = '/reference/blocks/lists.html#listtocsvrow';
Blockly.Msg.LANG_LISTS_TO_CSV_ROW_TITLE_TO_CSV = 'list to csv row';
Blockly.Msg.LANG_LISTS_TO_CSV_ROW_INPUT_LIST = 'list';
......
......@@ -1774,7 +1774,10 @@ Blockly.Versioning.AllUpgradeMaps =
22: "noUpgrade",
// AI2: Added Bitwise Blocks
23: "noUpgrade"
23: "noUpgrade",
// AI2: In BLOCKS_LANGUAGE_VERSION 24, added List Reverse Block
24: "noUpgrade"
}, // End Language upgraders
......
......@@ -1886,6 +1886,7 @@ Block name Kawa implementation
- remove list item (yail-list-remove-item! yail-list index)
- length of list (yail-list-length yail-list)
- copy list (yail-list-copy list)
- reverse list (yail-list-reverse list)
- list to csv row (yail-list-to-csv-row list)
- list to csv table (yail-list-to-csv-table list)
- list from csv row (yail-list-from-csv-row text)
......@@ -1980,6 +1981,13 @@ list, use the make-yail-list constructor with no arguments.
((not (pair? yl)) yl)
(else (YailList:makeList (map yail-list-copy (yail-list-contents yl))))))
;;; does a shallow copy of the yail list yl with its order reversed.
;;; yl should be a YailList
(define (yail-list-reverse yl)
(if (not (yail-list? yl))
(signal-runtime-error "Argument value to \"reverse list\" must be a list" "Expecting list")
(insert-yail-list-header (reverse (yail-list-contents yl)))))
;;; converts a yail list to a CSV-formatted table and returns the text.
;;; yl should be a YailList, each element of which is a YailList as well.
;;; inner list elements are sanitized
......
......@@ -444,8 +444,10 @@ public class YaVersion {
// - NOTIFIER_COMPONENT_VERSION was incremented to 6
// For YOUNG_ANDROID_VERSION 178:
// - CLOCK_COMPONENT_VERSION was incremented to 4
// For YOUNG_ANDROID_VERISON 179:
// - BLOCKS_LANGUAGE_VERSION was incremented to 24
public static final int YOUNG_ANDROID_VERSION = 177;
public static final int YOUNG_ANDROID_VERSION = 179;
// ............................... Blocks Language Version Number ...............................
......@@ -511,8 +513,10 @@ public class YaVersion {
// - Break block was added.
// For BLOCKS_LANGUAGE_VERSION 23:
// - Bitwise and, ior, and xor blocks were added.
// For BLOCKS_LANGUAGE_VERSION 24:
// - List reverse block was added.
public static final int BLOCKS_LANGUAGE_VERSION = 23;
public static final int BLOCKS_LANGUAGE_VERSION = 24;
// ................................. Component Version Numbers ..................................
......
......@@ -220,6 +220,7 @@ jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"","ajaxPageState":
<li><a href="#append">append to list</a></li>
<li><a href="#copy">copy list</a></li>
<li><a href="#isalist">is a list?</a></li>
<li><a href="#reverse">reverse list</a></li>
<li><a href="#listtocsvrow">list to csv row</a></li>
<li><a href="#listtocsvtable">list to csv table</a></li>
<li><a href="#listfromcsvrow">list from csv row</a></li>
......@@ -274,6 +275,9 @@ the members of the sublists are not themselves members of the list. For example,
<h3 id="isalist">is a list?</h3>
<p><img src="images/lists/isalist.png" /></p>
<p>If <em>thing</em> is a list, returns true; otherwise, returns false.</p>
<h3 id="reverse">reverse list</h3>
<p><img src="images/lists/reverse.png" /></p>
<p>Reverses the order of input list and returns it as a new list.</p>
<h3 id="listtocsvrow">list to csv row</h3>
<p><img src="images/lists/listtocsvrow.png" /></p>
<p>Interprets the list as a row of a table and returns a CSV (comma-separated value) text representing the row.<br />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment