Guppoc Soft | 14 Aug 07:37 2010
Picon

[racket] problems with struct datatype

Hi,

I'm trying to use the new struct datatype, but I keep getting the following error

struct: illegal use of signature form in: (struct posn (x y))

when defining the struct. The old way of defining a struct ((define-struct ...)) works though.

I'm running DrRacket version 5.0.1 on Ubuntu 10.2 that I built from source.

Any ideas on why the error occurs?




<div><p>Hi,<br><br>I'm trying to use the new struct datatype, but I keep getting the following error<br><br>struct: illegal use of signature form in: (struct posn (x y))<br><br>when defining the struct. The old way of defining a struct ((define-struct ...)) works though.<br><br>I'm running DrRacket version 5.0.1 on Ubuntu 10.2 that I built from source.<br><br>Any ideas on why the error occurs?<br><br><br><br><br></p></div>
Jon Rafkind | 14 Aug 07:01 2010
Picon

[racket] hack: implicit function arguments

  I came up with this little hack that lets you avoid giving an explicit 
argument list to functions. Arguments are discovered by usages of 
underscores followed by a number, like _1 and _2. Partly inspired by 
scala; sure to make your blood boil if you love hygiene.

;;; usage
(define/implicit foo1 (printf "~a ~a ~a\n" _8 _9 _8))
(foo1 5 12)

;;; code
#lang racket/base

(require (for-syntax racket/base
                      racket/list
                      syntax/parse
                      )
          racket/stxparam)

(define-syntax-rule (implicits all thing ...)
   (begin
     (define-syntax-parameter thing (lambda (stx)
                                   (raise-syntax-error #f (format "~a 
can only be used in a
  define/implicit function" 'thing))))
     ...
     (provide thing ...)
     (define-for-syntax all (list #'thing ...))))

(implicits all-implicits _1 _2 _3 _4 _5 _6 _7 _8 _9 _10)

(provide define/implicit lambda/implicit)
(define-syntax (lambda/implicit stx)
   (define (find-implicits stx)
     (define-syntax-class implicit
                          [pattern x:identifier
                                   #:when (ormap (lambda (y)
                                                   (free-identifier=? y 
#'x))
                                                 all-implicits)])
     (remove-duplicates
       (filter values
               (syntax-parse stx
                 [x:implicit (list #'x)]
                 [(x ...) (apply append (map find-implicits 
(syntax->list #'(x ...))))]
                 [else (list #f)]))
       free-identifier=?))
   (syntax-parse stx
     [(_ body ...)
      (define implicit-arguments (find-implicits stx))
      (with-syntax ([(new-arg ...) (generate-temporaries 
implicit-arguments)]
                    [(implicit ...) implicit-arguments])
        #'(lambda (new-arg ...)
            (syntax-parameterize ([implicit (make-rename-transformer 
#'new-arg)] ...)
                                 body ...)))]))

(define-syntax-rule (define/implicit name body ...)
                     (define name (lambda/implicit body ...)))

Christopher Bowron | 13 Aug 23:46 2010
Picon

[racket] Macros: "define" a variable with a transformed id

I'm trying to write a macro that takes in an id, and creates a
variable with a name based on id, and adds a string based on id into a
list.

If I have (define-filter-category foo), I want it to add
"CICategoryFoo" to the FILTER-CATEGORIES list as well as introduce a
binding for the variable filter-category-foo.  I have the part that
adds the string to the list, but I do not know how to manipulate the
id and introduce the variable.  Can anyone shed some light on this for
me?  Thanks

What I have so far:

(define FILTER-CATEGORIES empty)

(define (id->category-string n)
  (define (camel-case str)
    (regexp-replace* #rx"-" (string-titlecase str) ""))
  (string-append "CICategory" (camel-case (symbol->string n))))

(define (id->category-id n)
  (string->symbol (string-append "filter-category-" (symbol->string n))))

(define-syntax define-filter-category
  (syntax-rules ()
    ((_ id string)
     (begin
       ;;; FIXME: also (define ,id  string)
       (set! FILTER-CATEGORIES (cons string FILTER-CATEGORIES))))
    ((_ name)
     (define-filter-category
       (id->category-id (quote name))
       (id->category-string (quote name))))))

(define-filter-category distortion-effect)
(define-filter-category ...)

--

-- 
Christopher W. Bowron <chris@...>
[ Nothing is exciting if you know what the outcome will be ]
    - Joseph Campbell
Byron Gibson | 13 Aug 23:40 2010
Picon

[racket] Possible to install both plt-scheme from repo and racket from racket-lang.org?

Is it possible to install both of these, or do they overwrite parts of
each other?

--

-- 
Byron

--
I think I think, therefore I think I am.
The Configurator | 13 Aug 11:31 2010
Picon

[racket] Macros as a first class objects?

There must be great reasons why this would be horribly wrong, but why shouldn't macros and syntaxes be passed as first class objects, method parameters, return values etc.?


Note that I'm asking why it shouldn't and not why it's not. I'm talking about the theoretical possibility, not an actual implementation.
<div>
<p>There must be great reasons why this would be horribly wrong, but why shouldn't macros and syntaxes be passed as first class objects, method parameters, return values etc.?</p>
<div><br></div>
<div>Note that I'm asking why it shouldn't and not why it's not. I'm talking about the theoretical possibility, not an actual implementation.</div>
</div>
Will Kurt | 13 Aug 03:53 2010
Picon

[racket] question about foldl implementation

For a presentation I'm working on I've been implementing various higher order functions in javascript.


When trying to work out the proper foldl implementation I came across something interesting in Racket

> (foldl cons '() '(1 2 3 4))
(4 3 2 1)

> (foldl - 0 '(1 2 3 4))
2

However when I looked into various other implementations of foldl I came across very different behavior
Haskell's foldl seems to be implemented like this:
;;haskell-like definition
(define (foldl-haskell func accum lst)
  (if (null? lst)
      accum
      (foldl-haskell func (func accum (car lst)) (cdr lst))))

and yields these results:
> (foldl-haskell cons '() '(1 2 3 4))
((((() . 1) . 2) . 3) . 4)
> (foldl-haskell - 0 '(1 2 3 4))
-10

Unsure which was correct I broke out SICP which uses this definition:
;;sicp version
(define (fold-left op initial sequence)
  (define (iter result rest)
    (if (null? rest)
        result
        (iter (op result (car rest))
              (cdr rest))))
  (iter initial sequence))

with these results (same as the haskell-like version):
> (fold-left cons '() '(1 2 3 4))
((((() . 1) . 2) . 3) . 4)
> (fold-left - 0 '(1 2 3 4))
-10

So which of these is the canonical implementation of a left fold? Why the difference in Racket? 
For pure aesthetics I like the behavior of Racket in the case of cons, but for '-' the others seems to make more sense.

Any insight into this is greatly appreciated!

Thanks!
--Will Kurt
<div>
<p>For a presentation I'm working on I've been implementing various higher order functions in javascript.</p>
<div><br></div>
<div>When trying to work out the proper foldl implementation I came across something interesting in Racket</div>
<div><br></div>
<div>
<div>&gt; (foldl cons '() '(1 2 3 4))</div>
<div>(4 3 2 1)</div>
<div><br></div>
<div>&gt; (foldl - 0 '(1 2 3 4))</div>
<div>2</div>
</div>
<div><br></div>
<div>However when I looked into various other implementations of foldl I came across very different behavior</div>
<div>Haskell's foldl seems to be implemented like this:</div>
<div>
<div>;;haskell-like definition</div>
<div>(define (foldl-haskell func accum lst)</div>
<div>&nbsp;&nbsp;(if (null? lst)</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp;accum</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp;(foldl-haskell func (func accum (car lst)) (cdr lst))))</div>
</div>
<div><br></div>
<div>and yields these results:</div>
<div>
<div>&gt; (foldl-haskell cons '() '(1 2 3 4))</div>
<div>((((() . 1) . 2) . 3) . 4)</div>
<div>&gt; (foldl-haskell - 0 '(1 2 3 4))</div>
<div>-10</div>
<div>&gt;&nbsp;</div>
</div>
<div><br></div>
<div>Unsure which was correct I broke out SICP which uses this definition:</div>
<div>
<div>;;sicp version</div>
<div>(define (fold-left op initial sequence)</div>
<div>&nbsp;&nbsp;(define (iter result rest)</div>
<div>&nbsp;&nbsp; &nbsp;(if (null? rest)</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;result</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;(iter (op result (car rest))</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cdr rest))))</div>
<div>&nbsp;&nbsp;(iter initial sequence))</div>
</div>
<div><br></div>
<div>with these results (same as the haskell-like version):</div>
<div>
<div>&gt; (fold-left cons '() '(1 2 3 4))</div>
<div>((((() . 1) . 2) . 3) . 4)</div>
<div>&gt; (fold-left - 0 '(1 2 3 4))</div>
<div>-10</div>
<div>&gt;&nbsp;</div>
</div>
<div><br></div>
<div>So which of these is the canonical implementation of a left fold? Why the difference in Racket?&nbsp;</div>
<div>For pure aesthetics I like the behavior of Racket in the case of cons, but for '-' the others seems to make more sense.</div>
<div><br></div>
<div>Any insight into this is greatly appreciated!</div>
<div><br></div>
<div>Thanks!</div>
<div>--Will Kurt</div>
</div>
Jay McCarthy | 12 Aug 22:32 2010
Picon

[racket] DrDr requests: Hosts and Regression Tests

DrDr [1] has proven very useful for finding bugs across the core and
in particular on Linux. Unfortunately, it is doesn't do any tests on
PLaneT code, code that users are developing privately, and doesn't do
any testing on OSes other than Linux or distributions other than
Ubuntu. I would like to call on the community to help with this
problem.

1) Architectures, operating systems, distributions

I will buy equipment to run DrDr on Windows and Mac OS X. I would like
someone to help me set up a Windows build environment. I would also
like users to contribute either (a) a host [real or virtual machine]
to run tests on OR (b) a specification for a host [equipment to buy,
software to install, volunteering to install it] so I can slowly
acquire more test machines as funds are available.

2) Regression tests

I would like users to submit code that can be made public that DrDr
can continuously test. This will allow the developers to know when
changes will break user code. We can either figure out how to maintain
compatibility or we can work with the user to update the software.
Either way, users will know that there is a problem before they
actually download and try out a new release.

If you can't easily pare down some code in your system or are having
difficulty making an automated test suite, I'm happy to help you
develop it.

Please send host information, specs, and tests to me privately. Feel
free to discuss on the mailing list.

Jay

1. http://drdr.racket-lang.org/

--

-- 
Jay McCarthy <jay@...>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93
Neil Toronto | 12 Aug 22:11 2010
Picon

[racket] Polymorphic occurrence typing

Are there any plans for it? Would it be difficult to do? I ask because 
it seems it would make using polymorphic struct subtypes easier. Here's 
an example of the problem:

#lang typed/racket

(struct: (T) datum ([val : T]))
(struct: (T) data datum ([vals : (Listof T)]))

(: get-vals (All (T) ((datum T) -> (Listof T))))
;; Returns the values in the struct as a list
(define (get-vals d)
                      ; type error here:
   (cond [(data? d)   (cons (datum-val d) (data-vals d))]
         [(datum? d)  (list (datum-val d))]))

(get-vals (data 1 '(2 3 4)))

#|
Type Checker: Polymorphic function cons could not be applied to arguments:
Types: a (Listof a) -> (Listof a)
        a b -> (Pairof a b)
Arguments: Nothing (Listof Any)
Expected result: (Listof T)
  in: (cons (datum-val d) (data-vals d))
|#

The problem is the type of data?, which is (Any -> Boolean : (data 
Any)), so in the first branch above, d has type (data Any) instead of 
(data T). But if data? : (All (S) (Any -> Boolean : (data S))), it seems 
I could make this function work, even if I had to annotate data? with 
(Any -> Boolean : (data T)) to use it.

BTW, shouldn't the first argument type to cons be Any instead of Nothing?

Neil T
Neil Toronto | 12 Aug 21:30 2010
Picon

[racket] Typed Racket puzzler: nested lists

I'm writing a function array->list that returns a nested list. The depth 
depends on the number of array dimensions; e.g. I expect an array with 
dimensions '(4 5 6) to return a (Listof (Listof (Listof T))).

So I defined

     (define-type (Deep-Listof T) (U T (Listof T)))

and tried to write a definition for (: array->list ((array T) -> 
(Deep-Listof T))).

A type error shows up deep in its recursive definition, but this 
expression demonstrates the error just fine:

     (ann (ann (list 1 2 3) (Listof (Deep-Listof Integer)))
          (Deep-Listof Integer))

     Type Checker: Expected (Listof (U Integer (Listof Integer))),
     but got (U Integer (Listof Integer)) in: (list 1 2 3)

IOW, Typed Racket doesn't recognize that (Listof (Deep-Listof Integer)) 
is also a (Deep-Listof Integer). Is there a way to do some kind of cast?

I've been trying to write a function with type (Listof (Deep-Listof T)) 
-> (Deep-Listof T) that uses occurrence typing to do the cast. But I 
can't get a good predicate: define-predicate on (Deep-Listof Any) 
returns a predicate with type (Any -> Boolean) instead of (Any -> 
Boolean : (Deep-Listof Any)).

Neil T
Neil Toronto | 12 Aug 21:00 2010
Picon

[racket] Duplicate bug report: 11098

I thought the bug report I submitted from DrRacket, 11098, didn't make 
it through (it apparently didn't finish sending after five minutes), so 
I went to the web page and did another one, 11099.

11099 is more complete, so keep that one around.

Neil T
Vincent St-Amour | 12 Aug 01:51 2010

[racket] Arrow labels in slideshow

Hi,

Is there a way to add labels to arrows created with pin-arrow-line in
slideshow? Text would work, but arbitrary picts would be even better.

Thanks,

Vincent

Gmane