List Commands Library for 50g
|
08-07-2017, 05:54 PM
(This post was last modified: 09-10-2017 02:21 PM by DavidM.)
Post: #55
|
|||
|
|||
RE: List Commands Library for 50g
After working on Joe's Odd-digit mini-challenge and becoming reacquainted with SREPL, it inspired me to create one final command for the List Extensions library: CHR+.
It processes a string by adding an offset to every character's ordinal value. An alternate form of the command allows you to limit the range of characters that are valid targets for applying the offset. Like SREPL, it is very fast. Here's the description from the library documentation: CHR+ (Offset String Character Values) Input 2: String of 0 or more characters 1: number (Offset) or list { LowerBound UpperBound Offset } Output 1: String with offset added to appropriate characters Alters the string in stack level 2 by adding the given offset to each character in the string. The integer part of the offset must be between -255 and 255 (inclusive). If the parameter in stack level 1 is a list, the offset will only be added if the original character is within the bounds specified by the first two elements (inclusive). The final character value will always be in the range 0-255. If the given offset would move the new character value out of that range, the final value is normalized via a MOD 256 operation. Note: CHR+ will allow the creation of null characters (CHR value 0) in a string. If this happens, you may not be able to edit the string with the calculator's built-in commands. If you wish to convert all null characters in a string to some other character, simply execute "{ 0 0 <CHR> } CHR+" with whatever replacement character code for <CHR> you wish to use. Examples: "0000000000" 1 CHR+ => "1111111111" "99999" -5 CHR+ => "44444" "99999" 251 CHR+ => "44444" "THIS IS THE TENTH (10TH) TEST!" { 65 90 32 } CHR+ => "this is the tenth (10th) test!" "Convert to UPPER case???" { 97 122 -32 } CHR+ => "CONVERT TO UPPER CASE???" As I was creating the above description, I couldn't help but think how easy it would be to add commands for remapping the 50g's characters between lower and upper case. So LCASE and UCASE were added as well. See the command descriptions for a detailed listing of the character mappings used (diacritics are included where appropriate). I appreciate everyone's patience with this. I've probably already worn out my welcome with these posts, and in an effort to draw this to a close I'm promoting this version to "Release Candidate" status. If you have any interest at all in the list/string processing features the library includes, please give it a try! Edit: The attachment has been deleted; see the first post in this thread for the latest version. ______________________________________________________________________________ Version 1.0.0 RC1 2017-08-07 - DOCOMB and DOPERM now accept a "choices" parameter of 0. - DOCOMB and DOPERM now accept an empty list, but only if the choices parameter is 0. - Added new commands: CHR+, LCASE, UCASE - Status change to 1.0.0 Release Candidate 1 ______________________________________________________________________________ COMMAND SUMMARY DOCOMB - feeds indicated combinations of a list to a user-supplied program DOPERM - feeds indicated permutations of a list to a user-supplied program LCLLT - collates a list of sublists LCNT - counts objects in a list LDDUP - removes duplicates from a list LDST - distributes list items into sublists (reciprocal of LCLLT) LEQ - checks list items to see if any do not match LGRP - replaces repeated elements with a single instance LHDTL - retrieves the first element in a list while leaving the rest on the stack LMRPT - repeats list contents as indicated by count LNDUP - creates a list by repeating an object as indicated by count LPOS - returns a list of all positions of an object in a list LPOSL - returns a list of all positions of an object in a list or its sublists LPROD - ΠLIST that also accepts lists with 0 or 1 element LRCL - recalls objects identified by variables in a list LREPL - replaces list elements with a substitute object as indicated LRLL - rolls the list (equivalent to 1 LROT) LRLLD - "roll down" the list (equivalent to -1 LROT) LROT - rotates list elements left or right as indicated by count LRPCT - list with LGRP elements and another list of the count of each element LSDIV - subdivides a list into <count> sublists LSEQ - creates a list of <count> integers as a sequence from 1..<count> LSEQR - creates a list of integers for the range specified LSHF - shuffles the contents of a list LSPLT - splits a list as indicated into two sublists LSUM - ΣLIST that also accepts lists with 0 or 1 element LSWP - swaps the positions of two list elements LXIL - explodes inner sublists into individual elements (non-recursive) LXILR - recursive version of LXIL CHR+ - Adds an offset to the CHR value of each character of a string LCASE - Converts upper case characters in a string to lower case UCASE - Converts lower case characters in a string to upper case RPTCHR - creates a string of repeated characters I→NL - converts an integer to a list of numbers NL→I - converts a list of numbers to an integer S→NL - converts a string to a list of numbers NL→S - converts a list of numbers to a string S→SL - converts a string to a list of characters SL→S - converts a list of characters to a string |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 15 Guest(s)