[racket-users] Typed Racket: Using (Sequenceof a) in place of (Listof a)

2017-03-20 Thread Sourav Datta
Hello all!

I have a question regarding how sequence abstraction works in TR. In the 
sequence part of the docs it says that a sequence can consist of lists or 
vectors among other things. But does this make a function which ideally accepts 
a (Listof a) to accept something that is declared as a (Sequenceof a)? For 
example, in TR this works:

(: x (Sequenceof Symbol))
(define x '(a b c d))

However, this shows a type mismatch:

#lang typed/racket

(: step (All (a)
 (-> (-> a (Sequenceof a) (Sequenceof a))
 a
 (Sequenceof a)
 (Sequenceof a
(define (step fn x seq)
  (fn x seq))


(step (ann cons (-> Symbol (Listof Symbol) (Listof Symbol)))
  'a
  '(b c))

Results in:

Type Checker: Polymorphic function `step' could not be applied to arguments:
Argument 1:
  Expected: (-> a (Sequenceof a) (Sequenceof a))
  Given:(-> Symbol (Listof Symbol) (Listof Symbol))
Argument 2:
  Expected: a
  Given:'a
Argument 3:
  Expected: (Sequenceof a)
  Given:(List 'b 'c)

I think, trying to instantiate the polymorphic step function might help but I 
was not able to figure out how.

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to use the REPL with #lang s-exp "expander.rkt"

2017-03-20 Thread Matthew Butterick

> On Mar 20, 2017, at 2:59 AM, Jan Hondebrink  wrote:
> 
> Testing top-interaction with expression: (#%top-interaction + 1 2)
> . +: unbound identifier;
> also, no #%app syntax transformer is bound in: +
> 
> So when you pass an expression through to the racket/base #%module-begin, it 
> can use the racket/base bindings, but if you pass an expression through to 
> the racket/base #%top-interaction it cannot. How can you make 
> #%top-interaction use the racket/base bindings?


When you start a source file with this line:

#lang s-exp "ME-expander.rkt"

You are telling Racket to 1) parse the code into expressions using the default 
`s-exp` (aka Racket-style) reader and 2) use "ME-expander.rkt" as the expander 
module.

The expander module supplies the initial set of bindings for the code. 
Conversely, if the expander doesn't provide a certain binding, the code can't 
use it, and you get an unbound-identifier error.

Even though "ME-expander.rkt" is written with `#lang racket/base`, it does not 
automatically export the bindings from `racket/base`. If that's the behavior 
you want, you need to add this to "ME-expander.rkt":

(provide (all-from-out racket/base))

Though you have to be a little careful if you plan to override bindings from 
`racket/base` with your own (say, `#%top-interaction` and `#%module-begin`). In 
that case, you can omit those bindings with `except-out`:

(provide (except-out (all-from-out racket/base) #%top-interaction 
#%module-begin))



-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] syntax-parse: using expr/c with ~optional

2017-03-20 Thread Alex Knauth

> On Mar 20, 2017, at 11:04 AM, Philip McGrath  wrote:
> 
> Using expr/c to attach a contract to a macro sub-pattern doesn't seem to work 
> with ~optional, even when the attribute is bound with #:defaults.
> 
> For example, this program:
> #lang racket 
> (require (for-syntax syntax/parse))
> (define-syntax (example stx)
>   (syntax-parse stx
> [(_ (~optional (~seq #:return val)
>#:defaults ([val #'42])))
>  #:declare val (expr/c #'(or/c list? #f))
>  #'val.c]))
> (example)
> reports the following error:
> val.c: bad attribute value for syntax template
>   attribute value: #f
>   expected for attribute: syntax
>   sub-value: #f
>   expected for sub-value: syntax in: val.c
> 
> Is there a better way to do this? 

This is because the `val` in the #:defaults is treated as just an attribute 
name, not a variable pattern, and syntax-classes like `expr/c` can only apply 
to variable patterns. One way to work around this is to use ~or and ~parse to 
put it in a pattern position:

#lang racket 
(require (for-syntax syntax/parse))
(define-syntax example
  (syntax-parser
[(_ (~or (~seq #:return val)
 (~and (~seq) (~parse val #'42
 #:declare val (expr/c #'(or/c list? #f))
 #'val.c]))
(example)

This raises the contract violation you expected.

Alex Knauth

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] syntax-parse: using expr/c with ~optional

2017-03-20 Thread Philip McGrath
Using expr/c to attach a contract to a macro sub-pattern doesn't seem to
work with ~optional, even when the attribute is bound with #:defaults.

For example, this program:

> #lang racket

(require (for-syntax syntax/parse))
> (define-syntax (example stx)
>   (syntax-parse stx
> [(_ (~optional (~seq #:return val)
>#:defaults ([val #'42])))
>  #:declare val (expr/c #'(or/c list? #f))
>  #'val.c]))
> (example)

reports the following error:

> val.c: bad attribute value for syntax template
>   attribute value: #f
>   expected for attribute: syntax
>   sub-value: #f
>   expected for sub-value: syntax in: val.c


Is there a better way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] getting info from parallel-compile

2017-03-20 Thread Dan Liebgold
Hi -

I have code to precompile a set of files that looks like this:

  http://pasterack.org/pastes/97351

Note in this example the given file doesn't exist.

How can I get better info from the build process?  Is my logging mechanism 
broken? It doesn't ever get any messages back.

And, relatedly, is there a way to get a proper error from the invalid file?

Thanks,
Dan

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to use the REPL with #lang s-exp "expander.rkt"

2017-03-20 Thread Jan Hondebrink
On Sunday, March 19, 2017 at 6:46:24 PM UTC+1, Greg Hendershott wrote:
> > This works fine in the ME-test.rkt Definition window, but not in the REPL 
> > which doesn't have bindings for anything. I would like anything typed into 
> > the ME-test.rkt REPL to be used as argument to the ME-module-begin macro in 
> > ME-expander.rkt.
> 
> I'm not sure but since no one has replied yet:
> 
> #%top-interaction is used by a REPL. It looks like you're providing
> the one from racket/base;
> maybe you need to provide your own that uses your m-eval?

Ah, cool, thanks! It never occurred to me that that was possible! A lot to 
learn for sure. Now to make it work...

I can now loop the REPL input through m-eval first, but it doesn't help me, 
which I'll try to illustrate: If I just pass the relevant part of the REPL 
input without modification through to the racket/base #%top-interaction:

(define-syntax (ME-top-interaction stx)
  (printf "Testing top-interaction with expression: ~a\n" (syntax->datum stx))
  #`(#%top-interaction . #,(cdr (syntax-e stx

(provide (rename-out (ME-top-interaction #%top-interaction)))

In ME-test.rkt:

> 4
Testing top-interaction with expression: (#%top-interaction . 4)
. ?: literal data is not allowed;
 no #%datum syntax transformer is bound in: 4

After providing #%datum in ME-expander.rkt:

> 4
Testing top-interaction with expression: (#%top-interaction . 4)
4
> (+ 1 2)
Testing top-interaction with expression: (#%top-interaction + 1 2)
. +: unbound identifier;
 also, no #%app syntax transformer is bound in: +

So when you pass an expression through to the racket/base #%module-begin, it 
can use the racket/base bindings, but if you pass an expression through to the 
racket/base #%top-interaction it cannot. How can you make #%top-interaction use 
the racket/base bindings?

I obviously have a very muddied and incomplete understanding of this whole 
subject, so please forgive me for any stupid/obvious questions.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.