Re: Best language for implementing compilers?

"Costello, Roger L." <costello@mitre.org>
Tue, 12 Feb 2019 17:27:11 +0000

          From comp.compilers

Related articles
[2 earlier articles]
Re: Best language for implementing compilers? gneuner2@comcast.net (George Neuner) (2019-02-08)
Re: Best language for implementing compilers? robin51@dodo.com.au (Robin Vowels) (2019-02-09)
Re: Best language for implementing compilers? bc@freeuk.com (Bart) (2019-02-11)
Best language for implementing compilers? davidlovemore@gmail.com (David Lovemore) (2019-02-12)
Re: Best language for implementing compilers? drb@ihatespam.msu.edu (2019-02-12)
Re: Best language for implementing compilers? 157-073-9834@kylheku.com (Kaz Kylheku) (2019-02-12)
Re: Best language for implementing compilers? costello@mitre.org (Costello, Roger L.) (2019-02-12)
Re: Best language for implementing compilers? 157-073-9834@kylheku.com (Kaz Kylheku) (2019-02-12)
Re: Best language for implementing compilers? drb@ihatespam.msu.edu (2019-02-19)
Re: Best language for implementing compilers? martin@gkc.org.uk (Martin Ward) (2019-02-19)
Re: Best language for implementing compilers? arnold@skeeve.com (2019-02-20)
Re: Best language for implementing compilers? mertesthomas@gmail.com (2019-03-09)
Re: Best language for implementing compilers? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2019-03-09)
[15 later articles]
| List of all articles for this month |

From: "Costello, Roger L." <costello@mitre.org>
Newsgroups: comp.compilers
Date: Tue, 12 Feb 2019 17:27:11 +0000
Organization: Compilers Central
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="53857"; mail-complaints-to="abuse@iecc.com"
Keywords: ML, comment
Posted-Date: 12 Feb 2019 12:53:07 EST

Kaz Kylheku wrote:
-------------------------------------------------
Suppose we want to check whether we have an expression that is the binary
product of two binary sums, as in (* (+ a b) (+ c d)).


Without pattern matching:


  (when (and (eq (car expr) '*) ;; starts with *
                        (consp (cdr expr)) ;; has an argument
                        (consp (cddr expr)) ;; has another argument
                        (null (cdddr expr)) ;; then the list ends
                        (consp (cadr expr)) ;; first arg is a compound
                        (eq (cadr expr) '+) ;; ... starting with a +
                        ... ;; etc
      (do-whatever ...))


With very rudimentary pattern matching (simple destructuring):


  (destructuring-when (op1 (op2 a b) (op3 c d)) expr
      (when (equal (list op1 op2 op3) '(* + +))
          (do-whatever ...)))


With pattern matching:


  (when-match expr (* (+ ?a ?b) (+ ?c ?d))
      (do-whatever ...) ;; ?a ?b ... are in scope bound to subtrees
      ...)
-------------------------------------------------
Wow!


That is a fantastic example.


Are there programming languages that have the pattern matching capability
shown in Kaz's last example?


What programming language has the best pattern matching capability?


Is the programming language with the best pattern matching capability the best
language for implementing compilers?


/Roger
[Why do you think we're talking about ML? It has matching as a
primitive. I don't recall any lisp-ish languages with built in tree
matchers but it's easy enough to do that it's often an exercise in the
introductory programming class. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.