From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: John Prevost <prevost@maya.com>
Cc: caml-list@inria.fr
Subject: Re: Labels and operators
Date: Sat, 24 Jun 2000 16:44:20 +0200 [thread overview]
Message-ID: <20000624164420.B5164@miss.wu-wien.ac.at> (raw)
In-Reply-To: <87bt0y71f9.fsf@isil.localdomain>; from prevost@maya.com on Mon, Jun 19, 2000 at 00:14:02 -0400
On Mon, 19 Jun 2000, John Prevost wrote:
> A friend of mine recently said "if ML had regexp stuff that was as
> convenient as Perl, I'd switch to it for everything", and mentioned =~
> as something he specifically wanted. So, as I was walking home
> tonight, I thought "hey, I bet I could make some little operators for
> the PCRE library and show him!"
The "=~"-operator itself, as it is normally used in Perl for matching,
is fairly easy to replicate:
let (=~) str pat = Pcre.pmatch ~pat str
let _ =
print_endline (if read_line () =~ "foo" then "has foo!" else "no foo!")
> But, it also occurred to me that you want to use the nice labelled
> optional argument stuff, and I wasn't sure you could do that with
> operators. Here's what I've discovered.
Well, sometimes we are really struck by the only "two-dimensional" way
in which we can write our sources (top-down + left-right). If we could
write into the depth, there would be an elegant solution for adding
arguments to infix operators...
> The only solution I can think of is something like:
[snip]
> # "foo" =~ re "f";;
> - : bool = true
> # "foo" =~ re "f" ~pos:1;;
> - : bool = false
>
> Which, well, works, but seems kind of nasty.
I normally try to avoid new operators, but if I wanted to have a somewhat
"powered up" version of "=~", your version here would look fine to me -
just read every piece aloud:
"foo" =~ re "f" ~pos:1
"foo" - is matched by - regular expression - "f" - at position one
This is pretty close to the human way of expressing things. (Larry Wall,
the linguist, would be proud of you! ;-)
> since the labelled args could not in any way shape or form be thought
> to go with either expr1 or expr2. This would lead to things like:
>
> # "foo" =~ ~pos:1 "f";;
> - : bool = false
>
> being possible. Don't know whether it's a great idea, though.
I prefer your first version: "subject", "verb" and "object" are close
together, the additional modifiers only follow afterwards. To my
knowledge, most natural languages would order expressions like this.
Best regards,
Markus Mottl
--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
next prev parent reply other threads:[~2000-06-26 10:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-06-19 4:14 John Prevost
2000-06-22 1:48 ` Ken Wakita
2000-06-22 5:19 ` Jacques Garrigue
2000-06-24 14:44 ` Markus Mottl [this message]
2000-06-24 18:03 ` John Prevost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20000624164420.B5164@miss.wu-wien.ac.at \
--to=mottl@miss.wu-wien.ac.at \
--cc=caml-list@inria.fr \
--cc=prevost@maya.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox