Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #2162
| From | "Costello, Roger L." <costello@mitre.org> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: Best language for implementing compilers? |
| Date | 2019-02-12 17:27 +0000 |
| Organization | Compilers Central |
| Message-ID | <19-02-010@comp.compilers> (permalink) |
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]
Back to comp.compilers | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Best language for implementing compilers? "Costello, Roger L." <costello@mitre.org> - 2019-02-12 17:27 +0000 Re: Best language for implementing compilers? Kaz Kylheku <157-073-9834@kylheku.com> - 2019-02-12 23:52 +0000
csiph-web