Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #45968

Re: string-stack.4th

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Re: string-stack.4th
Date 2016-03-11 06:24 +0000
Organization A noiseless patient Spider
Message-ID <nbtob1$dgd$1@dont-email.me> (permalink)
References (7 earlier) <nbiemr$5kg$1@gioia.aioe.org> <36f34016-ac87-4117-bff3-66bdc6e016d0@googlegroups.com> <b67d0308-b176-4d24-8357-980842c2d6eb@googlegroups.com> <56dd73a9$0$24031$e4fe514c@news.xs4all.nl> <4696cc36-ce3d-4786-b134-1da0a41f03c1@googlegroups.com>

Show all headers | View raw


hughaguilar96@gmail.com wrote:

> In the meantime, I upgraded the capability of string-stack.4th
> a bit. I can do this now:
> 
> s" foo:=bar" >$  ok
> s" :=" >$ infix$ . -1  ok
> extract$  ok
> .$ bar ok
> .$ foo ok
> 
> INFIX$ returns a flag indicating if it found the pattern in
> the string. The dot gave me -1 (TRUE) so I then used EXTRACT$
> to remove the infix and return the prefix and suffix that were
> surrounding the infix. So, I parsed a little bit of Pascal
> code there (in Pascal, := is an assignment).

Don't forget that ":=" can be surrounded by whitespace.

Ruby:

" foo  :=    bar ".split(":=").map(&:strip)
 ===>
["foo", "bar"]


OCaml:

#load "str.cma";;

List.map String.trim (Str.split (Str.regexp ":=") " foo  :=    bar ") ;;
 ===>
["foo"; "bar"]

If you want a considerable amount of string-manipulation power,
you'll have to implement a regular-expression engine.

Example: find each integer in a string and increment it.

Ruby:

"9, 10, 11 I see, now that 1983 has come and gone".
gsub(/\d+/){|s| s.to_i + 1}
 ===>
"10, 11, 12 I see, now that 1984 has come and gone"

OCaml:

#load "str.cma";;

Str.global_substitute (Str.regexp "[0-9]+")
  (fun s -> string_of_int ((int_of_string (Str.matched_string s)) + 1))
  "9, 10, 11 I see, now that 1983 has come and gone";;
 ===>
"10, 11, 12 I see, now that 1984 has come and gone"


Instead of splitting a string, shatter it.  In other words,
keep the separating strings instead of discarding them.

Ruby:

"foo := bar; write 8*9; end".split(/([^\w]+)/)
 ===>
["foo", " := ", "bar", "; ", "write", " ", "8", "*", "9", "; ", "end"]


OCaml:

#load "str.cma";;
open Str;;

Str.full_split (Str.regexp "[^a-z0-9]+") "foo := bar; write 8*9; end" ;;
 ===>
[Text "foo"; Delim " := "; Text "bar"; Delim "; "; Text "write"; Delim " ";
 Text "8"; Delim "*"; Text "9"; Delim "; "; Text "end"]

-- 
From the New York Times of October 11, 1991, ... we learn that ... researchers
at Boston University admitted that, "There is no question but that Dr. King
plagiarized in the dissertation." ... "Dr. Martin Luther King, Jr." [Michael
King] spent his last night on Earth having sexual intercourse with two women at
the motel and physically beating and abusing a third.  --  K. A. Strom

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

string-stack.4th hughaguilar96@gmail.com - 2016-03-03 21:42 -0800
  Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-03 21:54 -0800
  Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-04 18:01 -0800
    Re: string-stack.4th Mark Wills <markwills1970@gmail.com> - 2016-03-05 02:52 -0800
      Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-05 15:17 -0800
        Re: string-stack.4th foxaudioresearch@gmail.com - 2016-03-06 08:50 -0800
          Re: string-stack.4th foxaudioresearch@gmail.com - 2016-03-06 10:54 -0800
            Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-06 14:08 -0800
              Re: string-stack.4th "HAA" <someone@microsoft.com> - 2016-03-07 10:30 +1100
                Re: string-stack.4th foxaudioresearch@gmail.com - 2016-03-06 16:45 -0800
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-06 19:09 -0800
                Re: string-stack.4th Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-03-07 12:27 +0000
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-07 22:44 -0800
                Re: string-stack.4th JennyB <jennybrien@googlemail.com> - 2016-03-11 03:47 -0800
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-09 22:27 -0800
                Re: string-stack.4th Coos Haak <chforth@hccnet.nl> - 2016-03-10 11:05 +0100
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-10 09:28 -0800
                Re: string-stack.4th Coos Haak <chforth@hccnet.nl> - 2016-03-11 00:10 +0100
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-10 22:42 -0800
                Re: string-stack.4th Coos Haak <chforth@hccnet.nl> - 2016-03-11 12:29 +0100
                Re: string-stack.4th JennyB <jennybrien@googlemail.com> - 2016-03-12 01:33 -0800
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-12 16:56 -0800
                Re: string-stack.4th "WJ" <w_a_x_man@yahoo.com> - 2016-04-22 09:55 +0000
                Re: string-stack.4th "WJ" <w_a_x_man@yahoo.com> - 2016-04-22 10:00 +0000
                Re: string-stack.4th "WJ" <w_a_x_man@yahoo.com> - 2016-03-11 06:24 +0000
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-21 23:26 -0700
                Re: string-stack.4th franck.bensusan@gmail.com - 2016-03-10 10:42 -0800
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-03-10 23:00 -0800
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-04-10 20:23 -0700
                Re: string-stack.4th stephen@mpeforth.com (Stephen Pelc) - 2016-04-11 09:45 +0000
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-04-11 20:00 -0700
                Re: string-stack.4th Mark Wills <markwills1970@gmail.com> - 2016-04-11 03:16 -0700
                Re: string-stack.4th Mark Wills <markwills1970@gmail.com> - 2016-04-11 03:47 -0700
                Re: string-stack.4th Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-04-11 05:50 -0500
                Re: string-stack.4th Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-04-11 04:21 -0700
                Re: string-stack.4th Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-04-11 06:36 -0500
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-04-11 20:34 -0700
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-04-11 20:20 -0700
                Re: string-stack.4th hughaguilar96@gmail.com - 2016-06-03 05:53 -0700
              Re: string-stack.4th Mark Wills <markwills1970@gmail.com> - 2016-03-08 11:29 -0800

csiph-web