Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-12

My favourite missing feature

25 messages · 11 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

There seem to be a number of people currently making outrageous suggestions about missing features or how FPC could best be repackaged and promoted, so since it's the season of good will I trust that folk will tolerate this one from me.

There's been a recent thread in fpc-other on second languages, but it appeared to focus more on what was a useful part of a developer's skillset rather than what people miss from Pascal.

What /I/ miss is Perl's pattern matching, and I miss it to the extent that in some of my own scripting stuff I've implemented it myself:

IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN BEGIN
   cells[6, 1]:= /1/ + ordinalSuffix(/1/);
   cells[7, 1]:= monthName(/2/);
   IF /3/ > 999 THEN
     cells[8, 1]:= /3/
   ELSE
     cells[8, 1]:= '20' + /3/
END;

I knew nobody'd like it- I'll get my coat.

Merry Christmas and a happy New Year, everybody :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Frank de Groot (Rent-a-Geek
to Mark Morgan Lloyd

There are RexExp units available..

What /I/ miss is Perl's pattern matching, and I miss it to the extent that in some of my own scripting stuff I've implemented it myself:
Mark Morgan Lloyd
to Frank de Groot (Rent-a-Geek
Frank de Groot wrote
> What /I/ miss is Perl's pattern matching, and I miss it to the extent > that in some of my own scripting stuff I've implemented it myself: There are RexExp units available..

I know- you don't really think I've written the code from scratch do you? The issue is the convenience of being able to embed regexes and backrefs in the language rather than the availability of suitable units.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Marco van de Voort
to Mark Morgan Lloyd: There seem to be a number of people currently making outrageous suggestions about missing…

In our previous episode, Mark Morgan Lloyd said:

Show quoted text 15 lines
What /I/ miss is Perl's pattern matching, and I miss it to the extent that in some of my own scripting stuff I've implemented it myself: IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN BEGIN cells[6, 1]:= /1/ + ordinalSuffix(/1/); cells[7, 1]:= monthName(/2/); IF /3/ > 999 THEN cells[8, 1]:= /3/ ELSE cells[8, 1]:= '20' + /3/ END; I knew nobody'd like it- I'll get my coat. Merry Christmas and a happy New Year, everybody :-)

Well, at least it starts with a laugh :)

Mark Morgan Lloyd
to Henry Vermaak
Henry Vermaak wrote 5 lines
2008/12/22 Mark Morgan Lloyd : > .........>8 > IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN BEGIN i thought for a moment you were trying to draw some nice ascii art :)

"Leaning toothpick syndrome" :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
ik
to Mark Morgan Lloyd: There seem to be a number of people currently making outrageous suggestions about missing…

Your regex is awful :)

Why not to write it as follows (ruff rewrite):

IF cells[2, dateTime] = m|((\d\d)/){2}(\d{2,4})\s.*| THEN BEGIN

Anyway, I'm not sure how good idea it will be to have it part of the syntax.

Happy Hannuka everyone :P

Ido

On Mon, Dec 22, 2008 at 7:56 PM, Mark Morgan Lloyd <

Show quoted text 36 lines
wrote: There seem to be a number of people currently making outrageous suggestions about missing features or how FPC could best be repackaged and promoted, so since it's the season of good will I trust that folk will tolerate this one from me. There's been a recent thread in fpc-other on second languages, but it appeared to focus more on what was a useful part of a developer's skillset rather than what people miss from Pascal. What /I/ miss is Perl's pattern matching, and I miss it to the extent that in some of my own scripting stuff I've implemented it myself: IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN BEGIN cells[6, 1]:= /1/ + ordinalSuffix(/1/); cells[7, 1]:= monthName(/2/); IF /3/ > 999 THEN cells[8, 1]:= /3/ ELSE cells[8, 1]:= '20' + /3/ END; I knew nobody'd like it- I'll get my coat. Merry Christmas and a happy New Year, everybody :-) -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marc Weustink
to Mark Morgan Lloyd: There seem to be a number of people currently making outrageous suggestions about missing…
Mark Morgan Lloyd wrote 13 lines
There seem to be a number of people currently making outrageous suggestions about missing features or how FPC could best be repackaged and promoted, so since it's the season of good will I trust that folk will tolerate this one from me. There's been a recent thread in fpc-other on second languages, but it appeared to focus more on what was a useful part of a developer's skillset rather than what people miss from Pascal. What /I/ miss is Perl's pattern matching, and I miss it to the extent that in some of my own scripting stuff I've implemented it myself: IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN BEGIN

and now in plain english, what does it match ?

Marc

ik
to Marc Weustink

It looks for a date pattern like the follow

10/10/08 and 10/10/2008 with space and then some other chars as well.

I think if it was with boundaries of begin and/or end (^ and $) it would work even better.

The () indicates groups. each group is the string extracted from the pattern, and can be used (that's the /1/ and /2/ that he wrote).

This entire thingy called regular expression or regex for short.

Ido

Marc Weustink wrote 26 lines
Mark Morgan Lloyd wrote: > There seem to be a number of people currently making outrageous > suggestions about missing features or how FPC could best be repackaged and > promoted, so since it's the season of good will I trust that folk will > tolerate this one from me. > > There's been a recent thread in fpc-other on second languages, but it > appeared to focus more on what was a useful part of a developer's skillset > rather than what people miss from Pascal. > > What /I/ miss is Perl's pattern matching, and I miss it to the extent that > in some of my own scripting stuff I've implemented it myself: > > IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN BEGIN > and now in plain english, what does it match ? Marc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Mattias Gaertner
to ik
Show quoted text 38 lines
It looks for a date pattern like the follow 10/10/08 and 10/10/2008 with space and then some other chars as well. I think if it was with boundaries of begin and/or end (^ and $) it would work even better. The () indicates groups. each group is the string extracted from the pattern, and can be used (that's the /1/ and /2/ that he wrote). This entire thingy called regular expression or regex for short. Ido On Wed, Dec 24, 2008 at 1:17 AM, Marc Weustink wrote: > Mark Morgan Lloyd wrote: > >> There seem to be a number of people currently making outrageous >> suggestions about missing features or how FPC could best be >> repackaged and promoted, so since it's the season of good will I >> trust that folk will tolerate this one from me. >> >> There's been a recent thread in fpc-other on second languages, but >> it appeared to focus more on what was a useful part of a >> developer's skillset rather than what people miss from Pascal. >> >> What /I/ miss is Perl's pattern matching, and I miss it to the >> extent that in some of my own scripting stuff I've implemented it >> myself: >> >> IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN >> BEGIN >> > > and now in plain english, what does it match ?

see also
http://wiki.lazarus.freepascal.org/IDE_regular_expressions

Mattias

Marc Weustink
to Mattias Gaertner
Mattias Gaertner wrote 43 lines
On Wed, 24 Dec 2008 01:41:16 +0200 ik wrote: > It looks for a date pattern like the follow > > 10/10/08 and 10/10/2008 with space and then some other chars as well. > > I think if it was with boundaries of begin and/or end (^ and $) it > would work even better. > > The () indicates groups. each group is the string extracted from the > pattern, and can be used (that's the /1/ and /2/ that he wrote). > > This entire thingy called regular expression or regex for short. > > Ido > > > On Wed, Dec 24, 2008 at 1:17 AM, Marc Weustink > wrote: > >> Mark Morgan Lloyd wrote: >> >>> There seem to be a number of people currently making outrageous >>> suggestions about missing features or how FPC could best be >>> repackaged and promoted, so since it's the season of good will I >>> trust that folk will tolerate this one from me. >>> >>> There's been a recent thread in fpc-other on second languages, but >>> it appeared to focus more on what was a useful part of a >>> developer's skillset rather than what people miss from Pascal. >>> >>> What /I/ miss is Perl's pattern matching, and I miss it to the >>> extent that in some of my own scripting stuff I've implemented it >>> myself: >>> >>> IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN >>> BEGIN >>> >> and now in plain english, what does it match ? see also http://wiki.lazarus.freepascal.org/IDE_regular_expressions

I know what regular expressions are, I know that when you are writing them, you understand what you wanted to do, but 5 mins later you don't know anymore what it meant, let alone how to debug.

(no it wasn't a serious question)

Marc

ik
to Marc Weustink
Marc Weustink wrote 51 lines
Mattias Gaertner wrote: > On Wed, 24 Dec 2008 01:41:16 +0200 > ik wrote: > > It looks for a date pattern like the follow >> >> 10/10/08 and 10/10/2008 with space and then some other chars as well. >> >> I think if it was with boundaries of begin and/or end (^ and $) it >> would work even better. >> >> The () indicates groups. each group is the string extracted from the >> pattern, and can be used (that's the /1/ and /2/ that he wrote). >> >> This entire thingy called regular expression or regex for short. >> >> Ido >> >> >> On Wed, Dec 24, 2008 at 1:17 AM, Marc Weustink >> wrote: >> >> Mark Morgan Lloyd wrote: >>> >>> There seem to be a number of people currently making outrageous >>>> suggestions about missing features or how FPC could best be >>>> repackaged and promoted, so since it's the season of good will I >>>> trust that folk will tolerate this one from me. >>>> >>>> There's been a recent thread in fpc-other on second languages, but >>>> it appeared to focus more on what was a useful part of a >>>> developer's skillset rather than what people miss from Pascal. >>>> >>>> What /I/ miss is Perl's pattern matching, and I miss it to the >>>> extent that in some of my own scripting stuff I've implemented it >>>> myself: >>>> >>>> IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN >>>> BEGIN >>>> >>>> and now in plain english, what does it match ? >>> >> > see also > http://wiki.lazarus.freepascal.org/IDE_regular_expressions > I know what regular expressions are, I know that when you are writing them, you understand what you wanted to do, but 5 mins later you don't know anymore what it meant, let alone how to debug.

Funny, I'm not the original writer of the regex code, but I understood it. It's just another language for text patterns, that's all. A more complicated regex is harder to understand with that one I can agree, but like with Pascal, if you learn the language (and not only the syntax), you can understand most good written patterns.

Ido

Show quoted text 11 lines
(no it wasn't a serious question) Marc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
S. Fisher
to Mark Morgan Lloyd: There seem to be a number of people currently making outrageous suggestions about missing…
Mark Morgan Lloyd wrote 20 lines
There's been a recent thread in fpc-other on second languages, but it appeared to focus more on what was a useful part of a developer's skillset rather than what people miss from Pascal. What /I/ miss is Perl's pattern matching, and I miss it to the extent that in some of my own scripting stuff I've implemented it myself: IF cells[2, dateTime] = /(\d\d)\/(\d\d)\/((\d\d)?\d\d)\s.*/i THEN BEGIN cells[6, 1]:= /1/ + ordinalSuffix(/1/); cells[7, 1]:= monthName(/2/); IF /3/ > 999 THEN cells[8, 1]:= /3/ ELSE cells[8, 1]:= '20' + /3/ END;

That regular expression can be made less terrifying to tyros by using extended mode in Ruby. We can include whitespace and even comments.

match_data =
"a day to remember: 31/08/2008 ".match(
# Start the regex with %r{ so we can use / without escaping it. %r{

      # The date begins with 2 digits for the day;
      # enclose them in () to capture them for later use.
      (\d\d)
      # A separator.
      /
      # The month is 2 digits or numerals.
      (\d\d)
      # The separator.
      /
      (
        # The year can be 4 digits or 2 digits.
        # Now the parentheses are for grouping;
        # we don't care whether they capture or not.
        (\d\d) ?  # The question mark means preceding item is optional.
        \d\d
      )
      # Our dates must always be followed by whitespace.
      # It can be a space, tab, carriage-return, or linefeed.
      \s
    }x  # End of the regex. The x calls for extended mode.

)

# Our captures are strings; convert them to integers and assign # them to our variables.
day,month,year = match_data.captures.map{|s| s.to_i } # Print results.
p day, month, year

To use grep, sed, awk, or a text editor effectively, one must understand regular expressions. Anyone who doesn't, isn't a power user. Even some users of Mickeysoft Word use regular expressions for searching. Ask yourself this: do you want to be less computer-literate than users of Mickey's software?

To refuse to learn regular expressions because they are cryptic before you learn them is like refusing to learn English because it is cryptic before you learn it.

Mark Morgan Lloyd
to Mattias Gaertner: On Wed, 24 Dec 2008 01:41:16 +0200 see also http://wiki.lazarus.freepascal.org/IDE_regular…
Mattias Gaertner wrote

Also http://regexpstudio.com/TRegExpr/Help/regexp_syntax.html which is the one I use with Delphi, not sure whether it's related to the one that FPC bundles.

I think I could have used a better example- all those \d are a bit offputting- but I wanted something from live code and wanted it to be non-trivial.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Jürgen Hestermann
to S. Fisher: That regular expression can be made less terrifying to tyros by using extended mode in…
To use grep, sed, awk, or a text editor effectively, one must understand regular expressions.

Maybe. I never used them (except a text editor of course). Everything you can do with these tools is also possible with a good Pascal compiler (and much more). So why waste time on learning another language that is only a subset of the language you already know?

Anyone who doesn't, isn't a power user.

Just the opposite. All the time you utilize on learning Regex could have been better invested in learning Pascal even better.

To refuse to learn regular expressions because they are cryptic before you learn them is like refusing to learn English because it is cryptic before you learn it.

No. The metaphor for learnig Regex would be that you try to learn yet another foreign language (addtionally to English) so that you have less time learning English.

Jürgen Hestermann.

Mark Morgan Lloyd
to Jürgen Hestermann
Jürgen Hestermann wrote 6 lines
> To use grep, sed, awk, or a text editor effectively, one must > understand regular expressions. Maybe. I never used them (except a text editor of course). Everything you can do with these tools is also possible with a good Pascal compiler (and much more).

Very true, I'd not deny that for a moment. However what's better: a single regex expressing a pattern to underlying well-tested code or ten lines of "classic" Pascal doing the same job? Cryptic though regular expressions are I'd suggest that the latter case has far more scope for coding error or for misinterpretation by a maintainer.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Frank de Groot (Rent-a-Geek
to Mark Morgan Lloyd

I agree with Jürgen.

It's is much more preferable to write standard Pascal, for many reasons:

1. The number of people proficient in RegExes is very small, and it takes regular practice to keep the skill up.
Very bad to be dependent on such a subset of Pascal programmers.

2. RegExes are notoriously difficult to debug, even for experts.

3. You become dependent on yet another external library (and possible bugs).

4. RegExes, especially complex ones, are usually orders of magnitude slower than straight Pascal, because they're usually interpreted at runtime by a parser.

Earlier message 9 lines
----- Original Message ----- From: "Mark Morgan Lloyd" > However what's better: a single regex expressing a pattern to underlying > well-tested code or ten lines of "classic" Pascal doing the same job? > Cryptic though regular expressions are I'd suggest that the latter case > has far more scope for coding error or for misinterpretation by a > maintainer.
ik
to Jürgen Hestermann: Maybe. I never used them (except a text editor of course). Everything you can do with…

http://ik.homelinux.org/

On Wed, Dec 24, 2008 at 12:56 PM, Jürgen Hestermann <

Show quoted text 10 lines
wrote: To use grep, sed, awk, or a text editor effectively, one must > understand regular expressions. > Maybe. I never used them (except a text editor of course). Everything you can do with these tools is also possible with a good Pascal compiler (and much more). So why waste time on learning another language that is only a subset of the language you already know?

First of all it's a another tool, and if you are using it correctly, it is faster and more efficient then using pos, copy and looping across each char on your own, because the code is very optimized and reduce your work when parsing for patterns. It is bad practice when you use it for non pattern usage, or when you know the exact location and length of each sub string you wish to extract. Otherwise it only makes life more easier imho.

Show quoted text 16 lines
Anyone who doesn't, isn't a power user. > Just the opposite. All the time you utilize on learning Regex could have been better invested in learning Pascal even better. To refuse to learn regular expressions because they are cryptic > before you learn them is like refusing to learn English because > it is cryptic before you learn it. > No. The metaphor for learnig Regex would be that you try to learn yet another foreign language (addtionally to English) so that you have less time learning English.

Amm, The metaphor should be learning a new rule in the English language to use the English language better.

Show quoted text 9 lines
Jürgen Hestermann. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Mark Morgan Lloyd
to Frank de Groot (Rent-a-Geek: I agree with Jürgen. It's is much more preferable to write standard Pascal, for many…
Frank de Groot wrote
1. The number of people proficient in RegExes is very small, and it takes regular practice to keep the skill up. Very bad to be dependent on such a subset of Pascal programmers.

I am very sorry, but your logic is bad there. A high proportion of unix users have at least basic familiarity with regexes. The majority of C or C++ programmers, particularly working under unix, are familiar with them. The reason that comparatively few Pascal programmers are familiar with them is because they are not widely used in Pascal.

Your argument could have been applied against including generics, polymorphic functions or streams into Pascal: before they were implemented few people were familiar with them.

3. You become dependent on yet another external library (and possible bugs).

But part of the strength of Pascal is that it is a comparatively small language with most non-core features implemented as libraries- one obvious example being objpas.

4. RegExes, especially complex ones, are usually orders of magnitude slower than straight Pascal, because they're usually interpreted at runtime by a parser.

They could possibly be preprocessed if assigned to a constant, although I've not tried doing this.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Frank de Groot (Rent-a-Geek
to Mark Morgan Lloyd
Show quoted text 6 lines
> 4. RegExes, especially complex ones, are usually orders of magnitude > slower than straight Pascal, because they're usually interpreted at > runtime by a parser. They could possibly be preprocessed if assigned to a constant, although I've not tried doing this.

If you modify the RegExp-parsing source code AND implement it in the FPC compiler sources to do that, sure.

Marco van de Voort
to Mark Morgan Lloyd: Very true, I'd not deny that for a moment. However what's better: a single regex…

In our previous episode, Mark Morgan Lloyd said:

Show quoted text 9 lines
> Maybe. I never used them (except a text editor of course). Everything > you can do with these tools is also possible with a good Pascal compiler > (and much more). Very true, I'd not deny that for a moment. However what's better: a single regex expressing a pattern to underlying well-tested code or ten lines of "classic" Pascal doing the same job? Cryptic though regular expressions are I'd suggest that the latter case has far more scope for coding error or for misinterpretation by a maintainer.

I don't see that. Worse, even if there was something to it, I don't see how one you can assume to make less mistakes in a second language you don't use everyday than in the language that you do use everyday.

The pinnacle of Regex madness seems to be compiled regex. The syntax is so terse because it had to be interpreted. "compiler regex" as in the Ruby example with comments is pretty much an oxymoron.

Marco van de Voort
to Mark Morgan Lloyd: I am very sorry, but your logic is bad there. A high proportion of unix users have at…

In our previous episode, Mark Morgan Lloyd said:

Show quoted text 8 lines
Frank de Groot (Rent-a-Geek) wrote: > 1. The number of people proficient in RegExes is very small, and it > takes regular practice to keep the skill up. > Very bad to be dependent on such a subset of Pascal programmers. I am very sorry, but your logic is bad there. A high proportion of unix users have at least basic familiarity with regexes.

True. But mostly for trial and error interactive use in editors and simple scripts, and have no clue about doing them safely automated.

IMHO use in unattended programming is totally different.

C++ programmers, particularly working under unix, are familiar with them. The reason that comparatively few Pascal programmers are familiar with them is because they are not widely used in Pascal.

Most of them also only basic. There is a lot of bad code out there.

Your argument could have been applied against including generics, polymorphic functions or streams into Pascal: before they were implemented few people were familiar with them.

No. At least those come from the same realm. Regexes come from scripts and interactive use. Sure, they are used in other programs (like Spamassasin too), but crafting such ones is a truely black art.

Show quoted text 6 lines
> 4. RegExes, especially complex ones, are usually orders of magnitude > slower than straight Pascal, because they're usually interpreted at > runtime by a parser. They could possibly be preprocessed if assigned to a constant, although I've not tried doing this.

See previous message. If they are not directly interpreted, why bother with such terse syntax?

S. Fisher
to ik: http://ik.homelinux.org/ On Wed, Dec 24, 2008 at 12:56 PM, Jürgen Hestermann < First of…

Anyone who pretends to know how to use computers effectively must know how to use grep. (grep is available for Windoze.)

Let's say that you want to search all of the files in the current directory for lines that contain "foobar" or "foo bar" or "foo-bar", followed later in the line by "practise" or "practice", ignoring case.

grep -i "foo[ -]?bar.*practi[cs]e" *

The same regular expression could be used for searching in a text editor. Can you imagine hiring a "programmer" who doesn't even know how to perform searches in a text editor? Neither can I. And yet there are those who boast of this ignorance! Extremely disgusting.

Consider a four-year-old mamma's boy who has always worn shoes that are fastened with velcro. When his father tries to teach him how to tie shoe-laces, he pouts and cries and says "That's too hard! I want my velcro! Mommy never made me tie laces!"

A real programmer knows more than one language.
He knows, for example, that one can write a program to extract information from text files much more quickly in awk than in Pascal. That's what awk was designed for.

The fake programmers who know Pascal and nothing else refuse to learn anything new, saying: "The time I would spend learning regular expressions could be spent honing my Pascal skills."

The four-year-old mamma's boy refuses to learn to tie his shoe-laces, saying: "I'll get better and better at sticking the velcro together."

I wish that the Pascal community would be purged of the fake programmers who are pampered, smug, and self-indulgent and who refuse to learn new things. Perhaps then Pascal would become more practical and attractive to real programmers.

Jonas Maebe
to S. Fisher
S. Fisher wrote
I wish

that people would stop getting so derogatory and fired up about mundane things like whether or not someone else likes a particular programming language (and that goes for both sides of the "debate"). And that they'd stop over-generalising based on a couple of personal reactions, obviously only from the few people who feel so strongly about the topic (and possibly language advocacy in general) that they posted heated replies about it in the first place.

Anyway, this thread is now officially over, all further replies will be rejected.

And that's my Christmas gift to the list, happy holidays everyone!

Jonas
FPC mailing lists admin