There is an effort underway to collect valuable snippets of
Forth, https://github.com/project-forth-works/
I have regular expression package that I used (i.a.) to transform
the fifth chapter of "thinking forth" from xml to tex and the
manx music score that went through half a dozen different notations.
I have recently used it to convert ARM assembler
language to risc-V language. Regular expression without the
facility to transform texts is a joke.
The program doesn't comply to ISO, so I thought an elaborate
rationale is in order. If you consider the rationale unconvincing,
I will not bother to upload the package.
"
Why ciforthisms?
In short, I could never manage to write the regular expression
package with ciforthism.
Note that to have recently used it to convert ARM assembler
language to risc-V language. Regular expression without the
facility to transform texts is a joke.
****************** STRINGS **********************
A regular expression package handles strings. Any attempt to handle
strings portably in Forth sucks.
1. String denotations.
Strings defined by S" are unacceptable:
the S leads to confusion
Much less visible is the problem that S" AAP" is 3 characters
and S" AAP" is 4, I guess?. In ciforth there is a normal string
denotation:
"AAP" is three chars
" AAP" is four chars
" AAP" is five chars
2.
Strings with escapes are unacceptable:
They conflict with the escapes needed in this package.
There is one exception, the double quote convention.
In order to have a double quote &" in a string you have
to double it like so `` "" ''.
In ciforth you can have strings that span multiple lines,
albeit only in a program.
3. Character denotations, function denotations.
We use &A and for a good reason.
CHAR [CHAR] are verbose and cumbersome.
Moreover the notation 'x' for the character x overloads the tick
too much, because in ciforth ' is reserved to denote dea's.
Functions in a regular expression are passed around as executions tokens
like so 'ADVANCE+ , using a single tick, without square brackets
around it.
POSTPONE 'ADVANCE+
fails because "'ADVANCE+" is not in the dictionary, which is just
as well. ( "ADVANCE+" is present, of course).
4. Low level abstraction fails.
COUNT -TRAILING S" C" WORD PLACE form a non-unified conglomerate
of handling strings.
You need : $! $@ $+! C+$ and $/
Get familiar with these. They are easy, because they use
the underlying buffers explicitly. Any half-assed attempt to
use string-stacks and more poorly conceived abstractions
adds to the problem not the solution.
************************** The library *************************
I use WANT. All words following are supposed to be available.
You can load them, or give an error are they not present.
The library contains tools, notably the SET and BAG tools.
It is not good to have them as part of the package.
First get familiar to the tools, then attempt to read the
package. You have lifted yourself to a higher plane.
That is needed for regular expressions, they are not easy.
Anytime you encounter WANT you have to get familiar to the
tools wanted. In ciforth they are mostly Forth words that
are present in fat Forth's, so there in lies no problem.
****************** USABILITY ******************************
Using Forth programs sucks. Mostly you must have the particular
Forth installed in your computer. Then the invocations leave
much to be desired.
The best one come up with is
<forth> <somesource>
but the question is "where do the parameters go
-- in particular filenames -- ? "
ciforth solves this in four ways, each of those are
preferable in some situations.
1. interactive, you start forth then you load your program
2. scripting, the forth is in the first line of the script
Parameters are passed naturally to the script.
The forth must load the regular expression module first
3. scripting, the regular expressions library is compiled into
an enhanced forth. In the script you specify the the particular
expressions you want changed.
Parameters are passed naturally to the script.
Note that you don't need a Forth installed. The scripting
program is enough. You can send it as an attachment and
it will run on the same Operating System.
4. Compiled. Now the transformations you want to do are
burned into the executable.
Parameters are passed naturally to the script.
Note that you don't need a Forth installed. The scripting
program is enough. You can send it as an attachment and
it will run on the same Operating System.
This sounds a lot of hype. Therefore I have supplied a
simple practical examples, in several circumstances and operating
systems.
"
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make
spring. You must not say "hey" before you have crossed the bridge.
Don't sell the hide of the bear until you shot it. Better one bird in
the hand than ten in the air. - the Wise from Antrim -
There is an effort underway to collect valuable snippets of
Forth, https://github.com/project-forth-works/
I have regular expression package that I used (i.a.) to transform
the fifth chapter of "thinking forth" from xml to tex and the
manx music score that went through half a dozen different notations.
I have recently used it to convert ARM assembler
language to risc-V language. Regular expression without the
facility to transform texts is a joke.
The program doesn't comply to ISO, so I thought an elaborate
rationale is in order. If you consider the rationale unconvincing,
I will not bother to upload the package.
Why ciforthisms?^^^^
In short, I could never manage to write the regular expression
package with ciforthism.
Note that to have recently used it to convert ARM assembler
language to risc-V language. Regular expression without the
facility to transform texts is a joke.
****************** STRINGS **********************
A regular expression package handles strings. Any attempt to handle
strings portably in Forth sucks.
1. String denotations.
Strings defined by S" are unacceptable:
the S leads to confusion
2.
Strings with escapes are unacceptable:
They conflict with the escapes needed in this package.
There is one exception, the double quote convention.
In order to have a double quote &" in a string you have
to double it like so `` "" ''.
In ciforth you can have strings that span multiple lines,
3. Character denotations, function denotations.
We use &A and for a good reason.
CHAR [CHAR] are verbose and cumbersome.
4. Low level abstraction fails.
COUNT -TRAILING S" C" WORD PLACE form a non-unified conglomerate
of handling strings.
You need : $! $@ $+! C+$ and $/
There is an effort underway to collect valuable snippets ofFirst, you know me to be quite frank - but that doesn' mean disrespect.
Forth, https://github.com/project-forth-works/
I have regular expression package that I used (i.a.) to transform
the fifth chapter of "thinking forth" from xml to tex and the
manx music score that went through half a dozen different notations.
I have recently used it to convert ARM assembler
language to risc-V language. Regular expression without the
facility to transform texts is a joke.
The program doesn't comply to ISO, so I thought an elaborate
rationale is in order. If you consider the rationale unconvincing,
I will not bother to upload the package.
"
Why ciforthisms?
In short, I could never manage to write the regular expression
package with ciforthism.
Note that to have recently used it to convert ARM assembler
language to risc-V language. Regular expression without the
facility to transform texts is a joke.
****************** STRINGS **********************
A regular expression package handles strings. Any attempt to handle
strings portably in Forth sucks.
1. String denotations.
Strings defined by S" are unacceptable:
the S leads to confusion
Much less visible is the problem that S" AAP" is 3 characters
and S" AAP" is 4, I guess?. In ciforth there is a normal string
denotation:
"AAP" is three chars
" AAP" is four chars
" AAP" is five chars
2.
Strings with escapes are unacceptable:
They conflict with the escapes needed in this package.
There is one exception, the double quote convention.
In order to have a double quote &" in a string you have
to double it like so `` "" ''.
In ciforth you can have strings that span multiple lines,
albeit only in a program.
3. Character denotations, function denotations.
We use &A and for a good reason.
CHAR [CHAR] are verbose and cumbersome.
Moreover the notation 'x' for the character x overloads the tick
too much, because in ciforth ' is reserved to denote dea's.
Functions in a regular expression are passed around as executions tokens
like so 'ADVANCE+ , using a single tick, without square brackets
around it.
POSTPONE 'ADVANCE+
fails because "'ADVANCE+" is not in the dictionary, which is just
as well. ( "ADVANCE+" is present, of course).
4. Low level abstraction fails.
COUNT -TRAILING S" C" WORD PLACE form a non-unified conglomerate
of handling strings.
You need : $! $@ $+! C+$ and $/
Get familiar with these. They are easy, because they use
the underlying buffers explicitly. Any half-assed attempt to
use string-stacks and more poorly conceived abstractions
adds to the problem not the solution.
************************** The library *************************
I use WANT. All words following are supposed to be available.
You can load them, or give an error are they not present.
The library contains tools, notably the SET and BAG tools.
It is not good to have them as part of the package.
First get familiar to the tools, then attempt to read the
package. You have lifted yourself to a higher plane.
That is needed for regular expressions, they are not easy.
Anytime you encounter WANT you have to get familiar to the
tools wanted. In ciforth they are mostly Forth words that
are present in fat Forth's, so there in lies no problem.
****************** USABILITY ******************************
Using Forth programs sucks. Mostly you must have the particular
Forth installed in your computer. Then the invocations leave
much to be desired.
The best one come up with is
<forth> <somesource>
but the question is "where do the parameters go
-- in particular filenames -- ? "
ciforth solves this in four ways, each of those are
preferable in some situations.
1. interactive, you start forth then you load your program
2. scripting, the forth is in the first line of the script
Parameters are passed naturally to the script.
The forth must load the regular expression module first
3. scripting, the regular expressions library is compiled into
an enhanced forth. In the script you specify the the particular
expressions you want changed.
Parameters are passed naturally to the script.
Note that you don't need a Forth installed. The scripting
program is enough. You can send it as an attachment and
it will run on the same Operating System.
4. Compiled. Now the transformations you want to do are
burned into the executable.
Parameters are passed naturally to the script.
Note that you don't need a Forth installed. The scripting
program is enough. You can send it as an attachment and
it will run on the same Operating System.
This sounds a lot of hype. Therefore I have supplied a
simple practical examples, in several circumstances and operating
systems.
"
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make
spring. You must not say "hey" before you have crossed the bridge.
Don't sell the hide of the bear until you shot it. Better one bird in
the hand than ten in the air. - the Wise from Antrim -
Regular Expression packages. About 10 years ago I wrote a
comprehensive Regex package in ANS Forth (yes it can be done) that
works on several Forths including GForth, VFX Forth, SwiftForth, WF32
and my own system and made it available on a website and there was
virtually no interest.
Gerry Jackson <do-no...@swldwa.uk> writes:
Regular Expression packages. About 10 years ago I wrote aWell I didn't know about it. I think it is good to have such a thing,
comprehensive Regex package in ANS Forth (yes it can be done) that
works on several Forths including GForth, VFX Forth, SwiftForth, WF32
and my own system and made it available on a website and there was virtually no interest.
for those who do any type of text processing in Forth. I can't think of
any times where I'd have used it myself though.
For some alarm log filtering long time ago I just called awk from Forth.There are several things to the issue. First, getting the individual elements. I can use both a sscanf() like function (if I'm lazy) or simply use several "PARSE"
But we had to upload the logs to a server to do it and send the result back. Had we some regex in the remote machines it could perhaps be done
locally - theoretically.
Gerry Jackson <do-not-use@swldwa.uk> writes:
Regular Expression packages. About 10 years ago I wrote a
comprehensive Regex package in ANS Forth (yes it can be done) that
works on several Forths including GForth, VFX Forth, SwiftForth, WF32
and my own system and made it available on a website and there was
virtually no interest.
Well I didn't know about it. I think it is good to have such a thing,
for those who do any type of text processing in Forth. I can't think of
any times where I'd have used it myself though.
Gerry Jackson <do-no...@swldwa.uk> writes:
Regular Expression packages. About 10 years ago I wrote aWell I didn't know about it. I think it is good to have such a thing,
comprehensive Regex package in ANS Forth (yes it can be done) that
works on several Forths including GForth, VFX Forth, SwiftForth, WF32
and my own system and made it available on a website and there was virtually no interest.
for those who do any type of text processing in Forth. I can't think of
any times where I'd have used it myself though.
There is an effort underway to collect valuable snippets of
Forth, https://github.com/project-forth-works/
I have regular expression package that I used (i.a.) to transform
the fifth chapter of "thinking forth" from xml to tex and the
manx music score that went through half a dozen different notations.
I have recently used it to convert ARM assembler
language to risc-V language. Regular expression without the
facility to transform texts is a joke.
On Friday, January 13, 2023 at 9:49:02 AM UTC+1, minf...@arcor.de wrote:<SNIP>
For some alarm log filtering long time ago I just called awk from Forth.There are several things to the issue. First, getting the individual elements. >I can use both a sscanf() like function (if I'm lazy) or simply use
But we had to upload the logs to a server to do it and send the result back. >> Had we some regex in the remote machines it could perhaps be done
locally - theoretically.
several "PARSE"
variants to break those up (like a PARSE-CSV).
Second, if you really got messed up elements there are several ways to handle >those. I got a small lib which enables you to encode REGEX like expressions - >but in Forth. >(https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/lib/chmatch.4th)
For some purposes, I got specialized libs to handle those. Like dates: >(https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/lib/getdate.4th)
Or time: >https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/lib/hms2secs.4th
Once you got their numerical equivalents, it's not too hard to reformat
them accordingly.
Therefore - I hardly ever need regex to get the job done. In the 30 odd
years I've been
using 4tH, I built a vast array of specialized functions to tackle that. >Every time I
encountered something I didn't have a function for - I created it. Note
I use (and used)
it ad hoc for my professional work too - with significant success.
So I think I'm good. In any case, I also got a tiny matching regex if
I'm being lazy. Used
it once in a program I guess - just because the expression had to be
entered at runtime.
Hans Bezemer
1. String denotations.Why, I used them without any problems
Strings defined by S" are unacceptable:
the S leads to confusion
Suppose you are confronted with a number of files like
so
"
SCORE Vader-Jacob
DEFAULT: 112 /4 MM
INFO: Copyright AH & CH
PART one
\ PDEFAULT: GOLD
PDEFAULT: ORGAN 3 TRANSPOSE-UP L7
||: 4 /4 MEASURE
L: m1
/4 C3 D3 E3 C3 | duplicate
/4 E3 F3 /2 G3 | duplicate
/8 G3 A3 G3 F3 /4 E3 C3 | duplicate
/4 C3 G2 /2 C3 |
L: m2 duplicate
m1 .. m2 .S bis .S
||
On Friday, January 13, 2023 at 2:20:07 PM UTC+1, none albert wrote:
Suppose you are confronted with a number of files like
so
"
SCORE Vader-Jacob
DEFAULT: 112 /4 MM
INFO: Copyright AH & CH
PART oneI frankly have ZERO idea what I'm looking at - or what is expected of me.
\ PDEFAULT: GOLD
PDEFAULT: ORGAN 3 TRANSPOSE-UP L7
||: 4 /4 MEASURE
L: m1
/4 C3 D3 E3 C3 | duplicate
/4 E3 F3 /2 G3 | duplicate
/8 G3 A3 G3 F3 /4 E3 C3 | duplicate
/4 C3 G2 /2 C3 |
L: m2 duplicate
m1 .. m2 .S bis .S
||
I'm only a (light) consumer of music. Sports examples aren't much
good for me as well.
Got another one? Or at least show me what is expected to come out?
On Friday, January 13, 2023 at 2:20:07 PM UTC+1, none albert wrote:
Suppose you are confronted with a number of files like
so
"
SCORE Vader-Jacob
DEFAULT: 112 /4 MM
INFO: Copyright AH & CH
PART one
\ PDEFAULT: GOLD
PDEFAULT: ORGAN 3 TRANSPOSE-UP L7
||: 4 /4 MEASURE
L: m1
/4 C3 D3 E3 C3 | duplicate
/4 E3 F3 /2 G3 | duplicate
/8 G3 A3 G3 F3 /4 E3 C3 | duplicate
/4 C3 G2 /2 C3 |
L: m2 duplicate
m1 .. m2 .S bis .S
||
I frankly have ZERO idea what I'm looking at - or what is expected of me.
I'm only a (light) consumer of music. Sports examples aren't much
good for me as well.
Got another one? Or at least show me what is expected to come out?
Hans Bezemer
SCORE Vader-Jacob
DEFAULT: 112 /4 MM
INFO: Copyright AH & CH
PART one
\ PDEFAULT: GOLD
PDEFAULT: ORGAN 3 TRANSPOSE-UP L7
||: 4 /4 MEASURE
L: m1
/4 C3 D3 E3 C3 | duplicate
/4 E3 F3 /2 G3 | duplicate
/8 G3 A3 G3 F3 /4 E3 C3 | duplicate
/4 C3 G2 /2 C3 |
L: m2 duplicate
m1 .. m2 .S bis .S
||
On Sunday, January 15, 2023 at 4:22:49 PM UTC+1, Hans Bezemer wrote:<SNIP>
Given all "easy options" it was just a shame not to make a complete
program of it:
: fixit >r 2dup isnote? if 2dup 1- chars + dup c@ r> + swap c! ;then rdrop ;
: Usage abort" Usage: notes -o<octave> infile outfile" ;At least you generate a practical facility, probably usable by other persons. Proof that you actually use Forth.
QED.
Hans Bezemer
On Friday, January 13, 2023 at 2:20:07 PM UTC+1, none albert wrote:
SCORE Vader-Jacob
DEFAULT: 112 /4 MM
INFO: Copyright AH & CH
PART one
\ PDEFAULT: GOLD
PDEFAULT: ORGAN 3 TRANSPOSE-UP L7
||: 4 /4 MEASURE
L: m1
/4 C3 D3 E3 C3 | duplicate
/4 E3 F3 /2 G3 | duplicate
/8 G3 A3 G3 F3 /4 E3 C3 | duplicate
/4 C3 G2 /2 C3 |
L: m2 duplicate
m1 .. m2 .S bis .S
||
Just to satisfy my curiosity, Albert - what IS this musical ASCII
format? Is it a standard? Doesn't resemble
Lillypond or ABC..
Hans Bezemer
That is a format invented by Dutch Forth to play the tingle tangle and
the organ. It went through numerous formats, and I collected them in 2002
and invent a new format, hence the conversions.
There is a demonstration on youtube that has been published here a
number of times. (hcc tingel tangel).
You have me convinced that you could do it easily with the tools youThank you! From your mouth that actually means something. :)
have.
I'm equally convinced that I'm using less tools, and do it more easily,Well - look at it this way. All include files are actually inlined. So, when compiled
on the premise that you need to have familiarity with the tools.
The decision to implement regular expression, on behalf of the score conversion, was the right one, I think.
I know it is. But - as I said - I've taken the simple route. All the way ;-): fixit >r 2dup isnote? if 2dup 1- chars + dup c@ r> + swap c! ;then rdrop ; That is -- date I say this -- a bit ugly. But in the original solutionthat was more ugly, separating out the cases by hand.
"(<[A-Ga-g][eisEIS]*)2>" "\11" GLOBAL
"(<[A-Ga-g][eisEIS]*)3>" "\12" GLOBAL
"(<[A-Ga-g][eisEIS]*)4>" "\13" GLOBAL
"(<[A-Ga-g][eisEIS]*)5>" "\14" GLOBAL
"(<[A-Ga-g][eisEIS]*)6>" "\15" GLOBAL
On Friday, January 13, 2023 at 7:20:07 AM UTC-6, none albert wrote:This would have been clearer:
"(<[A-Ga-g][eisEIS]*)2>" "\11" GLOBAL
"(<[A-Ga-g][eisEIS]*)3>" "\12" GLOBAL
"(<[A-Ga-g][eisEIS]*)4>" "\13" GLOBAL
"(<[A-Ga-g][eisEIS]*)5>" "\14" GLOBAL
"(<[A-Ga-g][eisEIS]*)6>" "\15" GLOBAL
Just a FYI should someone missed what's going on:
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 50:11:57 |
Calls: | 6,711 |
Calls today: | 4 |
Files: | 12,243 |
Messages: | 5,354,922 |
Posted today: | 1 |