Author Topic: v1.5 128 bit (and beyond) math *** COMPILER ERROR ***  (Read 11749 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard

  • Seasoned Forum Regular
  • Posts: 344
Re: QB64 v1.5 Feature Request - new string functions
« Reply #30 on: July 25, 2020, 09:08:51 PM »
More string functions request:-

eg

Replace all instances of a string subset with a longer or shorter different string subset (MID$/INSTR can easily be used when no change in length)

eg syntax   REPLACE$(stringname$, search substring$, replacement substring$)


usage

newstring$=REPLACE$(oldstring$,"abc","abcd")

would result in a newstring$ being one character longer than oldstring$ (assuming only one instance of "abc" in oldstring$


Many variations and special cases are possible for this request such as  - delete all instances of "abc", capitalize etc)
« Last Edit: July 26, 2020, 05:37:08 AM by Richard »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1824
Re: QB64 v1.5 Feature Request - new string functions
« Reply #31 on: July 26, 2020, 03:06:45 AM »
Hi Richard
here the prototype of your request
... someone that can do it he must inject this code in QB64 source adding the new Keyword

Code: QB64: [Select]
  1. FUNCTION Replace$ (InWhat AS STRING, AtPlaceOf AS STRING, WhatNew AS STRING)
  2.     ' this function replace WhatNew InWhat AtPlaceOf
  3.     ' all arguments must have at least one character
  4.  
  5.     IF LEN(InWhat) > 0 AND LEN(AtPlaceOf) > 0 AND LEN(WhatNew) > 0 THEN
  6.         DO WHILE INSTR(InWhat, AtPlaceOf)
  7.             InWhat = LEFT$(InWhat, INSTR(InWhat, AtPlaceOf) - 1) + WhatNew + RIGHT$(InWhat, LEN(InWhat) - (INSTR(InWhat, AtPlaceOf) - 1 + LEN(AtPlaceOf)))
  8.         LOOP
  9.         Replace$ = InWhat
  10.     END IF

I think that for a good gameplay  of function we can use an optional parameter that specifies what work must do the function.. CAPITALIZE characters,  normalize characters, substitute
characters... for default IMHO is this last... just to not loose the meaning of the keyword REPLACE$  (fun to think a PRINT keyword that read a data from keyboard !)
Waiting your and other feedback
Good Programming and Good Life
Programming isn't difficult, only it's  consuming time and coffee

Offline Richard

  • Seasoned Forum Regular
  • Posts: 344
Re: QB64 v1.5 Feature Request - new string functions
« Reply #32 on: July 26, 2020, 05:35:13 AM »
@TempodiBasic

I like your string names.

To be more useful it is important to be able to replace a string subset with NULL and of course ALL characters 0 - 255.

REPLACE is term used by Notepad - however CHANGE is term used by the QB64 IDE, and maybe a better choice of naming. Also SUBSTITUTE may be a candidate for naming.

Features (in line with the IDE) would have Match Upper/Lowercase, whole word, change first, Change All, go backwards for say one change, etc.

Online SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3708
    • Steve’s QB64 Archive Forum
Re: QB64 v1.5 Feature Request - new string functions
« Reply #33 on: July 26, 2020, 10:30:55 AM »
The problem with REPLACE type commands is nobody ever agrees what to replace.

I like food; my cat likes catfood.

Now in the above, let’s replace “food” with “cheese”.  A fight just started out because one group claims catfood should change, while another group claims its not an exact match.

So a REPLACE _EXACT command is added.

Now, a fight breaks out again.   One group extoles “food;“ isn’t an exact match to “food”.  The next group claims punctutation doesn’t count.

REPLACE _EXACT _NOPUNCTUATION is born.

Now a fight breaks out because someone changed the typo to “cat-food”.  One group wants that food to change now.  The other group says it shouldn’t...

REPLACE _EXACT _NOPUNCTUATION _IGNOREHYPHON is born.

And now a group complains because the command is too long, too complicated, and no one will ever use it....

Replace is a command that has to be custom rolled, in my opinion.  There’s just no way to please the masses when implementing it.  Add it to a language, and forevermore you’ll get suggestions on “how to improve it”.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Online FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 3077
  • Let it go, this too shall pass.
    • QB64.org
Re: QB64 v1.5 Feature Request - new string functions
« Reply #34 on: July 26, 2020, 10:33:14 AM »
Sounds like the beginning of a collective project to be featured in the samples gallery instead.

Offline bplus

  • Forum Resident
  • Posts: 7155
  • b = b + ...
Re: QB64 v1.5 Feature Request - new string functions
« Reply #35 on: July 26, 2020, 10:43:52 AM »
Sounds like the beginning of a collective project to be featured in the samples gallery instead.

I don't know, Steve just put forward a pretty good argument for NOT that!

Quote
Replace is a command that has to be custom rolled, in my opinion.  There’s just no way to please the masses when implementing it.  Add it to a language, and forevermore you’ll get suggestions on “how to improve it”.

Online FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 3077
  • Let it go, this too shall pass.
    • QB64.org
Re: QB64 v1.5 Feature Request - new string functions
« Reply #36 on: July 26, 2020, 10:45:38 AM »
His arguments - all of which make perfect sense - would be not to add it to the language itself.

Think of CircleFill, though: several decisions have had to be made in that one and now we have a major tool available for everyone to use.

Offline bplus

  • Forum Resident
  • Posts: 7155
  • b = b + ...
Re: QB64 v1.5 Feature Request - new string functions
« Reply #37 on: July 26, 2020, 10:50:14 AM »
His arguments - all of which make perfect sense - would be not to add it to the language itself.

Think of CircleFill, though: several decisions have had to be made in that one and now we have a major tool available for everyone to use.

Yeah, OK not to the language definitely, do we have these various versions of Replace hammered out somewhere yet?

@SMcNeill do you have these versions somewhere: REPLACE _EXACT _NOPUNCTUATION _IGNOREHYPHON is born.

Offline luke

  • QB64 Developer
  • Seasoned Forum Regular
  • Posts: 285
Re: QB64 v1.5 Feature Request - new string functions
« Reply #38 on: July 26, 2020, 10:58:20 AM »
All you need is a function that does plain search replace and one that does regex matches, and all of Steve's strange desires for catfood are taken care of.

result$ = REGEXREPLACE(regex$, replacement$, subject$[, limit&])

Now let's all argue over whether we use POSIX or perl regexen.

Offline bplus

  • Forum Resident
  • Posts: 7155
  • b = b + ...
Re: QB64 v1.5 Feature Request - new string functions
« Reply #39 on: July 26, 2020, 11:08:51 AM »
All you need is a function that does plain search replace and one that does regex matches, and all of Steve's strange desires for catfood are taken care of.

result$ = REGEXREPLACE(regex$, replacement$, subject$[, limit&])

Now let's all argue over whether we use POSIX or perl regexen.

Well for starters, I would be happy to see one version or the other :)

I assume the version TempodiBasic posted is the regular "plain" version, straight replacement regardless of before and after the string? and I can assume the straight replace is case sensitive? ie "Food" would not get replaced if "food" was to be replaced.
« Last Edit: July 26, 2020, 11:10:02 AM by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1824
Re: QB64 v1.5 Feature Request - new string functions
« Reply #40 on: July 26, 2020, 01:48:22 PM »
Hi guys
fine to meet you again
well I agree with the funny tale of Steve that brings his experience into developing a new Keyword of language, but this
I don't know, Steve just put forward a pretty good argument for NOT that!

  is one reality, not all reality...
the solution of Fellippe : make a new tool for toolbox is a good mediation between new keyword generating disaster and nothing to do for REPLACE$, so each coder does by his own.

and thanks to luke I have learned regex idea! https://en.wikipedia.org/wiki/Regular_expression
Thanks!

Yes Bplus my plain prototype is case sensitive, but it is possible to project an option panel like this one
 

all we need is a large discussion going to a consensus about What to do (How should REPLACE$  be?)  and How it must be done (Is it a FUNCTION? In this case What kind of feedback does  it give? What error number feedback does it send? ....to not waste your time and your energy!
Programming isn't difficult, only it's  consuming time and coffee

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1109
  • If you're API and you know it clap your hands
    • My GitHub
Re: QB64 v1.5 Feature Request - new string functions
« Reply #41 on: July 26, 2020, 02:42:32 PM »
Functions to remove/replace characters from a string as a built in function would be awesome if they can do that
If you're API and you know it clap your hands
My GitHub

Offline +KZ

  • Newbie
  • Posts: 21
  • an ugly avatar :)
Re: QB64 v1.5 Feature Request - new string functions
« Reply #42 on: July 26, 2020, 07:42:28 PM »
I realize that "for next" can only contain one variable (correct me if I'm wrong)

my suggestion is enable "for next" to contain more variables

example:

Code: QB64: [Select]
  1. 'Actual:
  2. FOR X = 1 TO 5
  3. IF z < 3 THEN z = z + 1
  4.  
  5. Y = x + z
  6.  
  7. 'My suggestion
  8.  
  9. FOR X = 1 TO 5, z = 1 TO 3                        'CAN BE:  |IF z < 3 THEN z = z + 1|  OR  |z = z + 1: IF z > 3 then z = 1|
  10.  
  11. Y = x + z
  12.  
  13.  
google translate :0

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1109
  • If you're API and you know it clap your hands
    • My GitHub
Re: QB64 v1.5 Feature Request - new string functions
« Reply #43 on: July 26, 2020, 10:59:28 PM »
@+KZ I like that idea.
If you're API and you know it clap your hands
My GitHub

Online SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3708
    • Steve’s QB64 Archive Forum
Re: QB64 v1.5 Feature Request - new string functions
« Reply #44 on: July 26, 2020, 11:18:34 PM »
FOR X = 1 TO 5, z = 1 TO 3                       
 'CAN BE:  |IF z < 3 THEN z = z + 1|  OR  |z = z + 1: IF z > 3 then z = 1|
 
Y = x + z
PRINT Y
NEXT

I think I’m confused by the above.  The comments seem to show two completely different concepts. 

The first (IF z < 3 THEN z = z + 1), seems to indicate z would be 1, 2, 3, 3, 3, during the 5 passes of X. 

The second (z = z + 1: IF z > 3 then z = 1), seems to indicate z would be 1, 2, 3, 1, 2.

Those are vastly different results!

Wouldn’t the easy way simply be:


 
FOR X = 1 TO 5
z = z MOD 3 + 1
Y = x + z
PRINT Y
NEXT

Here, z would be 1, 2, 3, 1, 2.  If you actually wanted 1, 2, 3, 3, 3, wouldn’t that IF statement in the original be easier to understand and more readable?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!