Post Reply 
(50g) String inside string manipulation, UserRPL
10-15-2016, 01:56 PM (This post was last modified: 10-16-2016 10:31 AM by Vtile.)
Post: #1
(50g) String inside string manipulation, UserRPL
I have spend too many hours to find a way to make string inside to the string in UserRPL program, which did seem impossible, since ie. all string manipulation commands refuges to create such (because of the way stack editors etc. works), but eventually I did find a way to do it. This allows me finally .. after tens of hours of trying to make a parser for a choose command. *happy*

For someone that might given up hope, here it is (thx. Gerald H. for giving more elegant solutions).

Code:
34 CHR "Your existing string to be wrapped in extra quotation marks" 34 CHR + +

First we need to create a empty string, to do so press:
[RShift] [*] [Enter]
There is now empty string object in stack, next press
[DOWNARRY]
To enter editor, press following:
[RSHIFT] [*] [DEL] [ENTER]

Now in stack we have object """
store in to variable 'FOOLSTR'


Now you can also make a program that make a string of strings and other more "synthetic" programs.

Hopefully this is usefull.
Find all posts by this user
Quote this message in a reply
10-15-2016, 06:48 PM
Post: #2
RE: (50g) String inside string manipulation, UserRPL
Try

C$ 4 """"

& observe the result.
Find all posts by this user
Quote this message in a reply
10-15-2016, 08:03 PM (This post was last modified: 10-15-2016 08:15 PM by Vtile.)
Post: #3
RE: (50g) String inside string manipulation, UserRPL
(10-15-2016 06:48 PM)Gerald H Wrote:  Try

C$ 4 """"

& observe the result.
Can you provide more information (or link and page to document ) of that mnemonic and the purpose of those components, I'm too old and grumpy to be a happy detective.

What I tested it in CMD line it do indeed create string with random success inside string with some text inside.. Can it be programmed dynamically or only static way.
Find all posts by this user
Quote this message in a reply
10-16-2016, 05:43 AM (This post was last modified: 10-16-2016 05:44 AM by Gerald H.)
Post: #4
RE: (50g) String inside string manipulation, UserRPL
(10-15-2016 06:48 PM)Gerald H Wrote:  Try

C$ 4 """"

& observe the result.

Sorry simpler(?) is

CHR 34 CHR 34 + CHR 34 + CHR 34 +
Find all posts by this user
Quote this message in a reply
10-16-2016, 05:46 AM
Post: #5
RE: (50g) String inside string manipulation, UserRPL
(10-15-2016 08:03 PM)Vtile Wrote:  
(10-15-2016 06:48 PM)Gerald H Wrote:  Try

C$ 4 """"

& observe the result.
Can you provide more information (or link and page to document ) of that mnemonic and the purpose of those components, I'm too old and grumpy to be a happy detective.

What I tested it in CMD line it do indeed create string with random success inside string with some text inside.. Can it be programmed dynamically or only static way.

Can't see why success is "random". "dynamically or static" - a self-modifying programme?
Find all posts by this user
Quote this message in a reply
10-16-2016, 05:49 AM
Post: #6
RE: (50g) String inside string manipulation, UserRPL
The command

C$ n

n a positive integer takes the next n characters & produces an n length character string.
Find all posts by this user
Quote this message in a reply
10-16-2016, 05:51 AM
Post: #7
RE: (50g) String inside string manipulation, UserRPL
The programme here

http://www.hpcalc.org/details/6741

shows a nice use of C$.
Find all posts by this user
Quote this message in a reply
10-16-2016, 10:21 AM (This post was last modified: 10-16-2016 10:34 AM by Vtile.)
Post: #8
RE: (50g) String inside string manipulation, UserRPL
(10-16-2016 05:49 AM)Gerald H Wrote:  The command

C$ n

n a positive integer takes the next n characters & produces an n length character string.
Much helpfull, now I get the snippet.

(10-16-2016 05:51 AM)Gerald H Wrote:  The programme here

http://www.hpcalc.org/details/6741

shows a nice use of C$.
Hah, nice program I actually meant also to do something partially similar with this string manipulation, related to userkey assigments. PS. Which now when I look at it still effects in sense that I have taken too complex aproach for creating a choose box. Obviously in case I show below the "phonebook" example is enough, since wrapping to program object is not needed... Oh, well.
(10-16-2016 05:46 AM)Gerald H Wrote:  
(10-15-2016 08:03 PM)Vtile Wrote:  Can you provide more information (or link and page to document ) of that mnemonic and the purpose of those components, I'm too old and grumpy to be a happy detective.

What I tested it in CMD line it do indeed create string with random success inside string with some text inside.. Can it be programmed dynamically or only static way.

Can't see why success is "random". "dynamically or static" - a self-modifying programme?
Well the randomness did come out since I didn't get the behaviour impact of the number 4 in your code snippet (calculating wrong the charcount of the outcome, while guessing that the purpose is something length related). While now seeing your second post, it is clear where did the "randomness" come from. It did come from my keyboard trying with different strings after command C$ n.

Yes. This is handy command and will easy up the creation of the "FOOSTR" variable. Its nature still seems to be somewhat more static than dynamic. Since it doesn't take argument before itself, but instead after itself. For more dynamic use in extreme with morphing code, you still need to use it more like in example in the first post.

The problem where this solution doesn't fit directy (as doesn't the Lib256 nor ->STR etc. UserRPL commands) is when I do need to create a program that constructs (parses) the choose window from datafile based on certain options. In my case I use source from standards IEC-60364 and CENELEC HD 60364 with "set to the stone" minimal values of certain electrical installation properties. The data is a multicolumn and -row table and I do not want to repeat and split it in different IFs or CASEs inside the main program. Instead I do create dynamically (these commands will be a small library) a sub-program(s) containing the data parsed from one big datafile containing whole table and one description in list of lists format. This provides two advances first is the substantial memory saving and another is ease of update. I only need to do minimal changes if the table values change over time (which they do at times). PS. Again this is too complex aproach for this case, I just need to put the parts to the stack, no need to create sub-program. The morphing userkey program that uses choosebox is still hounting back of my head.

I also now noticed the char example. Which I also tried before this thread, but reason or another didn't get "right results", maybe I did jump to different idea middle of testing, who knows. Must be the easiest way of creating the single """ object to be appented to existing string in any use that needs such thing.

Thank you for your input, it actually sorted out many things. I must edit my first post partially, since the use of << 34 CHR >> is the most elegant solution to use as FOOLSTR in 1st approach.
Find all posts by this user
Quote this message in a reply
10-17-2016, 06:28 PM
Post: #9
RE: (50g) String inside string manipulation, UserRPL
*meh* still doesn't work, with more complex objects the stack will parse it wrong. I'll give up.

For simple things it works
Find all posts by this user
Quote this message in a reply
10-17-2016, 07:07 PM
Post: #10
RE: (50g) String inside string manipulation, UserRPL
(10-17-2016 06:28 PM)Vtile Wrote:  *meh* still doesn't work, with more complex objects the stack will parse it wrong. I'll give up.

For simple things it works

Vtile, I'm still having difficulty understanding exactly what you're trying to accomplish.

Can you give a couple examples of source strings and how they should look after manipulation? It's not clear to me how this relates to your "choose window" comments, or how parsing is part of this mix. And is the context for this meant to be the results of a running program, or are you only asking about creating strings while in the editing process? I'm confused. Smile
Find all posts by this user
Quote this message in a reply
10-17-2016, 08:49 PM (This post was last modified: 10-17-2016 08:58 PM by Vtile.)
Post: #11
RE: (50g) String inside string manipulation, UserRPL
(10-17-2016 07:07 PM)DavidM Wrote:  
(10-17-2016 06:28 PM)Vtile Wrote:  *meh* still doesn't work, with more complex objects the stack will parse it wrong. I'll give up.

For simple things it works

Vtile, I'm still having difficulty understanding exactly what you're trying to accomplish.

Can you give a couple examples of source strings and how they should look after manipulation? It's not clear to me how this relates to your "choose window" comments, or how parsing is part of this mix. And is the context for this meant to be the results of a running program, or are you only asking about creating strings while in the editing process? I'm confused. Smile
I think I'm the most confused one here, haha. I need a few evening to test all things more, but here is a little story.

The confusion actually comes from the reason a few months ago I had an idea of creating a usrkey program that is assigned to one physical key on calculator. The grand idea were to create a choose box/list that have all the type related normal commands in it (Lin256 included) for easy stack manipulation etc. This is really simple one and can be just be written normally and attached to the desired key.

However in this form it wouldn't be too great, since it would be slow to use if the desired command would be middle of the list. So my though were that the first two options on the list would be two last chosen commands for fast use as many times you use a few times the same command, ie "to tag", "to list" or "Real to Int". (Note. This could be archieved by using variable in ram? or ie. home directory, but lets forget this for now) I did want it use itself as a variable to store the two last used commands so the solution would been that it needs to "recompile/parse" itself and change the two first values of the list of lists that is used as argument for CHOOSE command. Then return the updated program code to stack and attach it again to the physical key. (so inefficient, but cool) Then I started the journey fiddling with all sorts of type "hacks" trying to convert a string to program (with the << >> as Lib256 PRG/-> seems not to attach those) etc. etc. one major hick up were how this system handles the string when type conversions or editors etc. are used. Now I'm facing problems (I think, or I just made some mistake.. Most propably my brains are just melting Tongue ) in some of my test snippets that it doesn't still like "string of string" object at cases with some type conversion methods it explodes it to pieces as it finds first two quotation marks and refuges to believe that the second one is starting glypth for 2nd order string, not ending glypth. So it slices a bread while it should peel the onion (as is done with ie. lists with removing layer by layer the depth of list of lists). So yeah, I'm still OCD to this Quine (wikipedia is golden) style problem. I have a good feeling of list object and PRG/-> command atm., but propably it is a dead end after all. Smile

The string handling is just so annoying and the fact that there is no command (as far as I'm aware, which takes object and adds the program start and end glyphs in it.). I'm pretty sure that these problems would be a piece of cake with SysRPL with full control, but but.

I'm not sure about C$ n XXX maybe I'm not just figured out how to append it with .. wait a bit .. yep didn't work. SIZE needs a string(or integer) as argument, and OBJ/-> gets a hickup with ie. Global Name inside the X variable.
Code:
/<< DUP  SIZE /-> X Y /<< "C$ " Y " " + X + + OBJ/-> />> />>

.. What I mentioned a program that uses a table from IEC standard can be archieved without any string in string style of hack, my brains were just so stuckt in that above usrkey problem that I started to make this second one way too complicated. Normal UserRPL is enough for this case what I have scetched it to the paper so far.

I'm swimming in too deep water here, I'm afraid. Big Grin
Find all posts by this user
Quote this message in a reply
10-18-2016, 01:41 AM
Post: #12
RE: (50g) String inside string manipulation, UserRPL
Why not simply store the list of items in a global variable, then populate the required parameters from that variable? Instead of hard-coding the list of items into the key assignment, you would simply RCL that list into place before calling CHOOSE. That would keep you from having to update the key assignment program every time, since its contents would never change. You'd still have to change the global variable to represent the newest items, though. But since the program itself wouldn't change, the key assignment stays intact.

As for making a program out of strings, you can still add the opening and closing brackets with the CHR methodology mentioned previously, or simply enclosing those characters in double quotes:

Code:
« "«" 34 CHR "Vtile" 34 CHR "»" + + + + STR→ »
or
Code:
« 171 CHR 34 CHR "Vtile" 34 CHR 187 CHR + + + + STR→ »

It's always possible that I'm still misunderstanding the issues, though. Smile
Find all posts by this user
Quote this message in a reply
10-18-2016, 03:08 AM
Post: #13
RE: (50g) String inside string manipulation, UserRPL
Here's another alternative for building a program containing a string. It shows yet another way to put the double quote in where needed: by "escaping" it. This is done by prefacing the " character with a \, which allows you to keep the following " from being interpreted as the closing quote. \ is entered as alpha-rightshift-5. It also uses the STREAM command to concatenate all the pieces together, which is a bit cleaner (and keeps you from having to count all the pieces):

Code:
«
   { "«" "\"" "Vtile" "\"" "»" } « + » STREAM
   STR→
»
Find all posts by this user
Quote this message in a reply
10-18-2016, 07:43 AM (This post was last modified: 10-18-2016 07:47 AM by Vtile.)
Post: #14
RE: (50g) String inside string manipulation, UserRPL
(10-18-2016 01:41 AM)DavidM Wrote:  Why not simply store the list of items in a global variable, then populate the required parameters from that variable? Instead of hard-coding the list of items into the key assignment, you would simply RCL that list into place before calling CHOOSE. That would keep you from having to update the key assignment program every time, since its contents would never change. You'd still have to change the global variable to represent the newest items, though. But since the program itself wouldn't change, the key assignment stays intact.
Yep, it is the best solution to use global variable for data and then update it instead of the program itself and I have one of those in use. Even though only storing the object number of previously selected object so the default selection is always the last used one.

Mmmh. I were so sure I finally nailed the string part when creating this thread, but last evening I though there is problem with certain more complex strings that contains another program elements, propably it were uneven number of quotation marks that coused the issue. I'm using not so good testing method, doing it only in calculator, so I need to start to store the snippets before using them to get more precise results and possibility to analyse the outcome better.

(10-18-2016 01:41 AM)DavidM Wrote:  As for making a program out of strings, you can still add the opening and closing brackets with the CHR methodology mentioned previously, or simply enclosing those characters in double quotes:

Code:
« "«" 34 CHR "Vtile" 34 CHR "»" + + + + STR→ »
or
Code:
« 171 CHR 34 CHR "Vtile" 34 CHR 187 CHR + + + + STR→ »

It's always possible that I'm still misunderstanding the issues, though. Smile
I ended up to similar solution and found following small program to be handy to convert a string to a program object. It doesn't preserve the quotation marks, since at that point I haven't noticed the "34 CHR" instruction for a reason or another.
Code:
/<< 
"/>>" + "/<<" SWAP + OBJ/-> 
/>>

I test (the supposed problem) more this evening to see if it were my typo or does the program and system really behave as I think atm. it behaves.
Find all posts by this user
Quote this message in a reply
10-18-2016, 07:53 AM (This post was last modified: 10-18-2016 07:57 AM by Vtile.)
Post: #15
RE: (50g) String inside string manipulation, UserRPL
(10-18-2016 03:08 AM)DavidM Wrote:  Here's another alternative for building a program containing a string. It shows yet another way to put the double quote in where needed: by "escaping" it. This is done by prefacing the " character with a \, which allows you to keep the following " from being interpreted as the closing quote. \ is entered as alpha-rightshift-5. It also uses the STREAM command to concatenate all the pieces together, which is a bit cleaner (and keeps you from having to count all the pieces):

Code:
«
   { "«" "\"" "Vtile" "\"" "»" } « + » STREAM
   STR→
»
Oh, that is the way you need to type the backslash when using the editor.. I spend like an hour trying last evening, after I noticed these "escaped" characters from the C$ n XXX results. ... A
proper programming degree would be handy to have to know what to google for. Big Grin
Find all posts by this user
Quote this message in a reply
10-18-2016, 07:32 PM (This post was last modified: 10-18-2016 09:33 PM by Vtile.)
Post: #16
RE: (50g) String inside string manipulation, UserRPL
Now tested more, I can not make any errors or odd behaviour that would be really odd. I'm using the escaped character and not the "34 CHR" -method this time so it propably makes difference. That said look at the first two snippets, they produce cryptic outcome without system giving any type of warning.

The results have "right" amount of quotation marks and other symbols as they exist on editor, in case of string objects the outermost quotation marks are also written snippets below.

So yep, I think I now can compose/parse new programs programmatically from existing program parts, if I want to. Wishful thinking? Edit. Yes and no... Program that contains escape character, will not convert to string and back to program nicely, I need to cook up some analytics. ... Yep, got it right my bad Need fresh eyes. ugh. Not work when you convert program to string (by replacing the program symbols with quotation marks) and adding one extra pair around both and the adding two programs together, quotation mismatch and kaboom. Tongue

Code:

"ABC"
« " \\\" " + » 
------------------[EVAL]
"ABC \" "
« "»" + "«" SWAP + STR→ »    @@ Convert str to prg
==================[EVAL]
"ABC \ " »" »            @@ Cryptic


Code:

"ABC"
« " \\\" " + » 
------------------[EVAL]
"ABC \" "
"ABC"
+
------------------[EVAL]
"ABC \" ABC"
« "»" + "«" SWAP + STR→ »     @@ Convert str to prg
==================[EVAL]
« "ABC \ " ABC»" »        @@ Cryptic


Code:

"ABC"
« " \\\" " + » 
------------------[EVAL]
"ABC \" "
"ABC"
+
------------------[EVAL]
"ABC \" ABC"
« → X « "\"" X "\"" + + »»    @@ Increase str depth
------------------[EVAL]
""ABC \" ABC""
« "»" + "«" SWAP + STR→ »    @@ Convert str to prg
==================[EVAL]
« "ABC \" ABC" »        @@ OK


Code:

"ABC "\"" +"
« "»" + "«" SWAP + STR→ »    @@ Convert str to prg
------------------[EVAL]
« ABC "\"" + »
==================[EVAL]
"ABC""                @@ OK


Code:

{ "ABC" "\"" }
→STR                @@ Converts lst to str. Note: Needs typecheck in program since "\"" + method doesn't work.
------------------[EVAL]
"{ "ABC" "\"" }"
« "»" + "«" SWAP + STR→ »    @@ Converts str to prg
==================[EVAL]
« { "ABC" "\"" } »        @@ OK


Code:

{{{ "ABC" "\"" }}}
→STR                @@ Converts lst to str. 
------------------[EVAL]
"{ { { "ABC" "\"" } } }"
« "»" + "«" SWAP + STR→ »    @@ Converts str to prg
==================[EVAL]
«{ { { "ABC" "\"" } } }»    @@ OK


Code:

""A""B""C""
« "»" + "«" SWAP + STR→ »    @@ Converts str to prg
==================[EVAL]
« "A" "B" "C" »            @@ OK


Code:

""A"B"C""
STR→                 @@ Converts str to objects
==================[EVAL]
"A"
'B'
"C"                @@ OK


Code:

"[ A 1 ]"
« "»" + "«" SWAP + STR→ »    @@ Converts str to prg
==================[EVAL]
"«[ A 1 ]»"            @@ STR→ Invalid syntax, OK!
Find all posts by this user
Quote this message in a reply
10-18-2016, 09:08 PM (This post was last modified: 10-18-2016 09:15 PM by Claudio L..)
Post: #17
RE: (50g) String inside string manipulation, UserRPL
(10-17-2016 08:49 PM)Vtile Wrote:  ...
Then I started the journey fiddling with all sorts of type "hacks" trying to convert a string to program (with the << >> as Lib256 PRG/-> seems not to attach those)
...

Perhaps not exactly what you are looking for, but you can use lists of objects, then convert to a program using the ->PRG command from Lib 256.

{ 1 } ->PRG ====> :: %1 ;

The program is a sysRPL secondary, so in the stack doesn't look complete << >>, but EVAL will work fine so it's good for a key assignment, and it skips the step of compiling the string.

Just a different angle for you to explore, you seem to have discarded this idea because of the << >>.
Find all posts by this user
Quote this message in a reply
10-18-2016, 11:17 PM (This post was last modified: 10-19-2016 01:38 PM by DavidM.)
Post: #18
RE: (50g) String inside string manipulation, UserRPL
It definitely appears that the parser used by STR→ (and by extension, OBJ→) is confused by \" sequence in certain situations. I noticed that "\"" seems to always work, though.

Is there a reason that you have to build the escape sequence in multiple steps? If you keep putting the elements in place on the stack (or better yet, in a list) and then concatenate them all at the end, the final string may be more coherent for the parser. Just a thought.

Otherwise you probably need to start considering alternatives to UserRPL. Either extended functions (as Claudio points out), SYSEVALs or straight SysRPL.

Don't give up!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)