Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #57607 > unrolled thread
| Started by | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| First post | 2017-04-19 20:13 +0000 |
| Last post | 2017-04-21 00:19 +0000 |
| Articles | 16 — 7 participants |
Back to article view | Back to comp.lang.forth
.Re: splitting a string into 2 new strings "Robert L." <No_spamming@noWhere_7073.org> - 2017-04-19 20:13 +0000
Re: splitting a string into 2 new strings "HAA" <someone@microsoft.com> - 2017-04-20 19:07 +1000
Re: splitting a string into 2 new strings "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-20 17:08 +0000
Re: splitting a string into 2 new strings "HAA" <someone@microsoft.com> - 2017-04-21 11:54 +1000
Re: splitting a string into 2 new strings "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 09:45 +0000
Re: splitting a string into 2 new strings "HAA" <someone@microsoft.com> - 2017-04-21 23:32 +1000
Re: splitting a string into 2 new strings john <anon@example.com> - 2017-04-21 16:36 +0100
Re: splitting a string into 2 new strings "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 20:15 +0000
Re: splitting a string into 2 new strings Paul Rubin <no.email@nospam.invalid> - 2017-04-21 17:06 -0700
Re: splitting a string into 2 new strings "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-22 04:59 +0000
Re: splitting a string into 2 new strings "HAA" <someone@microsoft.com> - 2017-04-23 10:55 +1000
Re: splitting a string into 2 new strings "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-29 03:15 +0000
Re: splitting a string into 2 new strings The Beez <the.beez.speaks@gmail.com> - 2017-05-02 04:07 -0700
Re: splitting a string into 2 new strings "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-05-05 15:26 +0000
Re: splitting a string into 2 new strings hughaguilar96@gmail.com - 2017-04-20 13:32 -0700
Re: .Re: splitting a string into 2 new strings "Robert L." <No_spamming@noWhere_7073.org> - 2017-04-21 00:19 +0000
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Date | 2017-04-19 20:13 +0000 |
| Subject | .Re: splitting a string into 2 new strings |
| Message-ID | <od8gd9$1hsj$1@gioia.aioe.org> |
> > I have a string e.g. 'C6 H12 O6' that I wish to split up to give 2
> > strings
> > 'C H O' and '6 12 6'. I have played with string.split() and the re module
> > - but can't quite get there.
> >
> > Any help would be greatly appreciated.
...
> I'm, assuming that these are chemical compounds, so you're not limited to
> one-character symbols.
...
> import re
>
> re_pat = re.compile('([A-Z]+)(\d+)')
> text = 'C6 H12 O6'
>
> # find each component, returns list of tuples (e.g. [('C', '6'), ...]
> component = re_pat.findall(text)
>
> #split into separate lists
> symbols, counts = zip(*component)
>
> # create the strings
> symbols = ' '.join(symbols)
> counts = ' '.join(counts)
'C6 H12 O6'.split.map{|s| s.scan /\d+|\D+/}.transpose.
map{|a| a.join ' '}
===>
["C H O", "6 12 6"]
In Forth?
--
"A Jew always has a much higher soul than a gentile, even if he is a
homosexual," he [Israel's Deputy Defense Minister Eli Ben-Dahan] said.
theoccidentalobserver.net/2015/10/israeli-minister-latest-in-long-line-of-jews-asserting-the-inferiority-of-non-jews
[toc] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2017-04-20 19:07 +1000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <od9tpp$1mmg$1@gioia.aioe.org> |
| In reply to | #57607 |
Robert L. wrote:
> > > I have a string e.g. 'C6 H12 O6' that I wish to split up to give 2
> > > strings
> > > 'C H O' and '6 12 6'. I have played with string.split() and the re module
> > > - but can't quite get there.
> > >
> > > Any help would be greatly appreciated.
> ...
> > I'm, assuming that these are chemical compounds, so you're not limited to
> > one-character symbols.
> ...
> > import re
> >
> > re_pat = re.compile('([A-Z]+)(\d+)')
> > text = 'C6 H12 O6'
> >
> > # find each component, returns list of tuples (e.g. [('C', '6'), ...]
> > component = re_pat.findall(text)
> >
> > #split into separate lists
> > symbols, counts = zip(*component)
> >
> > # create the strings
> > symbols = ' '.join(symbols)
> > counts = ' '.join(counts)
>
> 'C6 H12 O6'.split.map{|s| s.scan /\d+|\D+/}.transpose.
> map{|a| a.join ' '}
>
> ===>
> ["C H O", "6 12 6"]
>
> In Forth?
Forth has sufficient flexibility so when there's no library or not fit for purpose, you
won't be left stranded. Your code will likely be more efficient than a library because
you won't be solving problems you don't have. You can code anything because
Forth encourages you to be a programmer - not a user dependent upon libraries.
[toc] | [prev] | [next] | [standalone]
| From | "Rudy Velthuis" <newsgroups@rvelthuis.de> |
|---|---|
| Date | 2017-04-20 17:08 +0000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <xn0koyolz8gwlap001@nntp.aioe.org> |
| In reply to | #57638 |
HAA wrote:
> Robert L. wrote:
> > > > I have a string e.g. 'C6 H12 O6' that I wish to split up
> > > > to give 2 strings
> > > > 'C H O' and '6 12 6'. I have played with string.split() and
> > > > the re module - but can't quite get there.
> > > >
> > > > Any help would be greatly appreciated.
> > ...
> > > I'm, assuming that these are chemical compounds, so you're not
> > > limited to one-character symbols.
> > ...
> > > import re
> > >
> > > re_pat = re.compile('([A-Z]+)(\d+)')
> > > text = 'C6 H12 O6'
> > >
> > > # find each component, returns list of tuples (e.g. [('C', '6'),
> > > ...] component = re_pat.findall(text)
> > >
> > > #split into separate lists
> > > symbols, counts = zip(*component)
> > >
> > > # create the strings
> > > symbols = ' '.join(symbols)
> > > counts = ' '.join(counts)
> >
> > 'C6 H12 O6'.split.map{|s| s.scan /\d+|\D+/}.transpose.
> > map{|a| a.join ' '}
> >
> > ===>
> > ["C H O", "6 12 6"]
> >
> > In Forth?
>
> Forth has sufficient flexibility so when there's no library or not
> fit for purpose, you won't be left stranded.
I guess that is true for almost any general purpose language.
But writing and testing your own code is not always preferrable to
using existing, well written and thoroughly tested code from a
(bonafide) library.
--
Rudy Velthuis http://www.rvelthuis.de
"It is only those who have neither fired a shot nor heard the
shrieks and groans of the wounded who cry aloud for blood...
War is hell." -- General William Tecumseh Sherman
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2017-04-21 11:54 +1000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <odboqo$p54$1@gioia.aioe.org> |
| In reply to | #57645 |
Rudy Velthuis wrote: > HAA wrote: > > ... > > Forth has sufficient flexibility so when there's no library or not > > fit for purpose, you won't be left stranded. > > I guess that is true for almost any general purpose language. > > But writing and testing your own code is not always preferrable to > using existing, well written and thoroughly tested code from a > (bonafide) library. I know what's in the library code I write myself and can make an intelligent decision whether or not to use it. That won't be true of library code written by others which by definition was created to solve *their* problem.
[toc] | [prev] | [next] | [standalone]
| From | "Rudy Velthuis" <newsgroups@rvelthuis.de> |
|---|---|
| Date | 2017-04-21 09:45 +0000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <xn0kozrfz1ooo0003@nntp.aioe.org> |
| In reply to | #57680 |
HAA wrote: > > > Forth has sufficient flexibility so when there's no library or not > > > fit for purpose, you won't be left stranded. > > > > I guess that is true for almost any general purpose language. > > > > But writing and testing your own code is not always preferrable to > > using existing, well written and thoroughly tested code from a > > (bonafide) library. > > I know what's in the library code I write myself and can make an > intelligent decision whether or not to use it. Sure. But it is a bit tedious to have to write everything yourself, especially if there are well written and trusted libraries around already. Trusting only your own code smells a bit like a case of NIH syndrome, IMO. -- Rudy Velthuis http://www.rvelthuis.de "It's not at all important to get it right the first time. It's vitally important to get it right the last time." -- Andrew Hunt and David Thomas
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2017-04-21 23:32 +1000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <odd1mf$uqi$1@gioia.aioe.org> |
| In reply to | #57705 |
Rudy Velthuis wrote: > HAA wrote: > > > > > Forth has sufficient flexibility so when there's no library or not > > > > fit for purpose, you won't be left stranded. > > > > > > I guess that is true for almost any general purpose language. > > > > > > But writing and testing your own code is not always preferrable to > > > using existing, well written and thoroughly tested code from a > > > (bonafide) library. > > > > I know what's in the library code I write myself and can make an > > intelligent decision whether or not to use it. > > Sure. But it is a bit tedious to have to write everything yourself, > especially if there are well written and trusted libraries around > already. It's an academic point since such libraries are virtually non-existent in Forth and no evidence to suggest that will change. > Trusting only your own code smells a bit like a case of NIH syndrome, > IMO. Forthers traditionally wrote their own code and in doing so became proficient. That isn't to say they always used the best methods or algorithms. If someone shows me a better way, or I see it in their code, I'll learn from that. But to blindly use another's code without a care as to suitability or efficiency, I may just as well be programming in a language such as WJ promotes. It's not why I came to Forth.
[toc] | [prev] | [next] | [standalone]
| From | john <anon@example.com> |
|---|---|
| Date | 2017-04-21 16:36 +0100 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <MPG.33643750a576c08698970c@news.virginmedia.com> |
| In reply to | #57718 |
In article <odd1mf$uqi$1@gioia.aioe.org>, someone@microsoft.com says... > Forthers traditionally wrote their own code and in doing so became > proficient. That isn't to say they always used the best methods or > algorithms. If someone shows me a better way, or I see it in their > code, I'll learn from that. But to blindly use another's code without a > care as to suitability or efficiency, I may just as well be programming > in a language such as WJ promotes. It's not why I came to Forth. > > > > I thought forth was a library? another for anyone interested. http://rosettacode.org/wiki/Category:Forth -- john ========================= http://johntech.co.uk "Bleeding Edge Forum" http://johntech.co.uk/forum/ =========================
[toc] | [prev] | [next] | [standalone]
| From | "Rudy Velthuis" <newsgroups@rvelthuis.de> |
|---|---|
| Date | 2017-04-21 20:15 +0000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <xn0kp08378mvulk003@nntp.aioe.org> |
| In reply to | #57718 |
HAA wrote: > Rudy Velthuis wrote: > > HAA wrote: > > > > > > > Forth has sufficient flexibility so when there's no library > > > > > or not fit for purpose, you won't be left stranded. > > > > > > > > I guess that is true for almost any general purpose language. > > > > > > > > But writing and testing your own code is not always preferrable > > > > to using existing, well written and thoroughly tested code from > > > > a (bonafide) library. > > > > > > I know what's in the library code I write myself and can make an > > > intelligent decision whether or not to use it. > > > > Sure. But it is a bit tedious to have to write everything yourself, > > especially if there are well written and trusted libraries around > > already. > > It's an academic point since such libraries are virtually > non-existent in Forth and no evidence to suggest that will change. > > > Trusting only your own code smells a bit like a case of NIH > > syndrome, IMO. > > Forthers traditionally wrote their own code and in doing so became > proficient. If I needed, say, BigNumbers, I would search for a library for those. If I needed for instance string processing beyond the simple compare or replace/substitute, I would look for a library like that. Writing everthing from scratch instead of using a trusted and well written library seems pretty useless, IMO. Are you saying there are no trusted and well written libraries in Forth? -- Rudy Velthuis http://www.rvelthuis.de "Machine. Unexpectedly, I'd invented a time." -- Alan Moore
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2017-04-21 17:06 -0700 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <87lgqt1f1f.fsf@nightsong.com> |
| In reply to | #57743 |
"Rudy Velthuis" <newsgroups@rvelthuis.de> writes: > Are you saying there are no trusted and well written libraries in Forth? That would be an overstatement. But there are fewer than there are for other languages, and the ones that do exist often have limited functionality or interfaces that don't fit in with your existing code, so you end up reimplementing them anyway. Scroll through a few pages of pypi.python.org or hackage.haskell.org/packages sometime and see how many would be reasonable candidates for Forth implementation (not all, but at least some). Then ask yourself which of those are likely to actually currently *have* a Forth implementation. I think there would be very few.
[toc] | [prev] | [next] | [standalone]
| From | "Rudy Velthuis" <newsgroups@rvelthuis.de> |
|---|---|
| Date | 2017-04-22 04:59 +0000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <xn0kp0ygi95lnb500i@nntp.aioe.org> |
| In reply to | #57758 |
Paul Rubin wrote: > "Rudy Velthuis" <newsgroups@rvelthuis.de> writes: > > Are you saying there are no trusted and well written libraries in > > Forth? > > That would be an overstatement. But there are fewer than there are > for other languages, and the ones that do exist often have limited > functionality or interfaces that don't fit in with your existing code, > so you end up reimplementing them anyway. Hmmm... That's sad. -- Rudy Velthuis http://www.rvelthuis.de "My experience in Amsterdam is that cyclists ride where the hell they like and aim in a state of rage at all pedestrians while ringing their bell loudly, the concept of avoiding people being foreign to them. My dream holiday would be a) a ticket to Amsterdam b) immunity from prosecution and c) a baseball bat." -- Terry Pratchett
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2017-04-23 10:55 +1000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <odgu4f$18mb$1@gioia.aioe.org> |
| In reply to | #57743 |
Rudy Velthuis wrote: > HAA wrote: > > > Rudy Velthuis wrote: > > > HAA wrote: > > > > > > > > > Forth has sufficient flexibility so when there's no library > > > > > > or not fit for purpose, you won't be left stranded. > > > > > > > > > > I guess that is true for almost any general purpose language. > > > > > > > > > > But writing and testing your own code is not always preferrable > > > > > to using existing, well written and thoroughly tested code from > > > > > a (bonafide) library. > > > > > > > > I know what's in the library code I write myself and can make an > > > > intelligent decision whether or not to use it. > > > > > > Sure. But it is a bit tedious to have to write everything yourself, > > > especially if there are well written and trusted libraries around > > > already. > > > > It's an academic point since such libraries are virtually > > non-existent in Forth and no evidence to suggest that will change. > > > > > Trusting only your own code smells a bit like a case of NIH > > > syndrome, IMO. > > > > Forthers traditionally wrote their own code and in doing so became > > proficient. > > If I needed, say, BigNumbers, I would search for a library for those. > If I needed for instance string processing beyond the simple compare or > replace/substitute, I would look for a library like that. Writing > everthing from scratch instead of using a trusted and well written > library seems pretty useless, IMO. > > Are you saying there are no trusted and well written libraries in Forth? How many have you found? Sorry but Forth has never had a culture of general-purpose libraries. There was a brief flurry after Forth-94 e.g. from scientific users but it didn't last with various Forth interests reverting to form. Stephen mentioned a client with a million line application. AFAIK commercial Forth apps are written in-house from scratch. Forthers certainly create libraries whose components may have been sourced elsewhere. While general-purpose Forth libraries may not exist as such, a reasonable amount of Forth source does appear in public, from which newcomers can learn or adapt. I'd characterize Forth programmers as resourceful developers more than users and that's how they prefer it. Chuck remains the archetypal Forth programmer and inspiration behind Forth. Forth needs an edge in order to compete but that edge has been its programmers. 'Forth is an amplifier' Chuck once said and I'd say history has borne that out.
[toc] | [prev] | [next] | [standalone]
| From | "Rudy Velthuis" <newsgroups@rvelthuis.de> |
|---|---|
| Date | 2017-04-29 03:15 +0000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <xn0kpapr72nbphl004@nntp.aioe.org> |
| In reply to | #57870 |
HAA wrote: > > Are you saying there are no trusted and well written libraries in > > Forth? > > How many have you found? Sorry but Forth has never had a culture of > general-purpose libraries. That is sad. Reinventing the wheel over and over is IMO pretty futile. And yes, libraries tend to use parts you don't need or are different than you expect them to be. Still, using a trusted and well-tested library beats reinventing the wheel, no matter if that is in C, C++, Java, Pascal, Eiffel, Javascript, Smalltalk, Haskell, Lisp, assembler, CSS, HTML or whatever programming or markup language you prefer. Forth seems to be the first language I encounter without any significant number of them. That is a sad affair, IMO. -- Rudy Velthuis http://www.rvelthuis.de "The most important single aspect of software development is to be clear about what you are trying to build." -- Bjarne Stroustrup
[toc] | [prev] | [next] | [standalone]
| From | The Beez <the.beez.speaks@gmail.com> |
|---|---|
| Date | 2017-05-02 04:07 -0700 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <8d6a1640-26fb-4d3e-83a4-4b9d14a7db17@googlegroups.com> |
| In reply to | #58327 |
On Saturday, April 29, 2017 at 5:15:07 AM UTC+2, Rudy Velthuis wrote: > > How many have you found? Sorry but Forth has never had a culture of > > general-purpose libraries. True, although I've never hesitated to nick some good code, I've written most of 4tH's 450 libs myself. On the other hand I see reluctance of Forth programmers to use code others have produced. So IMHO this goes both ways.. Another thing is, that some write MASSIVE libs, some using some odd kind of framework, e.g. FSL arrays or other (huge) dependencies. It's no fun reusing that, because you have to maintain it as well (if it's part of your compiler). Hans Bezemer
[toc] | [prev] | [next] | [standalone]
| From | "Rudy Velthuis" <newsgroups@rvelthuis.de> |
|---|---|
| Date | 2017-05-05 15:26 +0000 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <xn0kpmhjs1hq2vq001@nntp.aioe.org> |
| In reply to | #58485 |
The Beez wrote: > On Saturday, April 29, 2017 at 5:15:07 AM UTC+2, Rudy Velthuis wrote: > > > How many have you found? Sorry but Forth has never had a culture > > > of general-purpose libraries. > True, although I've never hesitated to nick some good code, I've > written most of 4tH's 450 libs myself. I don't reembmer who said it, but: "If you steal from one person, you will be called a plagiarist. If you steel from many, you will be called a genius." <g> > > On the other hand I see reluctance of Forth programmers to use code > others have produced. So IMHO this goes both ways.. OK. A case of NIH syndrome after all? -- Rudy Velthuis http://www.rvelthuis.de "Some tortures are physical And some are mental, But the one that is both Is dental." -- Ogden Nash
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2017-04-20 13:32 -0700 |
| Subject | Re: splitting a string into 2 new strings |
| Message-ID | <cd3af870-7c68-40ce-a6b2-6c5b22e1f393@googlegroups.com> |
| In reply to | #57638 |
On Thursday, April 20, 2017 at 2:08:12 AM UTC-7, HAA wrote:
> Robert L. wrote:
> > > > I have a string e.g. 'C6 H12 O6' that I wish to split up to give 2
> > > > strings
> > > > 'C H O' and '6 12 6'. I have played with string.split() and the re module
> > > > - but can't quite get there.
> > > >
> > > > Any help would be greatly appreciated.
> > ...
> > > I'm, assuming that these are chemical compounds, so you're not limited to
> > > one-character symbols.
> > ...
> > > import re
> > >
> > > re_pat = re.compile('([A-Z]+)(\d+)')
> > > text = 'C6 H12 O6'
> > >
> > > # find each component, returns list of tuples (e.g. [('C', '6'), ...]
> > > component = re_pat.findall(text)
> > >
> > > #split into separate lists
> > > symbols, counts = zip(*component)
> > >
> > > # create the strings
> > > symbols = ' '.join(symbols)
> > > counts = ' '.join(counts)
> >
> > 'C6 H12 O6'.split.map{|s| s.scan /\d+|\D+/}.transpose.
> > map{|a| a.join ' '}
> >
> > ===>
> > ["C H O", "6 12 6"]
> >
> > In Forth?
>
> Forth has sufficient flexibility so when there's no library or not fit for purpose, you
> won't be left stranded. Your code will likely be more efficient than a library because
> you won't be solving problems you don't have. You can code anything because
> Forth encourages you to be a programmer - not a user dependent upon libraries.
Normally HAA's posts are intelligent --- this post wasn't though.
Here are some snippets from my STRING-STACK.4TH package documentation that involve extracting substrings:
----------------------------------------------------------------------
FIND$ ( -- index|-1 ) \ string: a b --
This finds the A string in the B string, or returns -1 if not found.
IFIND$ ( -- index|-1 ) \ string: a b --
Like FIND$ except case-insensitive.
...
LEN$ ( -- length ) \ string: a --
This returns the length of the string on the data-stack. This consumes the string on the string-stack (Forth functions traditionally consume their arguments), so if this is used and you still need the string, then DUP$ or OVER$ or whatever should be used to keep a copy on the string-stack.
MID$ ( start-index length -- ) \ string: a -- b
The B string is a substring in the middle of the A string.
ANTI-MID$ ( start-index length -- ) \ string: a -- b
Returns the string with the middle part extracted (what MID$ would have returned is not returned, but instead the edge parts concatenated together are returned).
INNER$ ( start-index limit-index -- ) \ string: a -- b
This is like MID$ except that it uses a LIMIT-INDEX rather than a LENGTH (this is somewhat like Mark Wills' MID$ and, to the best of my recollection, like the QBASIC MID$). Note that the LIMIT-INDEX is 1 beyond the middle-part that is kept (LIMIT-INDEX minus START-INDEX equals length).
ANTI-INNER$ ( start-index limit-index -- ) \ string: a -- b
Returns the string with the middle part extracted (what INNER$ would have returned is not returned, but instead the edge parts concatenated together are returned). Note that the LIMIT-INDEX is 1 beyond the middle-part that is extracted (LIMIT-INDEX minus START-INDEX equals length).
LEFT$ ( length -- ) \ string: a -- b
This provides a substring of length LENGTH from the left side of the string.
RIGHT$ ( length -- ) \ string: a -- b
This provides a substring of length LENGTH from the right side of the string.
DISCARD-LEFT$ ( length -- ) \ string: a -- b
This discards a substring of length LENGTH from the left side of the string.
DISCARD-RIGHT$ ( length -- ) \ string: a -- b
This discards a substring of length LENGTH from the right side of the string.
...
Section 1.4.) prefixes and suffixes and infixes, oh my!
PREFIX$ ( -- found? ) \ string: a b -- a | c
This determines if B is a prefix of A. If PREFIX$ returns true, then it returns C which is the prefix inside of A (it is a derivative).
IPREFIX$ ( -- found? ) \ string: a b -- a | c
This is like PREFIX$ except case-insensitive.
SUFFIX$ ( -- found? ) \ string: a b -- a | c
This determines if B is a suffix of A. If SUFFIX$ returns true, then it returns C which is the suffix inside of A (it is a derivative).
ISUFFIX$ ( -- found? ) \ string: a b -- a | c
This is like SUFFIX$ except case-insensitive.
INFIX$ ( -- found? ) \ string: a b -- a | c
This determines if B is an infix of A. If INFIX$ returns true, then it returns C which is the infix inside of A (it is a derivative).
IINFIX$ ( -- found? ) \ string: a b -- a | c
This is like INFIX$ except case-insensitive.
EXTRACT$ ( -- ) \ string: a b -- c d
This requires B to be a derivative inside of A (it is also okay for B to be an empty unique). EXTRACT$ removes the B string from the A string and returns the prefix (the C string) and the suffix (the D string). This should only be used on the results returned by: INFIX$ PREFIX$ SUFFIX$ IINFIX$ IPREFIX$ or ISUFFIX$
Note that EXTRACT$ is the only function we have that requires the parameters to be derived one from the other. All of our other functions work on either unique or derivative strings. EXTRACT$ is context-sensitive, in that it is supposed to be used after certain other functions. See also ANTIMID$ that uses EXTRACT$ internally.
[toc] | [prev] | [next] | [standalone]
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Date | 2017-04-21 00:19 +0000 |
| Message-ID | <odbj70$ina$1@gioia.aioe.org> |
| In reply to | #57607 |
On 4/19/2017, Robert L. wrote:
> > > I have a string e.g. 'C6 H12 O6' that I wish to split up to give 2
> > > strings
> > > 'C H O' and '6 12 6'. I have played with string.split() and the re module
> > > - but can't quite get there.
> > >
> > > Any help would be greatly appreciated.
> ...
> > I'm, assuming that these are chemical compounds, so you're not limited to
> > one-character symbols.
> ...
> > import re
> >
> > re_pat = re.compile('([A-Z]+)(\d+)')
> > text = 'C6 H12 O6'
> >
> > # find each component, returns list of tuples (e.g. [('C', '6'), ...]
> > component = re_pat.findall(text)
> >
> > #split into separate lists
> > symbols, counts = zip(*component)
> >
> > # create the strings
> > symbols = ' '.join(symbols)
> > counts = ' '.join(counts)
>
> 'C6 H12 O6'.split.map{|s| s.scan /\d+|\D+/}.transpose.
> map{|a| a.join ' '}
>
> ===>
> ["C H O", "6 12 6"]
>
> In Forth?
Shorter:
["0-9","A-Z"].map{|s| 'C6 H12 O6'.delete s}
===>
["C H O", "6 12 6"]
--
Jewish drug dealers, child porn pushers, and slave traders are free
from prosecution in Israel. Israel does not consider these to be
crimes ... so long as the victims are non-Jews.
www.theoccidentalobserver.net/2009/08/the-culture-of-deceit/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web