Re: [racket-dev] feature request: gcd, lcm for rationals

2011-12-09 Thread Carl Eastlund
What does divides even mean in Q?  I think we need David to explain
what his extension of GCD and LCM means here, in that divisors and
multiples are fairly trivial things in Q.

Carl Eastlund

On Fri, Dec 9, 2011 at 3:08 PM, J. Ian Johnson i...@ccs.neu.edu wrote:
 What? The greatest common divisor would definitely not divide 1, unless it 
 truly were 1.
 -Ian
 - Original Message -
 From: Jens Axel Søgaard jensa...@soegaard.net
 To: David Van Horn dvanh...@ccs.neu.edu
 Cc: Racket Dev List dev@racket-lang.org
 Sent: Friday, December 9, 2011 2:04:46 PM GMT -05:00 US/Canada Eastern
 Subject: Re: [racket-dev] feature request: gcd, lcm for rationals




 One definition of greatest common divisor in a ring R is:
 d is a greatest common divisor of x and y when:
 i) d divides both x and y
 ii) If e is a divisor of both x and y, then d divides e


 Now let's consider the ring Q. Since Q is a field, 1 divides all elements.


 This implies that 1 is a greatest common divisor of any non-zero x and y.
 ( ad i) 1 is a divisor of both x and y
 ad ii) 1 is a divisor of e )


 It is therefore not obvious that gcd should be extendend as you suggest.
 But maybe we can finde another name for the operation?


 /Jens Axel



 2011/12/7 David Van Horn  dvanh...@ccs.neu.edu 


 It would be nice if gcd and lcm were extended to rational numbers, which 
 seems in-line with Scheme's philosophy (but not standards) on numbers.

 (define (gcd-rational . rs)
 (/ (apply gcd (map numerator rs))
 (apply lcm (map denominator rs

 (define (lcm-rational . rs)
 (/ (abs (apply * rs))
 (apply gcd-rational rs)))

 David

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] feature request: gcd, lcm for rationals

2011-12-09 Thread Daniel King
On Fri, Dec 9, 2011 at 15:27, Carl Eastlund c...@ccs.neu.edu wrote:
 What does divides even mean in Q?  I think we need David to explain
 what his extension of GCD and LCM means here, in that divisors and
 multiples are fairly trivial things in Q.

I don't suppose to understand all the math on this page, but I think
it uses the same definition that dvh is using.

http://mathworld.wolfram.com/GreatestCommonDivisor.html

-- 
Dan King
College of Computer and Information Science
Northeastern University

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] [racket-bug] all/12434: match fails to signal type error?

2011-12-09 Thread Jay McCarthy
This is now the fourth time I've seen people ask about this.

Why can't Typed Racket be a little different than Racket and have another
match form that does this or a notion of disjoint unions?

You've said many times that TR is for converting Racket programs, but
clearly some of us want to write quasi-ML in TR, but we can't without hacks
like this.

Jay

On Fri, Dec 9, 2011 at 1:29 PM, Sam Tobin-Hochstadt sa...@ccs.neu.eduwrote:

 I think what you're asking for is static errors for coverage failures
 in `match' when used in Typed Racket.

 There are two reasons this isn't something I'm planning on doing in
 general:
 1. It would be a significant change from the semantics of `match' in
 Racket, which as you note raises a runtime error.
 2. It's unlikely to be precise enough in enough cases to be useful.
 `match' is just too flexible, and TR insufficiently smart, for this to
 be the right default.

 However, for this purpose, Typed Racket provides the `typecheck-fail'
 form [1], for raising explicit type errors.  Rewrite your match
 expression to:

 (match f
[(list s) #true]
 [_ (typecheck-fail #'here #:covered-id f)])

 and you get the error message:
  Type Checker: Incomplete case coverage; missing coverage of Foo

 [1]
 http://pre.racket-lang.org/docs/html/ts-reference/Utilities.html?q=type-e#%28form._%28%28lib._typed-racket/base-env/prims..rkt%29._typecheck-fail%29%29

 On Fri, Dec 9, 2011 at 3:20 PM,  cleme...@brinckerhoff.org wrote:
  *** Description:
  Code using match to take apart opaque types
  signal runtime match failure rather than
  a type-checking failure.



 --
 sam th
 sa...@ccs.neu.edu




-- 
Jay McCarthy j...@cs.byu.edu
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

The glory of God is Intelligence - DC 93
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

[racket-dev] error using local-expand

2011-12-09 Thread Stephen Chang
Say I have the following program:


#lang racket

(define-for-syntax (loc-expand stx) (local-expand stx 'expression '()))

(define-syntax (my-begin stx)
  (syntax-case stx ()
[(_ e ...)
 (with-syntax ([(x ...) (map loc-expand (syntax-list #'(e ...)))])
   #'(begin x ...))]))

(define-syntax (my-lambda1 stx)
  (syntax-case stx ()
[(_ args body ...)
 #'(lambda args (my-begin body ...))]))

(define-syntax (my-lambda2 stx)
  (syntax-case stx ()
[(_ args body ...)
 (with-syntax ([(x ...) (map loc-expand (syntax-list #'(body ...)))])
 #'(lambda args (begin x ...)))]))


An expression (my-lambda1 (y) (+ y 1)) works fine but (my-lambda2 (y)
(+ y 1)) produces the error:

expand: unbound identifier in module in: y


I can't figure out why this is the case. Anyone know?
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] error using local-expand

2011-12-09 Thread Sam Tobin-Hochstadt
On Fri, Dec 9, 2011 at 4:53 PM, Stephen Chang stch...@ccs.neu.edu wrote:
 Say I have the following program:


 #lang racket

 (define-for-syntax (loc-expand stx) (local-expand stx 'expression '()))

 (define-syntax (my-begin stx)
  (syntax-case stx ()
    [(_ e ...)
     (with-syntax ([(x ...) (map loc-expand (syntax-list #'(e ...)))])
       #'(begin x ...))]))

 (define-syntax (my-lambda1 stx)
  (syntax-case stx ()
    [(_ args body ...)
     #'(lambda args (my-begin body ...))]))

`my-lambda1' does the local expansion after the `lambda' form
introduces the bindings from `args' into the environment.


 (define-syntax (my-lambda2 stx)
  (syntax-case stx ()
    [(_ args body ...)
     (with-syntax ([(x ...) (map loc-expand (syntax-list #'(body ...)))])
     #'(lambda args (begin x ...)))]))

`my-lambda2' does the local expansion before the `lambda' form
introduces the bindings from `args' into the environment, meaning that
there's no binding yet for any of the arguments.


 An expression (my-lambda1 (y) (+ y 1)) works fine but (my-lambda2 (y)
 (+ y 1)) produces the error:

    expand: unbound identifier in module in: y


 I can't figure out why this is the case. Anyone know?
 _
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev



-- 
sam th
sa...@ccs.neu.edu

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] [racket-bug] all/12434: match fails to signal type error?

2011-12-09 Thread Matthias Felleisen

On Dec 9, 2011, at 3:32 PM, Jay McCarthy wrote:

 but clearly some of us want to write quasi-ML in TR, but we can't without 
 hacks like this.


ML's match plays a very different role in the process of type inference. We 
would have to change the language in HUGE way. 

If you really want quasi-ML, consider implementing the 17th version of 
parenthesized ML. Everyone who did abandoned it eventually. Perhaps that's a 
hint. 


_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] feature request: gcd, lcm for rationals

2011-12-09 Thread Stephen Bloch

On Dec 9, 2011, at 3:31 PM, Daniel King wrote:

 On Fri, Dec 9, 2011 at 15:27, Carl Eastlund c...@ccs.neu.edu wrote:
 What does divides even mean in Q?  I think we need David to explain
 what his extension of GCD and LCM means here, in that divisors and
 multiples are fairly trivial things in Q.
 
 I don't suppose to understand all the math on this page, but I think
 it uses the same definition that dvh is using.
 
 http://mathworld.wolfram.com/GreatestCommonDivisor.html

Interesting: the Mathematica people have extended the gcd function from the 
integers to the rationals, not by applying the usual definition of gcd to Q 
(which would indeed be silly, as everything except 0 divides everything else), 
but by coming up with a different definition which, when restricted to 
integers, happens to coincide with the usual definition of gcd.

I would wonder: is this the ONLY reasonable function on rationals which, when 
restricted to integers, coincides with the usual definition of gcd?


Stephen Bloch
sbl...@adelphi.edu


_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev