Re: [racket-users] Prefab and contracts

2018-03-20 Thread Daniel Feltey
The same behavior occurs with vectors, the program

  (define v (vector 1 2))
  (define/contract vc (vectorof integer?) (vector 1 2))
  (place-message-allowed? v)
  (place-message-allowed? vc)

Produces:

#t
#f

I think the issue here is that both contracted vectors and structs are
wrapped in chaperones in order to enforce the contract, but that the place
machinery doesn't know what to do with chaperoned values so it just
prohibits them from being used as place messages.

I am a little surprised that the contracted vector can't be converted to an
immutable-vector like other mutable vectors for use as a place message
though.


On Tue, Mar 20, 2018 at 8:03 AM, 'Paulo Matos' via Racket Users <
racket-users@googlegroups.com> wrote:

> Hello,
>
> In a similar comment to my previous thread, I am yet again surprised at
> this:
>
> a.rkt:
>
> #lang racket
>
> (provide (struct-out foo))
>
> (struct foo (a b)
>   #:prefab)
>
> b.rkt:
>
> #lang racket
>
> (require "a.rkt")
>
> (place-message-allowed? (foo 1 2))
>
> This works! However, try to provide in a.rkt foo like this:
> (provide (contract-out (struct foo ((a integer?)
> (b integer?)
>
> Suddenly you get:
> #f
>
> Here's the even more confusing part:
> (define-values (pch1 pch2) (place-channel))
> (place-channel-put pch1 (foo 1 2))
>
> This will result in:
> place-channel-put: value not allowed in a message
>   value: '#s(foo 1 2)
>   message: '#s(foo 1 2)
>
>
> This will drive you mad because if you copy the message textual
> representation:
> (place-channel-put pch1 '#s(foo 1 2))
>
> then it works.
>
> What's the reason for this discrepancy? There's no mentioning of
> #:prefab in contract-out documentation.
>
> Regards,
>
> --
> Paulo Matos
>
> --
> 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.


[racket-users] Understanding prop:impersonator-of

2018-01-25 Thread Daniel Feltey
I'm trying to understand the use of the prop:impersonator-of struct
property, but the following program doesn't work the way I would have
expected:

#lang racket

(struct our-impersonate-proc (f orig)
 #:property prop:impersonator-of (lambda (x) (displayln 'hi)
(our-impersonate-proc-orig x))
 #:property prop:procedure (struct-field-index f))

(impersonator-of?
  (our-impersonate-proc add1 values)
  values)

The call to impersonator-of? doesn't seem to go through our
prop:impersonator-of at all because we don't 'hi displayed when the program
is run.

Am I misunderstanding the way to use prop:impersonator-of ? I don't fully
understand the documentation, so it's possible this isn't something that
prop:impersonator-of is intended for.

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] What am I misunderstanding about flat-contract-with-explanation?

2018-01-05 Thread Daniel Feltey
Are you using a recent version of Racket? I see the same error in Racket
6.8, but not in more recent releases.

Dan

On Fri, Jan 5, 2018 at 2:15 PM, David Storrs  wrote:

> https://docs.racket-lang.org/reference/data-structure-
> contracts.html#%28def._%28%28lib._racket%2Fcontract%
> 2Fprivate%2Fmisc..rkt%29._flat-contract-with-explanation%29%29
>
> says:
>
> (flat-contract-with-explanation get-explanation   [#:name name])  →
> flat-contract?
> get-explanation : (-> any/c (or/c boolean? (-> blame? any)))
> name : any/c = (object-name get-explanation)
>
> When I try to create a contract that means "a list of length >= 2", I
> get the following:
>
> (flat-contract-with-explanation
>   (lambda (l)
> (cond [(and (list? l) (>= (length l) 2))]
> [else
>   (lambda (blame)
> (raise-blame-error blame l '(expected: "list with length >=
> 2"\ngiven: "~e" )))]))
>  #:name 'foo)
> ; application: procedure does not accept keyword arguments
> ;   procedure: flat-contract-with-explanation
>
> What am I not understanding?
>
>
> PS:  I know I could do (-> (and/c list? (lambda (l) (>= (length l)
> 2 any) but I wanted to get something that wouldn't return ??? in
> the error message
>
> --
> 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] unexpected behavior of parametric polymorphism in Typed Racket

2017-11-28 Thread Daniel Feltey
Sorry for the late reply to this thread, I tried to send this message
yesterday, but ran into problems with my email setup.

> I'm starting to think that my base assumption (that Typed Units are more
or
> less equivalent to ML signatures, structures, and functors) is way off.

The intent is that they are similar to ML signatures, structures, and
functors, but unfortunately, they just aren't quite there yet. I think they
support most of the uses of units you would find in the Racket codebase,
but when I was implementing them there weren't many uses of them as ways to
parameterize over different data types and I didn't make supporting that
use case a priority.

I do think that Typed Units would be significantly more useful if they
supported more of the ML module system features, but there are some
interesting questions about units and signatures with type parameters
should interact with untyped racket programs.

> The mention of `sig-type-form' in the error message suggests that it is
> possible to do this, but I'm not seeing the concrete syntax for this
> described anywhere.  Am I overlooking something?

You aren't overlooking anything. I had started trying to support
`define-type` style type alias definitions inside of signature definitions,
but at
some point this was abandoned and probably should have been removed when
support for Typed Units was added to Typed Racket. The error message here
comes from a missing set of parentheses around the list of type
declarations, but adding that doesn't fix the real problem that typed units
don't currently support type parameterization.


The documentation for typed units can be found at
http://docs.racket-lang.org/ts-reference/Typed_Units.html?q=typed%20units
I'm not sure how helpful it would be, basically only the `define-signature`
form differs in racket and typed/racket, and the typed
version of the other unit syntactic forms are mostly a subset of their
untyped versions.

I'm sorry that this probably doesn't help you solve your original problem,
I hope we can eventually improve the support for units in Typed Racket to
better match the features of ML modules.
Dan

On Tue, Nov 28, 2017 at 9:09 AM, Matthias Felleisen 
wrote:

>
> > On Nov 28, 2017, at 10:02 AM, Richard Cobbe  wrote:
> >
> > On Tue, Nov 28, 2017 at 09:43:54AM -0500, Matthias Felleisen wrote:
> >>
> >> I have forwarded your email to Daniel Felty who designed and
> implemented the typed units. I am hoping to get a response soon — Matthias
> >
> > Great, thanks.
> >
> >>> On Nov 26, 2017, at 6:11 PM, Richard Cobbe  wrote:
> >
> > 
> >
> >>> I'm starting to think that my base assumption (that Typed Units are
> more or
> >>> less equivalent to ML signatures, structures, and functors) is way off.
> >
> > Probably worth clarifying this: I'm not claiming that Typed Units *have*
> to
> > work like ML functors, merely that this is my starting assumption, since
> > they both appear to be designed to address many of the same problems.  If
> > they don't work like that, though, then I might need some additional
> > documentation.
>
>
> Yes. Units are not functors.
>
> I believe Daniel has written some documentation. Perhaps he can point us
> there.
>
>
> --
> 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] What is meant to be the public API of ‘drracket:rep:text<%>’ ?

2017-04-09 Thread Daniel Feltey
I think the intention of the docs is that `drracket:rep:text<%>` is the
interface for all of the methods listed under the `drracket:rep:text%`
class. It looks like at the very least it extends the `racket:text<%>`
interface, this is likely just an oversight in the documentation.

Dan

On Sun, Apr 9, 2017 at 2:50 PM, gfb  wrote:

> The docs for ‘drracket:rep:text<%>’ just say it's an interface, without
> listing any interfaces it extends, nor methods it contains. Is there a
> public API it's meant to have and have documented?
>
> --
> 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] refactoring help/tools?

2017-03-23 Thread Daniel Feltey
For those not tracking the DrRacket github repo, this feature is now
available in the Racket snapshot builds.

https://plt.eecs.northwestern.edu/snapshots/

Thanks,
Dan

On Wed, Mar 22, 2017 at 5:17 PM, Daniel Feltey <dfel...@ccs.neu.edu> wrote:

> I think I've finally got something working within DrRacket so I've just
> pushed a change to check-syntax[1] which adds a `Remove Unused Requires`
> right-click menu item to DrRacket which will remove all requires which
> check-syntax marks as unused.
>
> If you're using DrRacket from github, I'd appreciate any feedback you
> might on the tool or how it could be improved.
>
> [1]: https://github.com/racket/drracket/commit/
> 10ac8e7d91c4d7ae7ba2dc6d929a7ec7ed9fe186
>
> Thanks
> Dan
>
> On Mon, Mar 13, 2017 at 9:43 PM, Daniel Feltey <dfel...@ccs.neu.edu>
> wrote:
>
>> I've started working on adding this refactoring to DrRacket[1], it's not
>> quite as full-featured(and is definitely still a bit buggy) as what
>> racket-mode in emacs seems to allow, but it's a first step and I'd
>> appreciate suggestions or requests on how DrRacket can better support
>> developers editing and refactoring code.
>>
>> [1] https://github.com/racket/drracket/pull/97
>>
>> Dan
>>
>> On Mon, Mar 13, 2017 at 7:30 PM, Greg Hendershott <
>> greghendersh...@gmail.com> wrote:
>>
>>> The `racket-trim-requires` and `racket-base-requires` commands use
>>> `raco check-requires` behind the scenes (then format/sort as does
>>> `racket-tidy-requires`).
>>>
>>> Today I tried to use `racket-trim-requires` on a Typed Racket file
>>> containing `define-type`; and got the error you mention. This turned
>>> out to be an issue with `raco check-requires`; thanks to a hint from
>>> Sam on Slack, I pushed a a PR that Ryan merged:
>>>
>>>   https://github.com/racket/macro-debugger/pull/22
>>>
>>> I just now saw this thread, which is weird timing!
>>>
>>> I'd welcome hearing any other examples where racket-{tidy
>>> base}-requires doesn't work -- and `raco check-requires` on that same
>>> file works or not. (Of course I'd also understand if folks are too
>>> busy to detour to report them.)
>>>
>>>
>>> On Mon, Mar 13, 2017 at 1:50 PM, Dan Liebgold
>>> <dan_liebg...@naughtydog.com> wrote:
>>> > raco check-requires does the job.
>>> >
>>> > I use emacs racket-mode, but it's hobbled in ways I haven't
>>> investigated -- e.g. when I try to use tidy or trim requires it gives me a
>>> "Can't do, source file has error" when it doesn't, or at least not in a way
>>> I can see.
>>> >
>>> > --
>>> > 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.
>>>
>>
>>
>

-- 
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] refactoring help/tools?

2017-03-22 Thread Daniel Feltey
I think I've finally got something working within DrRacket so I've just
pushed a change to check-syntax[1] which adds a `Remove Unused Requires`
right-click menu item to DrRacket which will remove all requires which
check-syntax marks as unused.

If you're using DrRacket from github, I'd appreciate any feedback you might
on the tool or how it could be improved.

[1]:
https://github.com/racket/drracket/commit/10ac8e7d91c4d7ae7ba2dc6d929a7ec7ed9fe186

Thanks
Dan

On Mon, Mar 13, 2017 at 9:43 PM, Daniel Feltey <dfel...@ccs.neu.edu> wrote:

> I've started working on adding this refactoring to DrRacket[1], it's not
> quite as full-featured(and is definitely still a bit buggy) as what
> racket-mode in emacs seems to allow, but it's a first step and I'd
> appreciate suggestions or requests on how DrRacket can better support
> developers editing and refactoring code.
>
> [1] https://github.com/racket/drracket/pull/97
>
> Dan
>
> On Mon, Mar 13, 2017 at 7:30 PM, Greg Hendershott <
> greghendersh...@gmail.com> wrote:
>
>> The `racket-trim-requires` and `racket-base-requires` commands use
>> `raco check-requires` behind the scenes (then format/sort as does
>> `racket-tidy-requires`).
>>
>> Today I tried to use `racket-trim-requires` on a Typed Racket file
>> containing `define-type`; and got the error you mention. This turned
>> out to be an issue with `raco check-requires`; thanks to a hint from
>> Sam on Slack, I pushed a a PR that Ryan merged:
>>
>>   https://github.com/racket/macro-debugger/pull/22
>>
>> I just now saw this thread, which is weird timing!
>>
>> I'd welcome hearing any other examples where racket-{tidy
>> base}-requires doesn't work -- and `raco check-requires` on that same
>> file works or not. (Of course I'd also understand if folks are too
>> busy to detour to report them.)
>>
>>
>> On Mon, Mar 13, 2017 at 1:50 PM, Dan Liebgold
>> <dan_liebg...@naughtydog.com> wrote:
>> > raco check-requires does the job.
>> >
>> > I use emacs racket-mode, but it's hobbled in ways I haven't
>> investigated -- e.g. when I try to use tidy or trim requires it gives me a
>> "Can't do, source file has error" when it doesn't, or at least not in a way
>> I can see.
>> >
>> > --
>> > 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.
>>
>
>

-- 
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] refactoring help/tools?

2017-03-13 Thread Daniel Feltey
I've started working on adding this refactoring to DrRacket[1], it's not
quite as full-featured(and is definitely still a bit buggy) as what
racket-mode in emacs seems to allow, but it's a first step and I'd
appreciate suggestions or requests on how DrRacket can better support
developers editing and refactoring code.

[1] https://github.com/racket/drracket/pull/97

Dan

On Mon, Mar 13, 2017 at 7:30 PM, Greg Hendershott  wrote:

> The `racket-trim-requires` and `racket-base-requires` commands use
> `raco check-requires` behind the scenes (then format/sort as does
> `racket-tidy-requires`).
>
> Today I tried to use `racket-trim-requires` on a Typed Racket file
> containing `define-type`; and got the error you mention. This turned
> out to be an issue with `raco check-requires`; thanks to a hint from
> Sam on Slack, I pushed a a PR that Ryan merged:
>
>   https://github.com/racket/macro-debugger/pull/22
>
> I just now saw this thread, which is weird timing!
>
> I'd welcome hearing any other examples where racket-{tidy
> base}-requires doesn't work -- and `raco check-requires` on that same
> file works or not. (Of course I'd also understand if folks are too
> busy to detour to report them.)
>
>
> On Mon, Mar 13, 2017 at 1:50 PM, Dan Liebgold
>  wrote:
> > raco check-requires does the job.
> >
> > I use emacs racket-mode, but it's hobbled in ways I haven't investigated
> -- e.g. when I try to use tidy or trim requires it gives me a "Can't do,
> source file has error" when it doesn't, or at least not in a way I can see.
> >
> > --
> > 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.
>

-- 
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] racket/gui -- How to implement a text% area with line number displayed?

2017-03-08 Thread Daniel Feltey
The easiest way to do this is to use the text:line-numbers-mixin in the
framework. Here's an example of an editor with line numbers:

#lang racket

(require racket/gui framework)

(define text (new (text:line-numbers-mixin text:standard-style-list%)))
(define frame
  (new frame%
   [label "editor with line numbers"]
   [height 500]
   [width 500]))
(define editor (new editor-canvas% [parent frame] [editor text]))
(send text show-line-numbers! #t)
(send frame show #t)




On Wed, Mar 8, 2017 at 8:09 PM, WarGrey Gyoudmon Ju 
wrote:

> Sorry for so many small mails on one topic.
>
> In my current project, I implements something similar to line numbers.
> At the beginning, I separate them into different canvases so that the GUI
> behaves like iTunes(later I found that they do not implement it in a
> consistent way), but now I like the way that racket already provides, to
> override the (on-paint) method of text%, its first argument gives the
> change to draw something before or after the text% itself is displayed.
>
> On Thu, Mar 9, 2017 at 9:51 AM, WarGrey Gyoudmon Ju  > wrote:
>
>> Okay, in the gui framework, there is an interface text:line-numbers<%>
>>
>> On Thu, Mar 9, 2017 at 9:46 AM, WarGrey Gyoudmon Ju <
>> juzhenli...@gmail.com> wrote:
>>
>>> But sometimes I happened to see that some one-line codes and their line
>>> number are overlapped.
>>> And line numbers are also controlled by the same horizontal scrollbar(I
>>> mean, it is contained in the scrollbar's view, if there is another canvas
>>> this should not happen).
>>>
>>> Maybe they are displayed in a special image box(also, those non-string
>>> snips may produce lines that bigger than text line height).
>>>
>>> On Thu, Mar 9, 2017 at 9:31 AM, WarGrey Gyoudmon Ju <
>>> juzhenli...@gmail.com> wrote:
>>>
 I think, line numbers are likely displayed in another canvas.
 The current implementation of text% does not support advanced font
 features, the line height therefore is always the same. Displaying the line
 numbers just consists of a bit of arithmetic.

 On Thu, Mar 9, 2017 at 8:31 AM, 武晓宇  wrote:

>   I want to implement a text% object. And display the line number when
> string is inserted the text/canvas area.
>   Like the DrRacket IDE in "show line number" mode.
>   I read the source code of DrRacket but do not find the answer. Could
> anyone give a hand?
>
> --
> 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.
>

-- 
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] Predictable random...so to say

2016-12-02 Thread Daniel Feltey
I think something like this works:

;; shuffle/seed : list? integer -> list?
(define (shuffle/seed lst seed)
  (random-seed seed)
  (shuffle lst))

> (define a-list (list 1 2 3 4 5 6 7 8 9 10))
> (shuffle/seed a-list 0)
'(3 4 9 8 5 1 10 7 6 2)
> (shuffle/seed a-list 0)
'(3 4 9 8 5 1 10 7 6 2)
> (shuffle/seed a-list 1)
'(3 2 1 8 5 10 4 7 6 9)
> (shuffle/seed a-list 1)
'(3 2 1 8 5 10 4 7 6 9)



On Fri, Dec 2, 2016 at 2:05 AM,  wrote:

> Hi,
>
> is there a racket function, which shuffles a list of items
> based on a seed value...that is: Same seed value results in
> same shuffle results?
>
> Cheers
> Meino
>
> --
> 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.


[racket-users] Mixin questions

2016-08-11 Thread Daniel Feltey
If you want to inherit from both the frame and the tab in the mixin you
would write something like:

(mixin
  (drracket:unit:frame<%>
   drracket:unit:tab<%>)
  ()
  ;; body
  ...)

In this case the mixin will only work on classes that implement both the
tab and the frame interfaces, and you can now inherit methods from each
interface.

In general the 'mixin' form takes two lists of interfaces: the first are
those that arguments to the mixin must implement, the second are those that
the result of applying the mixin must implement.

Hope this helps,
Dan


On Thursday, August 11, 2016, Normal Loone > wrote:

> Does that mean, I can not use inherit on tab% here? Because that's my
> problem I need functions from both classes but I can only inherit from one,
> the other always results in runtime errors.
>
> Is there a way to use more from-interfaces than just one? The they it's
> worded suggested that you can use more than one parent interface.
>
> Like mainly, I want to use the function (current-tab) in frame% to figure
> out the opened tab and acquire the file name it is referencing. And then in
> tab% i want to override the function (break-callback) to print the filename
> out when ever a program is cancelled (for some reason break-call is a
> function in tab whereas execute-call is a function in frame...)

-- 
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] Re: Mixin questions

2016-08-10 Thread Daniel Feltey
When you write

(mixin (drracket:unit:frame<%>) (drracket:unit:tab<%>)
 ;; body
 ...)

This produces a function that takes classes which implement the
drracket:unit:frame<%> interface and produces classes that implement the
drracket:unit:tab<%> interface. In the body of the mixin you can only
assume that you have a class which implements drracket:unit:frame<%>, and
you will need to implement the methods that are required by the
drracket:unit:tab<%> interface, so you can't assume that those methods are
available in the body of the mixin.

I hope this helps, if not could you post an example program which is
causing the trouble,

Dan

On Wed, Aug 10, 2016 at 4:11 AM, Normal Loone 
wrote:

> The Documentation talks about range of classes, and I am not really sure
> what that means.
> Above would then be everything between frame and tab? But why cant I then
> not use frame functions in the implementation?
>
> --
> 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] Question on contracts -- check equal length of args

2016-07-15 Thread Daniel Feltey
Here's a version that uses a #:pre condition:

#lang racket

(define/contract (tau l m)
  (->i ([list1 (listof (and/c exact-integer? (>/c 0)))]
[list2 (listof (and/c exact-integer? (>/c 0)))])
   #:pre (list1 list2) (= (length list1) (length list2))
   [_ number?])
  (begin
(println "I was called")
300))

(tau '(8) '(9))   ;; this succeeds
(tau '(8) '(9.0)) ;; this doesn't satisfy the contract anymore
(tau '(8) '(9 10)) ;; neither does this

For differentiating between integers like 9 and 9.0, the predicate you want
to use is `exact-integer?`. The `integer?` predicate accepts both exact and
inexact integers which can be a little strange at first.

Dan



On Fri, Jul 15, 2016 at 11:22 AM, David Storrs 
wrote:

> Hi folks,
>
> I'm writing a stats library (I'm sure there is already one out there;
> this is a learning exercise), and I'm currently implementing Kendall's
> Tau-a.  I've got my head wrapped part of the way around contracts, but
> not all the way.  I'd like to be able to express the following:
>
> (tau l m)
> - l is a non-empty list of numbers, all greater than 0
> - m is a non-empty list of numbers, all greater than 0
> - l and m are of the same length
>
> Here's a stub version that does the first two checks:
>
> (define/contract (tau l m)
>   (-> (listof (and/c integer? (>/c 0)))
>   (listof (and/c integer? (>/c 0)))
>   number?)
>   300)
>
> (tau '(8) '(9));; should succeed and does
> (tau '(8) '(9.0))  ;; should fail (element is not integer) => SUCCEEDS??
> ;;
> ;; not implemented
> ;; (tau '(8) '(9 10)) ;; should fail -- different length lists
>
>
> I figured I'd let the 'integer?' failure go for a minute and focus on
> the missing criteria (lists are of equal length).  First, I wanted to
> make sure that I had understood the ->i syntax, so I did this:
>
> (define/contract (tau l m)
>   (->i ([list1 (listof (and/c integer? (>/c 0)))]
> [list2 (list1) (and/c
> (listof (and/c integer? (>/c 0])
>
>[result (list1 list2) number?])
>   300)
>
> Okay, good, that has the same results as the one above.  Now let's try
> to get the 'equal length' criteria working.
>
> (define/contract (tau l m)
>   (->i ([list1 (listof (and/c integer? (>/c 0)))]
> [list2 (list1) (and/c
> (listof (and/c integer? (>/c 0)))
> (equal? (length list1) (length list2)))])
>
>[result (list1 list2) number?])
>   (begin
> (println "I was called")
> 300))
>
> Result =>
> t.rkt:21:79: list2: unbound identifier in module
>   in: list2
>
> Nope.  Unsurprisingly, 'arg2' is not available inside its own binding.
>
>
> At this point I faffed around with implementing the check as a
> precondition or in the result function, and everything else I could
> think of, all to no avail.
>
>
> How do I do this?  It feels like it shouldn't be this hard.
>
>
> On a separate question:  How do I contribute to the docs?  The
> contract docs are nearly silent on using preconditions and
> postconditions, Section 7.4, "A Thorough Example of Contracts" is
> anything but thorough, and the docs could stand to include more
> examples in general.  I'd love to help future Racket students
> understand what's going on.
>
>
> Dave
>
> --
> 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] why this error?

2016-04-26 Thread Daniel Feltey
Can you give a little more context?

I tried running your program in DrRacket and it seems to work, or at least
I don't get the error you're seeing.

Dan

On Tue, Apr 26, 2016 at 7:39 PM, Andreas Petrou  wrote:

> My code is here:)
> ;3.) A function called allDiff? that takes as parameters two lists. The
> function returns #t if none of  the elements in the first list can be found
> in the second
> (
>  define (allDiff? list1 list2)
> ( if (null? list1) '()
>( if (null? (cdr list1))
>  (if (memq (car list1) list2) #f #t)
>(if (memq (car list1) list2) #f
>(allDiff? (cdr list1) list2))
>)
>)
>   )
>
> See this error. Please Help
> list1: undefined;
>  cannot reference an identifier before its definition
>
> --
> 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] Cycle in loading. Units, (sub)modules, files...

2016-01-08 Thread Daniel Feltey
This doesn't quite answer your question, but another possibility that would
allow you to separate the a@ and b@ unit implementations in separate files
is to put all of your signature definitions in a single file that will be
required by both "a.rkt" and "b.rkt". In my experience, this strategy is
fairly common in uses of units in the Racket codebase (for example see
https://github.com/racket/games/blob/master/gobblet/sig.rkt).

Dan

On Wed, Jan 6, 2016 at 8:16 AM, Jonas Winje  wrote:

> Hello people,
>
> I've been fumbling around with cyclic dependencies and such and have
> started looking at signatures and units. I manage to make the cycles work
> out in a couple different ways, but I'm running into trouble when I try to
> put different parts in different files the way I want them. As far as I can
> tell it has to do with how much of a file/module is "loaded" if I really
> just want to require one of its submodules. Not particularly certain.
>
> It's pretty possible that I'm just doing everything wrong and backwards,
> or should really not be trying to do this to begin with, or something :)
>
> So: Does anyone know if it is possible to do something along the lines of
>
> - a.rkt with two submodules:
> - a-sig: provides signature a^
> - a-impl:
> - requires a-sig
> - requires b-sig from b.rkt
> - provides unit a@ (which imports b^ and exports a^)
> - b.rkt with two submodules:
> - b-sig: provides signature b^
> - b-impl:
> - requires b-sig
> - requires a-sig from a.rkt
> - provides unit b@ (which imports a^ and exports b^)
>
> without getting
>
> standard-module-name-resolver: cycle in loading
>   at path: ...\dep\b.rkt
>   paths:
>...\b.rkt
>...\a.rkt
>
> ?
>
> I get it to work by putting all 4 modules in the same file. And I get it
> to work by putting them in 4 different files. But if I want one file for
> both the a-things and one for both the b-things I get the error above.
> Presumably because (a submodule in) "a.rkt" requires (a submodule from)
> "b.rkt", and other way around. (Even though the "b.rkt"-submodule required
> in "a.rkt" does *not* require anything from "b.rkt", and other way around.)
>
> Examples:
>  * seems to work: https://gist.github.com/Glorp/c36bcb3af0d8586ec733
>  * doesn't seem to work:
> https://gist.github.com/Glorp/86e59ced2bd838d2161c
>
> --
> 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] read-line reads only a character at a time from file.

2015-12-17 Thread Daniel Feltey
I think the issue is that `read-line` is returning a string, so in every
iteration of the for loop line is bound to a single character from that
string, I think you may want to use `in-lines`[1] instead of `read-line`.

[1]:
http://docs.racket-lang.org/reference/sequences.html?q=in-lines#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-lines%29%29

On Thu, Dec 17, 2015 at 2:19 AM, Mark Thom  wrote:

> As an exercise, I'm implementing a simple grep function in Racket:
>
> (define (grep-file pattern . files)
>   (for ([file-path (in-list files)])
> (with-input-from-file file-path #:mode 'text
>   (lambda ()
> (for ([line (read-line (current-input-port) 'return-linefeed)]
>   [i (in-naturals 1)])
>   (match line
> [(regexp pattern)
>  (printf "~D : ~S~%" i line)]
> [else (printf "~S~%" line)]))
>
> I expect that read-line should read properly terminated lines from files.
> Instead, each value of line in the inner for is a single character from
> the file.
>
> I can't seem to find any mention of a similar problem online, or reproduce
> it in any other context. The same behavior follows regardless of whether
> the file is DOS or Unix formatted.
>
> I'm running Racket 6.2.1 on Windows 7. 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.
>

-- 
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] Long-term Runtime session state

2015-10-13 Thread Daniel Feltey
>  I just never found any good docs on how to do that. Near as I can tell,
runtime linking of a unit is even MORE verbose and persnickety than just
>  manually typing in all the procedures you want to pass to a callback

Some of the verbosity of units can be reduced using the "inference"
features that Racket's unit system provides.

Here's one way to do this:

;; define a signature that contains info about your runtime data
(define-signature runtime-data^ (runtime-value))

;; define a unit that encapsulates the initialization of data you need at
runtime
(define-unit runtime-data@
  (import)
  (export runtime-data^)
  (define runtime-value ...))

;; Implement the rest of your program in a unit which imports the
runtime-data^ signature
(define-unit use-runtime-data@
  (import runtime-data^)
  (export)
  ;; your main program code goes here ...
  )

;; link together the units to run your program
(invoke-unit/infer (link runtime-data@ use-runtime-data@))


There is still some syntactic overhead, but using unit inference does
alleviate many of the confusing parts of manually linking and invoking
units.

Dan

On Tue, Oct 13, 2015 at 7:07 PM, Nota Poin  wrote:

> On Tuesday, October 13, 2015 at 11:40:12 PM UTC, Alexis King wrote:
> > units
>
> Oh uh, conceivably you could have "code" that provided a live session
> object on linking, and handled session refreshing internally, then just
> link that with units that have session dependant code. I just never found
> any good docs on how to do that. Near as I can tell, runtime linking of a
> unit is even MORE verbose and persnickety than just manually typing in all
> the procedures you want to pass to a callback.
>
> --
> 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] Redex: call for alpha-equivalence beta testers

2015-09-19 Thread Daniel Feltey
> and then get Paul's version:
>
>   cd redex
>   git remote add paul https://github.com/paulstansifer/redex-1.git
>   git checkout public
>   raco setup

This didn't quite work for me the first time I tried it, I needed to run
`git fetch paul` before the checkout to make it work.

Looking forward to trying this out!

Dan

On Sat, Sep 19, 2015 at 12:21 PM, Robby Findler  wrote:

> Paul Stansifer has been implementing the ideas from his dissertation
> work in Redex and is now ready to share them with the world.
>
> Thanks to Paul, Redex languages now understand binding structure,
> meaning that if you write a substitution function that just blindly
> substitutes, it will actually properly do alpha conversion to avoid
> name collisions. In general, pattern matching now has alpha
> equivalence smarts (see the docs for more).
>
> The new features include the #:binding keyword in define-language and
> extend-language, and the alpha-equivalent? and substitute functions.
>
> The plan is to let it stay only in Paul's repo until the next release
> goes out and then push it to the main Redex repo to be included in the
> release after this one. If you'd like to give it a try, some
> instructions are below. Please let us know how it goes!
>
> Robby
>
>
> 
>
> To try it out, first download a snapshot build:
>
>http://pre.racket-lang.org/installers/
>
> and then create a parent directory to hold the git repo for Redex:
>
>   cd PLTDIR; mkdir extra-pkgs; cd extra-pkgs
>
> run this command to get the git version of Redex:
>
> raco pkg update --clone redex \
>   "git://github.com/racket/redex?path=redex" \
>   "git://github.com/racket/redex?path=redex-benchmark" \
>   "git://github.com/racket/redex?path=redex-doc" \
>   "git://github.com/racket/redex?path=redex-examples" \
>   "git://github.com/racket/redex?path=redex-gui-lib" \
>   "git://github.com/racket/redex?path=redex-lib" \
>   "git://github.com/racket/redex?path=redex-pict-lib" \
>   "git://github.com/racket/redex?path=redex-test"
>
> and then get Paul's version:
>
>   cd redex
>   git remote add paul https://github.com/paulstansifer/redex-1.git
>   git checkout public
>   raco setup
>
> --
> 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] Dozens and dozens of interdependent modules, better to use include?

2015-05-28 Thread Daniel Feltey
If the issue you're facing is mutual dependencies between modules, then using 
units[1] is one possible solution. 

Units are first-class modules that allow cyclic linking, and would avoid the 
need to use include. In particular using #lang racket/unit [2] may be useful to 
convert each the modules required by main.rkt into a unit. Then main.rkt would 
probably link the required modules together and invoke the result.

Dan


[1]: http://docs.racket-lang.org/guide/units.html
[2]: http://docs.racket-lang.org/guide/Whole-module_Signatures_and_Units.html


- Original Message -
From: Lux glsdes...@gmail.com
To: racket-users@googlegroups.com
Cc: michael tiedtke michael.tied...@o2online.de
Sent: Thursday, May 28, 2015 2:48:46 PM
Subject: Re: [racket-users] Dozens and dozens of interdependent modules, better 
to use include?

I am sorry, I've not explained well my intents.
My actual situation is like this:
I have a main.rkt file which require the most of all other modules, and it is 
the entry point of the application, it provide access to almost all procedures 
contained in the required modules.
Modules are abundant in number and any one need to require procedures from tens 
of other modules. It is an intricate web of relations, fairly hard to maintain 
and reason about, in effect.

What I was asking is if will be acceptable and/or advisable to have another 
type of approach:
Having a main.rkt which use (include path-spec) from racket/include to inline 
code from what was before a collection of modules, and now simply a collection 
of source files containing a bunch of functions, loaded in a specific order, 
without providing or requiring anything explicitly, because all will be finally 
accumulated in the sole namespace of main.rkt.

It will be possible even to make a script which will compile this set of 
files in a single program.rkt of one million of line of code (joking). If not 
for the ugliness of this, it can be done easily.

But I am not sure this is the way to go, feels like an hack... I need some 
confirms it is not a big no no.



On Thursday, May 28, 2015 at 6:53:19 PM UTC+2, Michael Tiedtke wrote:
 Include can't really handle mutual require references (if not with a main 
 file which holds all the excludes) but in general cyclic references were only 
 a problem for really old garbage collectors, I heard. Perhaps this is why a 
 lot of people try to avoid interdependencies in memory, in disk and ...
 
 This straightforward analysis caught three full days worth of never-executed 
 branches, transitive require assumptions, spelling errors, undocumented 
 procedures, missing procedures, and cyclic dependencies in SLIB.
 
 Perhaps it's still worthwile having a look at the origins of /require/ and 
 /provide/ when it comes to the Scheme: SLIB
 http://people.csail.mit.edu/jaffer/slib/The-Library-System.html
 
 With the concept of a catalog datastructure one could come up with a solution 
 based on /include/ or even try to fiddle around with the require 
 definitions with /read/? One could even try to fix Racket's module system. 
 Instead of outputting the error message that something cyclic was found one 
 could stop that cycle and simply go on?

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