[racket-users] Strange Error (Take 2)

2016-10-01 Thread 'brown131' via Racket Users
I am getting strange error in my Racquel package unit tests. I'm not sure what 
Racket release it started appearing in, but certainly 6.6 or 6.5. A couple of 
days ago, I posted the all of code that was causing the error, but there was 
too much going on for anyone to make sense of it (including me) and so I 
deleted the post. Now I've spent a few hours and reduced the bug to the minimum 
code required to reproduce it.

The error I'm seeing in my tests is:

define-values: assignment disallowed 
cannot re-define a constant
  constant: lifted.0

This error is rather obtuse and I have no I idea what it trying to communicate 
given that the code in question has no constant named "lifted". I can only 
assume that it is some internal error related to syntax lifting.

Below are the two modules needed to reproduce the error. What makes this error 
particularly strange is that the error occurs until the foobar function in 
bug2.rkt is commented out. This function is not even called anywhere!

Interestingly it must call query-rows. If foobar calls anything else, the bug 
goes away. This may mean that there is an error somewhere in the db package.

When the foobar function is commented out, everything works fine. In this 
example, for the sake of brevity, it will give an error that error-me% is 
undefined. I could have defined it and the other classes, and it would have ran 
with no errors.

The problem is that in the real version of the code, the foobar function is 
used and necessary. I can't just comment it out. Until I know what's going on 
here, I can't even devise a workaround. 

bug.rkt:
#lang racket

(require "bug2.rkt" (for-syntax racket/syntax syntax/parse "bug2.rkt"))

(define-syntax (data-class stx)
  (syntax-parse stx 
[(_ base-cls:id (i-face:id ...) elem:data-class-element ...) 
 (with-syntax ([m-data (generate-temporary)])
   #'(let* ([m-data (new error-me%)])
   (class* base-cls (bar% i-face ...) 
 elem.cls-expr ...
 (inspect #f]))

(define (gen-data-class) 
  (let* ([cls-nm 'cls-nm]
 [stx #`(data-class object% (foo%) (super-new))])
(eval-syntax stx bug-namespace)))

(define fred% (gen-data-class))

bug2.rkt:
#lang racket

(require syntax/parse db (for-syntax racket/syntax syntax/parse))

(provide (all-defined-out))

;;; Until this is commented-out the error persists.
(define (foobar con) (query-rows con ""))

(define-namespace-anchor bug-namespace-anchor)
(define bug-namespace (namespace-anchor->namespace bug-namespace-anchor))
 
(define-syntax-class data-class-element
  #:attributes (cls-expr)
  (pattern (x:expr ...)
   #:attr cls-expr #'(x ...)))
 

-- 
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] Good parser library in Racket

2016-10-01 Thread C K Kashyap
Thanks John and Jens!
Regards,
Kashyap

On Sat, Oct 1, 2016 at 11:23 AM, Jens Axel Søgaard 
wrote:

> Take a look at:
>
>  http://planet.racket-lang.org/display.ss?package=java.
> plt=dherman
>
> 2016-10-01 20:00 GMT+02:00 C K Kashyap :
>
>> Hi Racket users,
>> It appears that parser-tools/yacc is the parser tool that's bundled with
>> racket by default. I'd like to parse java like language. I was wondering if
>> there is already such an implementation that I could use or perhaps a
>> reference implementation I could use. The example in the sources - calc.rkt
>> is not quite enough :)
>> Ofcourse, I am not particular about using yacc - but I am inclined
>> towards it because it is bundled by default.
>> Thanks,
>> Kashyap
>>
>> --
>> 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.
>>
>
>
>
> --
> --
> Jens Axel Søgaard
>
>

-- 
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] Scribble: how to use #:tag-prefix and have @elemref work within the Table Of Contents?

2016-10-01 Thread Matthew Flatt
I've pushed a repair and also corrected the contracts on `elemtag` and
`elemref` to allow taglets.

When content is lifted to the table of contents, it was rendered as
being in the page's part, and opposed to the part where the content
originated. I've fixed ToC rendering for this this case, although I
think this problem must be more widespread, such as when the content of
a section title is rendered in a referencing context. (If I had a
better grasp on syntax and scope when initially creating Scribble,
maybe I would have figured out how to use scope instead of tags and
avoided this class of mistakes.)

I don't so far have a workaround to suggest that's better than yours.

At Fri, 30 Sep 2016 05:30:05 -0700 (PDT), Dupéron Georges wrote:
> I have two simple scribble files. The first one simply includes the second:
> 
> 
> 
> #lang scribble/manual
> @title{test-tag-prefix}
> @include-section{sub.scrbl}
> 
> 
> 
> And the second one uses #:tag-prefix, and inserts an @elemref in the TOC:
> 
> 
> 
> #lang scribble/manual
> @title[#:tag-prefix '(lib "test-tag-prefix/scribblings/sub.scrbl")]{sub}
> @(require scribble/struct)
> @(make-toc-element #f
>(list (elemtag '(prefixable "foo") "foo-tag"))
>(list (elemref '(prefixable "foo") "foo-ref-in-toc")))
> @(elemref '(prefixable "foo") "foo-ref-in-part")
> 
> 
> 
> The @elemref within the document works fine, but the @elemref in the Table Of 
> Contents is shown in red and is not a hyperlink, see the attached screenshot.
> 
> If I remove the #:tag-prefix, everything works fine. Also, the second file on 
> its own works fine (but it ignores the #:tag-prefix). I tried creating the 
> appropriate taglet:
> 
> 
> 
> (elemref '(prefixable "(lib 
> test-tag-prefix/scribblings/test-tag-prefix.scrbl)"
>   "(lib test-tag-prefix/scribblings/sub.scrbl)"
>   "foo")
>  "foo-ref-in-toc")
> 
> 
> 
> but elemref rejects it (I think the contract on elemref is wrong, it should 
> accept a taglet, not a tag). Directly calling make-link-element worked, 
> though:
> 
> 
> 
> (make-link-element
>  #f
>  (decode-content (list "foo-ref-in-toc"))
>  `(elem (prefixable "(lib test-tag-prefix/scribblings/test-tag-prefix.scrbl)"
> "(lib test-tag-prefix/scribblings/sub.scrbl)"
> "foo")))
> 
> 
> 
> Is there a better way to automatically generate this tag? I can store the 
> document tags within a global variable and cons them everywhere I'm inserting 
> an @elemref in the Table Of Contents, but it seems a bit of a hack.
> 
> Thanks,
> Georges
> 
> --
> 
> For experimentation, I uploaded a minimal package containing the two files at 
> https://github.com/jsmaniac/test-tag-prefix/tree/master/scribblings and the 
> package can be installed using:
> 
> raco pkg install https://github.com/jsmaniac/test-tag-prefix.git
> 
> -- 
> 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.
> 
> 
> --
> [image/png "scribble-elemref-in-toc-is-red.png"] [~/Desktop & open] [~/Temp & 
> open]
> .

-- 
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] Contract violation where number expected - can't understand why

2016-10-01 Thread Vincent St-Amour
On Sat, 01 Oct 2016 15:44:18 -0500,
Angus wrote:
> 
> And it is now more obvious to me that in:
> 
> (define (bigger w)
>   (interval (min (interval-big w) 
>  (add1 (guess w)))
> (interval-big w) (+ (interval-guesses w) 1)))
> 
> The (interval... part is a constructor ? for an interval and that is
> what this function returns - the new state of the world.

Precisely. Welcome to functional programming. :)

> It's interesting here that there is no assignment as such.  Although
> big-bang must somehow be dealing with mutating internal state
> somehow.

Probably not, in fact.

Internally, big-bang is probably just a recursive function that simply
passes the new world as argument to its next call. No need for mutation
there.

Vincent

-- 
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] Contract violation where number expected - can't understand why

2016-10-01 Thread Angus
On Saturday, 1 October 2016 16:13:01 UTC+1, Ben Greenman  wrote:
> Maybe this will help:
> 
> 
> 
> 
> (struct interval (small big guesses))
> 
> creates 5 new functions
> interval, for making intervals. For example (interval 5 10 0) creates an 
> interval from 5 to 10 that has 0 guessesinterval?, for testing if a value is 
> an interval. For example (interval? 1) is #false and (interval? (interval 0 0 
> 0)) is #trueinterval-small, to get the value of the "small" field out of an 
> interval. For example, (interval-small (interval 8 9 10)) is 8interval-big, 
> to get the value of the "big" fieldinterval-guesses, to get the value of the 
> "guesses" field
> This is all described in the Racket docs for struct
> http://docs.racket-lang.org/reference/define-struct.html
> 
> 
> 
> 
> 
> The value of (+ (interval-guesses w) 1) is a number 1 greater than the value 
> of the "guesses" field in the interval w.
> Notice that you give this value as the 3rd argument to a call to (interval 
> )


Thanks for the responses.  My confusion was with the meaning of w.  I see now 
that functions such as on-tick etc return the current state of the world.  In 
my program case the type is interval.  So on-key returns a world state, ie an 
interval.

And the bigger function takes arguments w which is the current world state.  It 
is confusing for me I think because in C (and C like languages) the function 
would be defined as:

WorldState bigger(WorldState previous_state)

The types are less explicit in lisp.

And it is now more obvious to me that in:

(define (bigger w)
  (interval (min (interval-big w) 
 (add1 (guess w)))
(interval-big w) (+ (interval-guesses w) 1)))

The (interval... part is a constructor ? for an interval and that is what this 
function returns - the new state of the world.

It's interesting here that there is no assignment as such.  Although big-bang 
must somehow be dealing with mutating internal state somehow.

-- 
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] Good parser library in Racket

2016-10-01 Thread Jens Axel Søgaard
Take a look at:

 http://planet.racket-lang.org/display.ss?package=java.plt=dherman

2016-10-01 20:00 GMT+02:00 C K Kashyap :

> Hi Racket users,
> It appears that parser-tools/yacc is the parser tool that's bundled with
> racket by default. I'd like to parse java like language. I was wondering if
> there is already such an implementation that I could use or perhaps a
> reference implementation I could use. The example in the sources - calc.rkt
> is not quite enough :)
> Ofcourse, I am not particular about using yacc - but I am inclined towards
> it because it is bundled by default.
> Thanks,
> Kashyap
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Re: Good parser library in Racket

2016-10-01 Thread JCG
On Saturday, October 1, 2016 at 2:00:23 PM UTC-4, ckkashyap wrote:
> Hi Racket users,
> It appears that parser-tools/yacc is the parser tool that's bundled with 
> racket by default. I'd like to parse java like language. I was wondering if 
> there is already such an implementation that I could use or perhaps a 
> reference implementation I could use. The example in the sources - calc.rkt 
> is not quite enough :)
> Ofcourse, I am not particular about using yacc - but I am inclined towards it 
> because it is bundled by default.
> Thanks,
> Kashyap

https://docs.racket-lang.org/honu/index.html

-- 
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] Good parser library in Racket

2016-10-01 Thread C K Kashyap
Hi Racket users,
It appears that parser-tools/yacc is the parser tool that's bundled with
racket by default. I'd like to parse java like language. I was wondering if
there is already such an implementation that I could use or perhaps a
reference implementation I could use. The example in the sources - calc.rkt
is not quite enough :)
Ofcourse, I am not particular about using yacc - but I am inclined towards
it because it is bundled by default.
Thanks,
Kashyap

-- 
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] Strange Error Message

2016-10-01 Thread Matthew Flatt
Hi Scott,

I think that you're seeing a bug in the current expander's marshaling
of information for a compiled module, specifically for the
"metadata.rkt" module that supplies `racquel-namespace`.

(The bug was introduced in v6.3 with the set-of-scopes expander.
Happily, a re-implementation of the expander doesn't have the bug, but
the re-implementation isn't quite ready to replace the current
expander.)

I'll fix the bug as soon as I can. Meanwhile, if you'd like a
workaround:

The conflicting "lifted.0" is created in "metadata.rkt" by the contract
system's expansion of `~a`. You can work around the problem by changing

  (~a col-fld)

to

  (format "~a" col-fld)


Matthew

At Thu, 29 Sep 2016 19:22:37 -0700 (PDT), "'brown131' via Racket Users" wrote:
> I was looking through the Racket packages the other day and noticed that 
> there 
> are errors in the Racquel package that I maintain. I the error I am seeing is 
> not very helpful:
> 
> define-values: assignment disallowed;
>  cannot re-define a constant
>   constant: lifted.0
> 
> The problem is that there is no constant anywhere in the code with that name. 
> I've done some reading and it appears that is may be connected to some 
> "lifted" syntax. Through a process of elemination by commenting out code, I 
> narrowed the problem to the block of code below. In particular, if I comment 
> out the data-class* definition of the stx id and replace it with a simple 
> class definition, i.e.
> "(class object% (super-new))" the error goes away. 
> 
> My suspicion is that using the data-class* in the syntax quasi-quote is 
> somehow lifting the syntax macro to a higher run-level. But how a constant is 
> re-defined as described in all the error is beyond me.
> 
> (define (gen-data-class con tbl-nm 
> #:db-system-type (dbsys-type (dbsystem-type con))
> #:generate-joins? (gen-joins? #t)
> #:generate-reverse-joins? (gen-rev-joins? #t)
> #:schema-name (schema-nm #f)
> #:inherits (base-cls 'object%)
> #:table-name-normalizer (tbl-nm-norm (lambda (n) 
> (table-name-normalizer n))) 
> #:column-name-normalizer (col-nm-norm (lambda (n) 
> (column-name-normalizer n)))
> #:in-name-normalizer (join-nm-norm (lambda (n (c 
> 'one-to-many)) 
>
> (join-name-normalizer n c))) 
> #:table-name-externalizer (tbl-nm-extern (lambda (n) 
> (begin n)))
> #:print? (prnt? #f)
> . rest) 
>   (let* ([schema (load-schema con schema-nm tbl-nm #:reverse-join? 
> gen-rev-joins? 
>   #:db-system-type dbsys-type)]
>  [cls-nm (string->symbol (tbl-nm-norm tbl-nm))]
>  [pkey (find-primary-key-fields schema col-nm-norm)]
>  [jns (if (or gen-joins? gen-rev-joins?)
>   (get-schema-joins con schema-nm schema dbsys-type 
> tbl-nm-norm join-nm-norm 
> col-nm-norm) null)]
>  [auto-key (get-autoincrement-key schema dbsys-type)]
>  [stx #`(let ([#,cls-nm 
>(data-class* #,base-cls (data-class<%>)
> (table-name #,tbl-nm #,(tbl-nm-extern 
> tbl-nm))
> #,(append '(column) (get-schema-columns 
> schema col-nm-norm))
> (primary-key '#,pkey #:autoincrement 
> #,auto-key)
> #,(if (and gen-joins? (list? jns) (> 
> (length jns) 0)) 
>   (append '(join) jns) '(begin #f))
> (super-new)
> #,@rest)
>])
>   (get-class-metadata-object #,cls-nm)
>   #,cls-nm)])
> (if prnt? (syntax->datum stx) (eval-syntax stx racquel-namespace 
> 
> Here is the syntax definition for the data-class*:
> 
> ;;; Define a data class with interfaces.
> (define-syntax (data-class* stx)
>   (syntax-parse stx 
> [(_ base-cls:id (i-face:id ...) elem:data-class-element ...) 
>  (with-syntax ([cls-id (generate-temporary #'class-id-)]
>[m-data (generate-temporary #'metadata-)]
>[ctxt ctxt-id]
>[set-auto-pkey! set-auto-pkey!-id]
>[set-pkey! set-pkey!-id]
>[set-tbl-nm-m-data! set-tbl-nm-m-data!-id]
>[jn-fld jn-fld-id]
>[jn-cls jn-cls-id]
>[con con-id]
>[dbsys-type dbsys-type-id])
>#'(let* ([ctxt null]
> [m-data (new data-class-metadata%)]
> [set-tbl-nm-m-data! (λ (tbl-nm extern-nm) (set-field! 
> table-name m-data tbl-nm) 
>

Re: [racket-users] Contract violation where number expected - can't understand why

2016-10-01 Thread Ben Greenman
Maybe this will help:

(struct interval (small big guesses))

creates 5 new functions

   1. interval, for making intervals. For example (interval 5 10 0) creates
   an interval from 5 to 10 that has 0 guesses
   2. interval?, for testing if a value is an interval. For example
   (interval? 1) is #false and (interval? (interval 0 0 0)) is #true
   3. interval-small, to get the value of the "small" field out of an
   interval. For example, (interval-small (interval 8 9 10)) is 8
   4. interval-big, to get the value of the "big" field
   5. interval-guesses, to get the value of the "guesses" field

This is all described in the Racket docs for struct
http://docs.racket-lang.org/reference/define-struct.html


The value of (+ (interval-guesses w) 1) is a number 1 greater than the
value of the "guesses" field in the interval w.
Notice that you give this value as the 3rd argument to a call to (interval
)

-- 
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] Contract violation where number expected - can't understand why

2016-10-01 Thread Vincent St-Amour
On Sat, 01 Oct 2016 09:47:00 -0500,
Angus wrote:
> I don't understand.  How would I pass it an interval?
> 
> I am confused about the w parameter in smaller.  ie (define (smaller w)
> 
> what is w?  Is that the current interval held as state within big-bang?

Yes, that is correct.

Have a closer look at the docs for big-bang. They should explain how
big-bang passes the value of the world to the handlers which, in your
program, pass it in turn to your `smaller` function.

On Sat, 01 Oct 2016 09:53:56 -0500,
Angus wrote:
> 
> This seems to work:
> 
> (define (smaller w)
>   (interval (interval-small w)
> (max (interval-small w) 
>  (sub1 (guess w))) (+ (interval-guesses w) 1)))
> 
> But I don't understand why???
> 
> the first argument is passed as (interval w)
> 
> what does that mean?  Does it mean that interval-small should be set to the 
> current interval-small???

What is the current interval? An interval is just a structure. You could
have as many as you want. Imagine you're writing a 2-player version of
your game, or even a multi-player tournament version. You'd need an
interval for each player.

Since there's no intrinsic "right" interval, your code must be explicit
about which interval it want to get the `small` field of. In this case,
you care about the interval that corresponds to the current state of the
world, which is bound to the variable `w`.

> So then what does 
> 
> (+ (interval-guesses w) 1) mean?
> 
> set interval guesses to whatever the current state is (represented by w) plus 
> 1?

That code doesn't set anything. It simply computes the number of guesses
of the current state, plus 1 (as you said).

If you want to use that value as the new number of guesses for the next
value of the state of the world, then you need to create a new interval
(as your code is already doing), and use that new number as its number
of guesses.

Vincent

-- 
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] Contract violation where number expected - can't understand why

2016-10-01 Thread Robby Findler
I guess you're familiar with the dot operator (object.field) in C and
Java? In Racket, we don't provide access to that directly, but instead
put such operations in "selector functions". So when you see

  (interval-guesses w)

that's something more like

   w.guesses

In other words, you can think of a secret, hidden define somewhere
(introduced by the struct) looking something like this:

(define (inverval-guesses w)
   w.guesses)

hth,
Robby



On Sat, Oct 1, 2016 at 9:53 AM, Angus  wrote:
> On Saturday, 1 October 2016 15:30:19 UTC+1, Vincent St-Amour  wrote:
>> On Sat, 01 Oct 2016 09:13:25 -0500,
>> Angus wrote:
>> > Then I changed smaller (and bigger) like this:
>> >
>> > (define (smaller w)
>> >   (interval (interval-small w)
>> > (max (interval-small w)
>> >  (sub1 (guess w)
>> >
>> > to
>> >
>> > (define (smaller w)
>> >   (interval (interval-small w)
>> > (max (interval-small w)
>> >  (sub1 (guess w))) ((+ interval-guesses 1) w)))
>> >
>> >
>> >
>> > But with these changes, when I run the program I get:
>> >
>> > +: contract violation
>> >   expected: number?
>> >   given: #
>> >   argument position: 1st
>> >   other arguments...:
>> >1
>>
>> What is `interval-guesses`? Your code would like it to be a number, but
>> it's actually an *accessor*. If you pass it an interval, then you'll get
>> the number you want.
>>
>> Jumping ahead a little: you may also want to double-check how you're
>> constructing your intervals.
>>
>> Vincent
>
> This seems to work:
>
> (define (smaller w)
>   (interval (interval-small w)
> (max (interval-small w)
>  (sub1 (guess w))) (+ (interval-guesses w) 1)))
>
> But I don't understand why???
>
> the first argument is passed as (interval w)
>
> what does that mean?  Does it mean that interval-small should be set to the 
> current interval-small???
>
> So then what does
>
> (+ (interval-guesses w) 1) mean?
>
> set interval guesses to whatever the current state is (represented by w) plus 
> 1?
>
> --
> 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.

-- 
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] Contract violation where number expected - can't understand why

2016-10-01 Thread Angus
On Saturday, 1 October 2016 15:30:19 UTC+1, Vincent St-Amour  wrote:
> On Sat, 01 Oct 2016 09:13:25 -0500,
> Angus wrote:
> > Then I changed smaller (and bigger) like this:
> > 
> > (define (smaller w)
> >   (interval (interval-small w)
> > (max (interval-small w) 
> >  (sub1 (guess w)
> > 
> > to
> > 
> > (define (smaller w)
> >   (interval (interval-small w)
> > (max (interval-small w) 
> >  (sub1 (guess w))) ((+ interval-guesses 1) w)))
> > 
> > 
> > 
> > But with these changes, when I run the program I get:
> > 
> > +: contract violation
> >   expected: number?
> >   given: #
> >   argument position: 1st
> >   other arguments...:
> >1
> 
> What is `interval-guesses`? Your code would like it to be a number, but
> it's actually an *accessor*. If you pass it an interval, then you'll get
> the number you want.
> 
> Jumping ahead a little: you may also want to double-check how you're
> constructing your intervals.
> 
> Vincent

This seems to work:

(define (smaller w)
  (interval (interval-small w)
(max (interval-small w) 
 (sub1 (guess w))) (+ (interval-guesses w) 1)))

But I don't understand why???

the first argument is passed as (interval w)

what does that mean?  Does it mean that interval-small should be set to the 
current interval-small???

So then what does 

(+ (interval-guesses w) 1) mean?

set interval guesses to whatever the current state is (represented by w) plus 1?

-- 
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] Contract violation where number expected - can't understand why

2016-10-01 Thread Angus
On Saturday, 1 October 2016 15:30:19 UTC+1, Vincent St-Amour  wrote:
> On Sat, 01 Oct 2016 09:13:25 -0500,
> Angus wrote:
> > Then I changed smaller (and bigger) like this:
> > 
> > (define (smaller w)
> >   (interval (interval-small w)
> > (max (interval-small w) 
> >  (sub1 (guess w)
> > 
> > to
> > 
> > (define (smaller w)
> >   (interval (interval-small w)
> > (max (interval-small w) 
> >  (sub1 (guess w))) ((+ interval-guesses 1) w)))
> > 
> > 
> > 
> > But with these changes, when I run the program I get:
> > 
> > +: contract violation
> >   expected: number?
> >   given: #
> >   argument position: 1st
> >   other arguments...:
> >1
> 
> What is `interval-guesses`? Your code would like it to be a number, but
> it's actually an *accessor*. If you pass it an interval, then you'll get
> the number you want.
> 
> Jumping ahead a little: you may also want to double-check how you're
> constructing your intervals.
> 
> Vincent

I don't understand.  How would I pass it an interval?

I am confused about the w parameter in smaller.  ie (define (smaller w)

what is w?  Is that the current interval held as state within big-bang?

So in that case do I write it like this:

(interval-guesses (+ w 1))

???

-- 
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] Contract violation where number expected - can't understand why

2016-10-01 Thread Vincent St-Amour
On Sat, 01 Oct 2016 09:13:25 -0500,
Angus wrote:
> Then I changed smaller (and bigger) like this:
> 
> (define (smaller w)
>   (interval (interval-small w)
> (max (interval-small w) 
>  (sub1 (guess w)
> 
> to
> 
> (define (smaller w)
>   (interval (interval-small w)
> (max (interval-small w) 
>  (sub1 (guess w))) ((+ interval-guesses 1) w)))
> 
> 
> 
> But with these changes, when I run the program I get:
> 
> +: contract violation
>   expected: number?
>   given: #
>   argument position: 1st
>   other arguments...:
>1

What is `interval-guesses`? Your code would like it to be a number, but
it's actually an *accessor*. If you pass it an interval, then you'll get
the number you want.

Jumping ahead a little: you may also want to double-check how you're
constructing your intervals.

Vincent

-- 
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] Realm of Racket chapter 5 easy question variable update question

2016-10-01 Thread Matthias Felleisen

> On Oct 1, 2016, at 7:51 AM, Greg Trzeciak  wrote:
> 
> On Saturday, October 1, 2016 at 11:35:52 AM UTC+2, Angus wrote:
>> 2. I don't really understand what is happening with the big-bang on-tick. 
>> 
>> My background is imperative languages, eg C, C++, Java, python, etc.  Not 
>> sure if that helps.
> 
> Coming from OOP background following tutorial may be helpful. It explains a 
> bit of magic behind big-bang (with classes):
> http://www.ccs.neu.edu/home/matthias/Thoughts/Programming_with_Class_in_Racket.html


Yes, but developers should always use the interface not the implementation. 
Always. 

-- 
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] Re: Realm of Racket chapter 5 easy question variable update question

2016-10-01 Thread Greg Trzeciak
On Saturday, October 1, 2016 at 11:35:52 AM UTC+2, Angus wrote:
> 2. I don't really understand what is happening with the big-bang on-tick. 
> 
> My background is imperative languages, eg C, C++, Java, python, etc.  Not 
> sure if that helps.

Coming from OOP background following tutorial may be helpful. It explains a bit 
of magic behind big-bang (with classes):
http://www.ccs.neu.edu/home/matthias/Thoughts/Programming_with_Class_in_Racket.html

-- 
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] Realm of Racket chapter 5 easy question variable update question

2016-10-01 Thread Jens Axel Søgaard
Hi Angus,

2. I don't really understand what is happening with the big-bang on-tick.
> The big-bang function is passed 50 as the initial state.  Does the big-bang
> function somehow internally keep the state variable cached and then it gets
> updated by the change-state function.  That bit seems a little confusing to
> me.  Or should I just read more of the book until it is clearer?
>

Yes - big-bang keeps track of the current state. And the various handlers
are called to compute the new state.

I can recommend:

"big-bang: the world, universe, and network in the programming language" by
Matthias Felleisen
https://www.youtube.com/watch?v=ayoofXuKqMY

The big-bang explanation starts at 12.30.


/Jens Axel

-- 
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] Re: Require/typed with racket/tcp

2016-10-01 Thread Sourav Datta
On Saturday, October 1, 2016 at 3:10:12 PM UTC+5:30, Sourav Datta wrote:
> I am currently trying to use racket/tcp library in a TR program and used 
> require/typed to import the necessary functions as I could not find this 
> provided with TR by default. However, the following code has a problem when 
> it runs:
> 
> #lang typed/racket
> 
> (require/typed racket/tcp
>[opaque TCP-Listener tcp-listener?]
>[tcp-listen (-> Number TCP-Listener)]
>[tcp-accept (-> TCP-Listener (Values Number Number))])
> 
> (: server (-> Number Void))
> (define (server port)
>   (let ([listener (tcp-listen port)])
> (define-values (inp outp) (tcp-accept listener))
> (displayln inp)
> (displayln outp)))
> 
> The code compiles fine but while running the "server" function with a valid 
> port it errors out:
> 
>  tcp-listen: broke its own contract
>   promised: tcp-listener?
>   produced: #
>   in: (-> any/c tcp-listener?)
>   contract from: (interface for tcp-listen)
>   blaming: (interface for tcp-listen)
>(assuming the contract is correct)
>   at: unsaved-editor:5.16
> 
> I am not sure what exactly this error message means as tcp-listener is 
> creating a valid listener as given by "produced: #" but still 
> the predicate seems to be failing. The program runs fine with #lang racket. 
> Any help?
> 
> Thanks!

I found the cause of the problem. Already there are base type TCP-Listener 
which I should have used in the code instead of defining a new opaque type. 
Using that solves the problem and I found there are types for Input-Port and 
Output-Port as well. So that fixes the issue. However, it's still a bit 
surprising why the opaque type definition did not work with the tcp-listener? 
predicate though.

Thanks.

-- 
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] Require/typed with racket/tcp

2016-10-01 Thread Sourav Datta
I am currently trying to use racket/tcp library in a TR program and used 
require/typed to import the necessary functions as I could not find this 
provided with TR by default. However, the following code has a problem when it 
runs:

#lang typed/racket

(require/typed racket/tcp
   [opaque TCP-Listener tcp-listener?]
   [tcp-listen (-> Number TCP-Listener)]
   [tcp-accept (-> TCP-Listener (Values Number Number))])

(: server (-> Number Void))
(define (server port)
  (let ([listener (tcp-listen port)])
(define-values (inp outp) (tcp-accept listener))
(displayln inp)
(displayln outp)))

The code compiles fine but while running the "server" function with a valid 
port it errors out:

 tcp-listen: broke its own contract
  promised: tcp-listener?
  produced: #
  in: (-> any/c tcp-listener?)
  contract from: (interface for tcp-listen)
  blaming: (interface for tcp-listen)
   (assuming the contract is correct)
  at: unsaved-editor:5.16

I am not sure what exactly this error message means as tcp-listener is creating 
a valid listener as given by "produced: #" but still the 
predicate seems to be failing. The program runs fine with #lang racket. Any 
help?

Thanks!

-- 
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] Realm of Racket chapter 5 easy question variable update question

2016-10-01 Thread Angus
I am working through Realm of Racket chapter 5, last exercise was: Find an 
image of a locomotive and create an animation which wraps around to the left 
side of the screen after passing the right margin.

I have a solution which is below, but have some questions:

1. Is the solution below a reasonable one?  How could I have done it better?

2. I don't really understand what is happening with the big-bang on-tick.  The 
big-bang function is passed 50 as the initial state.  Does the big-bang 
function somehow internally keep the state variable cached and then it gets 
updated by the change-state function.  That bit seems a little confusing to me. 
 Or should I just read more of the book until it is clearer?


My background is imperative languages, eg C, C++, Java, python, etc.  Not sure 
if that helps.

My solution to problem:

#lang racket
(require 2htdp/universe 2htdp/image)

(define LOCO-IMAGE )

(define WIDTH 800)
(define HEIGHT 200)

(define (change-state current-state)
  (cond
[(>= current-state 750) 0]
[else (+ current-state 3)]))

(define (draw-a-ufo-onto-an-empty-scene current-state)
  (place-image LOCO-IMAGE current-state (/ HEIGHT 2)
   (empty-scene WIDTH HEIGHT)))

(big-bang 50 
  (on-tick change-state)
  (to-draw draw-a-ufo-onto-an-empty-scene))

-- 
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.