[racket] Matching patterns of two function

From: Jos Koot (jos.koot at gmail.com)
Date: Fri Nov 30 09:13:55 EST 2012

What you are asking for seems like alpha congruence, but less restrictive.
How much less restrictive? That depends on you definition of "the same
pattern". In length you have "(car l)" and in length you have "1". Do they
have the same structure? That, of course depends on the definition of car
(it may have been redefined). If you suppose that commonly used functions
are not redefined, you might argue that both"car l" and "1" are atomic-like
things. So you need to define "atomic-like".
 
Consider also:
 
(define (flatten x)
 (cond
  ((null? x) '())
  ((pair? x) (append (flatten-helper (car x)) (flatten (cdr x))))
  (else (list x))))
 
(define flatten-helper flatten)
 
I suppose that in your opinion, flatten does not have the same structure as
sum and length. You need to know that (flatten-helper (car x)) is not
"atomic-like".
 
Just some thoughts, Jos

  _____  

From: users-bounces at racket-lang.org [mailto:users-bounces at racket-lang.org]
On Behalf Of Mohammad Mustaqeem
Sent: viernes, 30 de noviembre de 2012 9:24
To: users at racket-lang.org
Subject: [racket] Matching patterns of two function


I have a problem in matching the patterns of two functions. 
I want to match two function whether they are following the same pattern or
not?
e.g.
The "sum" function that computes the sum of all the elements of the list and
"length" function that computes the length of the list.
Here, we see that both the functions have same pattern.

(define (sum l)
  (cond[(empty? l)0]
       [else (+ (car l)(sum (cdr l)))]))

(define (length l)
  (cond[(empty? l)0]
       [else (+ 1(length (cdr l)))]))

How can we determine that both has same pattern or not?
I want to write a function that takes these functions as input and tells
whether they have same pattern or not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121130/247bc468/attachment.html>

Posted on the users mailing list.