[racket-users] Ambiguous binding error, and trying to add generic-interface inheritance

2015-09-23 Thread Alexander D. Knauth
I'm trying to add inheritance to generic interfaces:
https://github.com/AlexKnauth/racket/tree/gen-extends 


But it's in a weird state where it's passing some of the time, (seemingly 
depending on how exactly I fiddle with it, compile it, restart DrRacket, and/or 
other things), but the other times it's giving me ambiguous binding errors like 
this:

https://travis-ci.org/AlexKnauth/racket/jobs/81884173#L1461 


pkgs/racket-test/tests/generic/extend.rkt:6:3: get: identifier's binding is 
ambiguous
  context...:
   #(894142 module) #(894143 module extend 0) #(895177 macro) #(895618 local)
   #(895650 intdef) #(895651 local) #(895652 intdef) #(895655 local)
   #(895656 intdef) #(895661 local) #(895663 intdef) #(895664 local)
   #(895665 intdef) #(895666 local) #(895667 intdef) #(895671 local)
   #(895673 intdef) #(895674 local) #(895675 intdef)
  matching binding...:
   local get128618
   #(894142 module) #(894143 module extend 0) #(895618 local) #(895650 intdef)
   #(895651 local) #(895652 intdef) #(895655 local) #(895656 intdef) #(895661 
local)
   #(895663 intdef) #(895664 local) #(895665 intdef) #(895666 local)
   #(895667 intdef) #(895671 local) #(895673 intdef) #(895674 local)
   #(895675 intdef)
  matching binding...:
   local get128614
   #(894142 module) #(894143 module extend 0) #(895177 macro) #(895618 local)
   #(895650 intdef) #(895651 local) #(895652 intdef) #(895655 local)
   #(895656 intdef) #(895661 local) #(895663 intdef) #(895664 local)
   #(895665 intdef) #(895666 local)
  matching binding...:
   #f
   #(894142 module) #(894143 module extend 0)
  in: get
  compilation context...:
   
/Users/travis/build/AlexKnauth/racket/pkgs/racket-test/tests/generic/extend.rkt
  context...:
   
/Users/travis/build/AlexKnauth/racket/racket/collects/racket/private/generic-methods.rkt:161:2

I'm also getting errors from data/order.rkt, but that's a separate problem, and 
an easy one to fix. (I already did on my computer, but Travis is getting 
data/order from the package, not from my computer.)

Do you have any idea what's going on, or how to do this right?

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


Re: [racket-users] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-23 Thread Alexander D. Knauth

> On Sep 23, 2015, at 8:53 AM, Marc Kaufmann  wrote:

> #lang racket/base
> 
> (require scribble/base
> scribble/core)
> 
> (provide equation*)
> 
> (define (mymath start end . strs)
>  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))
> 
> (define (equation* . strs)
>  (apply mymath "\\begin{equation*}" "\\end{equation*}" strs))
> 
> 
> 
> I still do not understand why I have to type "\\" rather than "\". I get that 
> something somewhere is escaping the backslash. I am uncomfortable with this, 
> as it seems that "{" and "}" are not escaped, but since I do not know what is 
> and what isn't, I may at some point in the future get a cryptic error message 
> because I used a command or a character in the strings that gets unescaped.

To avoid dealing with escapes like that, you could use the raw-string package, 
which lets you do this:
raco pkg install raw-string

#lang raw-string/raw-string racket/base #\$

(require scribble/base
 scribble/core)

(provide equation*)

(define (mymath start end . strs)
  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))

(define (equation* . strs)
  (apply mymath $[\begin{equation*}] $[\end{equation*}] strs))

Those don't have to be [] brackets, they could be (), {}, <>, "", '', ^^, or 
any other pair of characters, as long as you don't try to put the ending 
character in the string.

You could also use at-exp for that, but raw-string is simpler.

-- 
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: line comment swallows paragraph break

2015-09-17 Thread Alexander D. Knauth
I forgot to include the list:

> On Sep 17, 2015, at 10:57 AM, Alexander D. Knauth  
> wrote:
> 
> Is there any reason why
> #lang at-exp racket
> '@stuff{
> Hello @; John
> 
> World
> }
> Shouldn't produce
> '(stuff "Hello " "\n" "\n" "World")
> Instead of
> '(stuff "Hello " "\n" "World")
> ?
> In other words, should the newline after the line comment still count as a 
> newline?
> 
>> On Sep 17, 2015, at 10:49 AM, Matthew Flatt  wrote:
>> 
>> Scribble can't be changed to match LaTeX without changing @-expression
>> reader at a fairly fundamental way, and I'm skeptical of the change.
>> 
>> Scribble's input is handled in three steps: @-expression parsing to
>> produce a syntax object (i.e., enriched S-expression), Racket expansion
>> and evaluation of the resulting syntax objects to produce values, and
>> (interleaved with the second step) a `scribble/decode` layer that is
>> used by some contexts (including the module body for `scribble/manual`)
>> to find paragraph based on the values produces by the second step. A
>> paragraph is determined at that last step as a pair of newlines
>> separated only by whitespace content.
>> 
>> LaTeX handles input in one big character-oriented sweep. In the default
>> mode, it effectively sees a source line that contains only white space
>> (before comment or other handling) and converts it into a `\par`. So,
>> it's detecting paragraphs at a much earlier point than Scribble 
>> unless you're in something like a `verbatim` environment, where that
>> character-level handling is changed and blank lines are handled in a
>> different way. Of course, the character-level nature of macros is one
>> of the things that makes TeX macros so powerful, but also one of the
>> things that make them non-composable.
>> 
>> For Scribble to define paragraph breaks in terms of blank source lines
>> (i.e., blank before handling comments or other expansions), the notion
>> of paragraph breaks would have to be built into @-expression layer.
>> Since the notion of paragraph breaks doesn't apply to some uses of
>> @-expression notation, paragraph breaks would have to reflected in some
>> different way than, say, inserting `(par)` into the stream as in LaTeX.
>> A syntax property could be attached to a newline to indicate that its
>> source line is blank, but those are fragile (e.g., not preserved in
>> bytecode), and they only work on syntax-object representations of
>> S-expressions. Whatever a better solution might be, I think an even
>> better "solution" is to not to try to solve this problem and keep the
>> @-expression model simpler.
>> 
>> At Wed, 16 Sep 2015 18:42:22 -0400, Benjamin Greenman wrote:
>>> Scribble and LaTeX disagree on these documents. Should Scribble be changed
>>> to match LaTeX?
>>> 
>>> Scribble:
>>> #lang scribble/manual
>>> 
>>> Hello @; John
>>> 
>>> World
>>> 
>>> Output is:
>>> "Hello World"
>>> 
>>> ;; ---
>>> 
>>> LaTeX
>>> \documentclass{article}
>>> \begin{document}
>>> Hello % John
>>> 
>>> World
>>> \end{document}
>>> 
>>> Output is:
>>> "Hello
>>> World"
>>> 
>>> -- 
>>> 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] Macro-generating macros

2015-09-04 Thread Alexander D. Knauth

> On Sep 4, 2015, at 4:26 AM, Konrad Hinsen  wrote:
> 
> Brian Mastenbrook writes:
> 
>> It's a capture problem. In the first case, you're just binding the
>> name "send" locally and all is well. In the second case, you're
>> trying to introduce a binding for "send" that you didn't get from
>> the input form.
> 
> Ahhh that one has bitten me before, but I had forgotten about it.
> Thanks for the reminder!
> 
>> You're also getting a confusing error because "send" is already
>> bound; try using a name that's not already defined and you should
>> get an unbound identifier.
> 
> I used a bound symbol intentionally to see if I can shadow an existing
> syntax transformer binding.

Ok, if you *really* want to shadow an existing binding, you can use 
datum->syntax, but using a syntax parameter is much better:
(define-syntax (def stx)
  (syntax-parse stx
[(_ (fn-name:id arg:id ...) body ... )
 #:with send-id (datum->syntax #'fn-name 'send)
 #'(define (fn-name arg ...)
 (let-syntax ([send-id (λ (stx)
 (syntax-parse stx
   [(send-id obj:expr method:id x:expr (... 
...))
#'(method obj x (... ...))]))])
   body ...))]))

>> Alternatively, you can use a syntax parameter, which is probably
>> the ideal solution here.
> 
> At least it's one that works. It feels like cheating to use dynamic
> scoping to get around a problem with lexical scoping, but knowing when
> to cheat is a fundamental competence when dealing with any bureaucracy ;-)

Um, the reason a syntax parameter is better is that it *does* follow the 
lexical scoping rules, where the unhygienic version does weird things you 
wouldn't expect. Using datum->syntax is cheating a lot more, and syntax 
parameters deal with problems like this in a much better way.

P.S.
Have you read Fear of Macros? If you haven't, I highly recommend it because 
it's awesome.

> Thanks again,
>  Konrad.

-- 
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] Lost in ellipsis depths

2015-09-02 Thread Alexander D. Knauth

> On Sep 2, 2015, at 7:09 AM, Konrad Hinsen  wrote:
> 
> Konrad Hinsen writes:
> 
>> In fact, what I want is do something like map over the ellipsis pattern,
>> but I haven't seen any example for doing this.
> 
> Well, map actually works:
> 
>  (syntax-parse #'(foo a b c)
>[(f:id s:id ...)
> (with-syntax ([(foo-s ...)
>(map (λ (x) (format-id #'f "foo-~a" x)) (syntax-e #'(s 
> ...) ))])
>   #'(list foo-s ...))])
> 
> But is this the only solution? It looks a bit messy.
> 
> Konrad.

To make it look a little less messy, here's what I would do for stuff like this:
(require fancy-app syntax/parse syntax/stx) ; in a for-syntax if necessary
(syntax-parse #'(foo a b c)
  [(f:id s:id ...)
   #:with (foo-s ...) (stx-map (format-id #'f "foo-~a" _) #'(s ...)) ; the _ 
makes a fancy-app anonymous function
   #'(list foo-s ...)])

Or if it's something more complicated, I would use a for/list instead of a 
stx-map.

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.


Re: [racket-users] Creating a language that extends typed/racket

2015-08-30 Thread Alexander D. Knauth

> On Aug 30, 2015, at 6:31 PM, Alexis King  wrote:
> 
> (Disclaimer: I think this question may have been visited before on this 
> mailing list, but I couldn’t find any resolution, so I’m going to ask again.)

Yes. What came out of it was this, which they got to work:
https://github.com/khinsen/racket-typed-lang

> I would like to write a language that extends typed/racket or 
> typed/racket/base. Specifically, I have a collection, called “envy”. I would 
> like to create a `#lang envy` that is just like #lang typed/racket/base, but 
> also includes (all-from-out envy). My first instinct was just to create a 
> language using syntax/module-reader, along with a simple module language:
> 
>   #lang typed/racket/base
>   (require envy)
>   (provide (all-from-out envy typed/racket/base))
> 
> Unfortunately, this doesn’t work. The `envy` module defines a macro called 
> `define-environment`, but attempting to use it in this `#lang envy` fails:
> 
>   Type Checker: Macro define-environment from typed module used in untyped 
> code in: (define-environment)
> 
> So that doesn’t work. For some reason, the typechecker thinks `#lang envy` is 
> untyped (though it seems to typecheck properly when not using macros). 
> However, I realized that `#lang typed/racket` is a module language that 
> obviously extends typed/racket/base. It uses typed-racket/minimal, but using 
> that instead of typed/racket/base didn’t alleviate my problem.
> 
> Is it possible to create a custom language that extends typed/racket/base? 
> How does typed/racket itself do it?
> 
> Alexis
> 
> -- 
> 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] unclear about this `parameterize` behavior

2015-08-30 Thread Alexander D. Knauth
To add to that a little bit, this is what I found:
#lang multi-file
#file param.rkt
#lang racket
(provide my-param)
(define my-param (make-parameter 'default))

#file param-test.rkt
#lang racket
(require "param.rkt")
(define-namespace-anchor a)
(parameterize ([current-namespace (make-base-namespace)]
   [error-print-width 4242]
   [my-param 'custom])
  ;(namespace-attach-module (namespace-anchor->namespace a) "param.rkt" 
(current-namespace))
  (namespace-require "param.rkt")
  (eval '(begin (printf "(error-print-width) = ~v\n" (error-print-width)) ;; 
4242, not 250
(printf "(my-param)  = ~v\n" (my-param))  ;; 
'default
)))

With the namespace-attach-module call commented out, this prints
#file param.rkt
#file param-test.rkt
(error-print-width) = 4242
(my-param)  = 'default

But if I uncomment that line, I get:
#file param.rkt
#file param-test.rkt
(error-print-width) = 4242
(my-param)  = 'custom

And if I move the namespace-attach-module call to after the (namespace-require 
"param.rkt"), I get this:
#file param.rkt
#file param-test.rkt
. namespace-attach-module: a different module with the same name is already in 
the destination namespace
  module name: "/Users/Alex/Documents/DrRacket/param-thing/param.rkt"

I hope that helps!

Alex Knauth

> On Aug 30, 2015, at 3:36 PM, Matthew Flatt  wrote:
> 
> The `make-base-namespace` function creates a new namespace, but it
> attaches the `racket/base` instance of the current namespace to the new
> one. The `error-print-width` parameter comes from `racket/base`, so
> it's still the same parameter.
> 
> You can use `namespace-attach-module` to attach "param.rkt" to the new
> namespace, too, if you want its instance and parameter to be shared
> across the namespaces.
> 
> At Sun, 30 Aug 2015 12:04:30 -0700, Matthew Butterick wrote:
>> In the example below, I'm curious about the reason for the difference 
>> between 
>> the behavior of the system parameter `error-print-width` and the custom 
>> parameter `my-param`. 
>> 
>> I understand why `my-param` doesn't take the parameterized value 'custom (= 
>> because `namespace-require` causes a fresh instantiation of "param.rkt" in 
>> the 
>> new namespace, which binds `my-param` with its default value). 
>> 
>> But if that's the case, then why does `error-print-width` accept the 
>> parameterized value? Why doesn't it get instantiated at its default value of 
>> 250 when the new namespace is made?
>> 
>> 
>> ;; param.rkt
>> #lang racket
>> (provide my-param)
>> (define my-param (make-parameter 'default))
>> 
>> 
>> ;; param-test.rkt
>> #lang racket
>> (require "param.rkt")
>> (parameterize ([current-namespace (make-base-namespace)]
>>   [error-print-width 4242]
>>   [my-param 'custom])
>>  (namespace-require "param.rkt")
>>  (namespace-require 'rackunit)
>>  (eval '(begin (check-equal? (error-print-width) 4242) ;; not 250
>>(check-equal? (my-param) 'default 
>> 
>> -- 
>> 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] (set-implements? (mutable-set) 'set-add)

2015-08-24 Thread Alexander D. Knauth
Was it this commit here?
https://github.com/plt/racket/commit/606a94621253391536e9c89c573dc70fd28efbe6

On Aug 24, 2015, at 5:50 PM, Alexander D. Knauth  wrote:

> It seems to me that (set-implements? (mutable-set) 'set-add) should return 
> #f, and in 6.1.1 (and I think 6.2), that's true.
> 
> But in the latest snapshots, it produces #t.
> 
> It seems like it's implemented as an error message instead of not implemented 
> at all, and `set-implements?` can't tell the difference between implemented 
> with an error message and actually implemented.
> 
> Is this a choice with reasons behind it, or should this be a bug?
> 
> 
> -- 
> 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] (set-implements? (mutable-set) 'set-add)

2015-08-24 Thread Alexander D. Knauth
It seems to me that (set-implements? (mutable-set) 'set-add) should return #f, 
and in 6.1.1 (and I think 6.2), that's true.

But in the latest snapshots, it produces #t.

It seems like it's implemented as an error message instead of not implemented 
at all, and `set-implements?` can't tell the difference between implemented 
with an error message and actually implemented.

Is this a choice with reasons behind it, or should this be a bug?


-- 
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] My son's game in Racket

2015-08-24 Thread Alexander D. Knauth
Or something like this, with the rackjure package:
(require rackjure/threading 2htdp/image)
(~>> background-img
 (place-image image-1 x y) ; the background-img will be inserted as the 
last argument, because that's what ~>> does
 (place-image image-2 x y) ; the background + image-1 will be inserted as 
the last argument
 (place-image image-3 x y) ; and so on
 ...)
Or if you don't want to use rackjure, then with let* it would be:
(let* ([img background-img]
   [img (place-image image-1 x y img)]
   [img (place-image image-2 x y img)]
   [img (place-image image-3 x y img)]
   ...)
  img)

On Aug 24, 2015, at 2:40 PM, Joel McCracken  wrote:

> This would be where I would reach for a let* to handle intermediate
> results, because code like this is very awkward.
> 
> On Mon, Aug 24, 2015 at 2:32 PM, John Carmack  wrote:
>> The idea that you functionally compose images like this:
>> 
>> (place-image image-1 x y
>>(place-image image-2 x y
>>(place-image image-3 x y)))
>> 
>> Which draws image1 on top of image2 on top of image 3, which is backwards 
>> from the "painters order" that would draw image 3, then image 2, then image 
>> 1.
>> 
>> This imperative, side-effect-ing code is a little less clear to a beginner 
>> with the OOP and DC concepts, but It better represents what actually 
>> happens, and it is much easier to modify the code without worrying about the 
>> nesting.
>> 
>> (send dc draw-bitmap imag3 x y)
>> (send dc draw-bitmap imag2 x y)
>> (send dc draw-bitmap imag1 x y)
>> 
>> -Original Message-
>> From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com] 
>> On Behalf Of David Grenier
>> Sent: Monday, August 24, 2015 1:14 PM
>> To: Racket Users
>> Cc: John Carmack
>> Subject: [racket-users] Re: My son's game in Racket
>> 
>> On Monday, August 24, 2015 at 12:28:07 PM UTC-4, John Carmack wrote:
>>> We “released” my 10 year old son’s game that was done in Racket:
>>> www.1k3c.com
>>> 
>>> 
>>> 
>>> I’m still taking a little heat from my wife for using an obscure
>>> language instead of something mainstream that is broadly used in industry, 
>>> but I have nothing but good things to say about using Racket and DrRacket 
>>> for a beginning programmer,  and highly recommend it.
>>> 
>>> 
>>> 
>>> I can’t recommend 2htdp/universe for this sort of thing, though.  I
>>> had to drop to the native GUI bitmaps for performance reasons, hack around 
>>> the lifecycle to support a separate editor window, and I still don’t know 
>>> how to make the Quit  menu item actually exit the app on the Mac version.
>>> 
>>> 
>>> 
>>> I completely understand the reasoning for the way 2htdp/universe is
>>> built, and saying that a “real” project should use the grown-up APIs is 
>>> fine, but the evolution from making a little animation to controlling it 
>>> somehow to fleshing it  out into a game is so natural that recommending a 
>>> fairly big rewrite is unfortunate.
>>> 
>>> 
>>> 
>>> I’m a big booster of functional programming, but I’m not sure that the
>>> functional drawing paradigm ever really sank in while my son was working 
>>> with it, rather it felt like you just drew everything backwards with 
>>> missing parenthesis at  the end.  I suspect that using the standard 
>>> imperative GUI drawing code will make perfect sense to him.
>>> 
>>> 
>>> 
>>> I’m not sure yet if we are going to migrate to the regular GUI code for 
>>> upcoming work, or jump all the way to OpenGL so he can learn the joys of 
>>> “Why is the screen all black?”
>>> 
>>> 
>> 
>> Not clear what was meant both times you wrote "backwards" are you referring 
>> to the lisp-style function call? Something that could be alleviated by say 
>> F#'s pipe forward operator?
>> 
>> let (|>) a f = f a
>> 
>> or Clojure's -> macro?
>> 
>> --
>> 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://urldefense.proofpoint.com/v1/url?u=https://groups.google.com/d/optout&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=Kjg6LltY9QjkipKooaVldA%3D%3D%0A&m=HArZE0M9OqU4wspKLzQzG6N5gO9ncSxPP9qVzkUgoVU%3D%0A&s=b451faca736dc42c554f148983e7279865ef32be9ddf2df75f5c88c15dd34a73.
>> 
>> --
>> 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 receive

Re: [racket-users] macro-generate attribute access?

2015-08-22 Thread Alexander D. Knauth
Does this get you what you want?
#lang racket
(require (for-syntax syntax/parse racket/syntax))

(define-syntax (define-stuff stx)
 (syntax-parse stx
   [(_ attr-name macro-name)
#:with c.attr-name (format-id #'c "~a.~a" #'c #'attr-name)
#'(begin
(begin-for-syntax
  (define-syntax-class C
(pattern any #:attr attr-name #'any)))
(define-syntax macro-name
  (syntax-parser
[(_ (~var c C))
 #'c.attr-name])))]))
(define-stuff an-attr a-macro)
(a-macro 1)


On Aug 21, 2015, at 12:57 PM, Stephen Chang  wrote:

> Is there a way to access an attribute, other than with the "." syntax?
> 
> For example, the following example does not work:
> 
> #lang racket
> (require (for-syntax syntax/parse))
> 
> (define-syntax (define-stuff stx)
>  (syntax-parse stx
>[(_ attr-name macro-name)
> #'(begin
> (begin-for-syntax
>   (define-syntax-class C
> (pattern any #:attr attr-name #'any)))
> (define-syntax macro-name
>   (syntax-parser
> [(_ (~var c C))
>  #'c.attr-name])))]))
> (define-stuff an-attr a-macro)
> (a-macro 1)
> 
> I've also tried various format-id's which I also can't get to work. Is
> there an alternate way, in the spirit of ~var vs ":", to get an
> attribute's value?
> 
> -- 
> 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] DrRacket crashing?

2015-08-21 Thread Alexander D. Knauth
I have no idea what's been happening, but in the past half hour or so DrRacket 
has crashed on me (I think) 6 times.
I don't know if this will help but here is what was in the error window that my 
computer gave me:

Process: DrRacket [20469]
Path:/Applications/Racket/*/DrRacket.app/Contents/MacOS/DrRacket
Identifier:  org.racket-lang.DrRacket
Version: 6.2.900.10 (6.2.900.10)
Code Type:   X86-64 (Native)
Parent Process:  launchd [165]
Responsible: DrRacket [20469]
User ID: 502

Date/Time:   2015-08-21 20:00:33.149 -0400
OS Version:  Mac OS X 10.9.5 (13F1096)
Report Version:  11
Anonymous UUID:  8ABEA743-D90C-CA8D-137C-2A4F0679E863

Sleep/Wake UUID: 09B771D9-37AF-4A41-A852-C8AC90205883

Crashed Thread:  7

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0008

VM Regions Near 0x8:
--> 
__TEXT 00010211e000-000102126000 [   32K] r-x/rwx 
SM=COW  /Applications/Racket/*/DrRacket.app/Contents/MacOS/DrRacket

Thread 0:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib  0x7fff9039da1a mach_msg_trap + 10
1   libsystem_kernel.dylib  0x7fff9039cd18 mach_msg + 64
2   com.apple.CoreGraphics  0x7fff8e73a74b 
_CGSSynchronizeWindowBackingStore + 97
3   com.apple.CoreGraphics  0x7fff8e6bc24c _CGSLockWindow + 3765
4   com.apple.CoreGraphics  0x7fff8e6bb15f CGSDeviceLock + 240
5   libRIP.A.dylib  0x7fff8daf3487 ripd_Lock + 43
6   libRIP.A.dylib  0x7fff8daf3027 RIPLayerBltShape + 
463
7   libRIP.A.dylib  0x7fff8daf1468 ripc_Render + 304
8   libRIP.A.dylib  0x7fff8daed3b9 ripc_DrawRects + 399
9   com.apple.CoreGraphics  0x7fff8e6b7afa CGContextFillRects + 
96
10  com.apple.AppKit0x7fff94b52d46 
NSRectFillUsingOperation + 299
11  com.apple.AppKit0x7fff94c0f0bd 
NSDrawWindowBackground + 253
12  com.apple.AppKit0x7fff94b31d04 -[NSThemeFrame 
drawWindowBackgroundRect:] + 129
13  com.apple.AppKit0x7fff94b315d0 -[NSFrameView 
drawThemeContentFill:inView:] + 293
14  com.apple.AppKit0x7fff94c0e715 -[NSFrameView 
drawRect:] + 1124
15  com.apple.AppKit0x7fff94c0e28a -[NSThemeFrame 
drawRect:] + 302
16  com.apple.AppKit0x7fff94b2d0b1 -[NSView 
_drawRect:clip:] + 3846
17  com.apple.AppKit0x7fff94b2a03c -[NSView 
_recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:]
 + 3199
18  com.apple.AppKit0x7fff94b28eb1 -[NSThemeFrame 
_recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:]
 + 314
19  com.apple.AppKit0x7fff94b25e9f -[NSView 
_displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2828
20  com.apple.AppKit0x7fff94b052da -[NSView 
displayIfNeeded] + 1680
21  Racket  0x00010249ef5c ffi_call_unix64 + 76
22  Racket  0x00010249f82d ffi_call + 973
23  Racket  0x00010248b460 ffi_do_call + 2192
24  Racket  0x00010248abac 
ffi_do_call_after_stack_check + 268
25  ??? 0x0001035eb959 0 + 4351506777
26  Racket  0x000102191d20 scheme_do_eval + 
13360
27  Racket  0x00010219286c 
_scheme_apply_multi_from_native + 364
28  ??? 0x00010357f01e 0 + 4351062046
29  ??? 0x00010358123d 0 + 4351070781
30  ??? 0x00010358123d 0 + 4351070781
31  Racket  0x000102191d20 scheme_do_eval + 
13360
32  Racket  0x0001021c87ff 
scheme_finish_apply_for_prompt + 639
33  Racket  0x0001021c8b80 
scheme_apply_for_prompt + 112
34  Racket  0x0001021b8e94 call_with_prompt + 
2532
35  ??? 0x0001035741d5 0 + 4351017429
36  Racket  0x000102191d20 scheme_do_eval + 
13360
37  Racket  0x0001021c87ff 
scheme_finish_apply_for_prompt + 639
38  Racket  0x0001021c8b80 
scheme_apply_for_prompt + 112
39  Racket  0x0001021b8e94 call_with_prompt + 
2532
40  ??? 0x0001035741d5 0 + 4351017429
41  ??? 0x0001035816eb 0 + 4351071979
42  Racket  0x000102191d20 scheme_do_eval + 
13360
43  Racket  

Re: [racket-users] Match value of symbol vs. binding to it

2015-08-17 Thread Alexander D. Knauth

On Aug 18, 2015, at 1:18 AM, Brian Adkins  wrote:

> On Tuesday, August 18, 2015 at 1:13:16 AM UTC-4, Alex Knauth wrote:
>> Is == what you're looking for?
>> Or do you want a version of == that uses string=? ?
> 
> I'm not sure what you're suggesting. I basically want a way to inject the 
> value of x into the pattern vs. using a literal such as "abc" since I need to 
> do this programmatically. The #:when clause and/or the ? function are 
> reasonable work arounds - I'm just hoping there's a more concise way to get 
> the value of x into the pattern.

I mean like this:
#lang racket
(define x "abc")
(match '(1 "abc")
  [(list 1 (== x)) #t]
  [_ #f])
Does that do what you want?

>> On Aug 18, 2015, at 12:55 AM, Brian Adkins  wrote:
>> 
>>> Consider the following:
>>> 
>>> (define x "abc")
>>> (match '(1 "abc")
>>> [ (list 1 y) #:when (string=? y x) #t ]
>>> [ _ #f ])
>>> 
>>> Is there a way to accomplish the same thing more concisely by interpolating 
>>> the value of x into the pattern? For example (non-working syntax):
>>> 
>>> (define x "abc")
>>> (match '(1 "abc")
>>> [ (list 1 ~x) #t ]
>>> [ _ #f ])
>>> 
>>> This also works, but seems overly verbose:
>>> 
>>> (define x "abc")
>>> (match '(1 "abc")
>>> [ (list 1 (? (λ (v) (string=? v x #t ]
>>> [ _ #f ])
>>> 
>>> I tried a few quasipatterns, but got nowhere.
>>> 
>>> Thanks,
>>> Brian
>>> 
>>> -- 
>>> 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] Match value of symbol vs. binding to it

2015-08-17 Thread Alexander D. Knauth
Is == what you're looking for?
Or do you want a version of == that uses string=? ?

On Aug 18, 2015, at 12:55 AM, Brian Adkins  wrote:

> Consider the following:
> 
> (define x "abc")
> (match '(1 "abc")
>  [ (list 1 y) #:when (string=? y x) #t ]
>  [ _ #f ])
> 
> Is there a way to accomplish the same thing more concisely by interpolating 
> the value of x into the pattern? For example (non-working syntax):
> 
> (define x "abc")
> (match '(1 "abc")
>  [ (list 1 ~x) #t ]
>  [ _ #f ])
> 
> This also works, but seems overly verbose:
> 
> (define x "abc")
> (match '(1 "abc")
>  [ (list 1 (? (λ (v) (string=? v x #t ]
>  [ _ #f ])
> 
> I tried a few quasipatterns, but got nowhere.
> 
> Thanks,
> Brian
> 
> -- 
> 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] macro making a struct with a macro

2015-08-17 Thread Alexander D. Knauth
I'm not sure why that doesn't work, but I redid it with my define-struct-fields 
macro factored out and this worked:

I'm not sure but I suspect the real difference comes from passing gen:printable 
to the pstruct macro though, because that's what causes this to fail.
I also had to add the optional argument to the definition of gen-print in the 
(pstruct test ...) definition.
The rest was just refactoring as I was trying to see how to simplify it so that 
I could see what was broken and what wasn't.

#lang racket/base
(require racket/generic
 syntax/parse/define
 "define-struct-fields.rkt"
 (for-syntax racket/base syntax/parse racket/syntax))

(define-generics printable
  (gen-print printable [port])
  (gen-port-print port printable)
  (gen-print* printable [port] #:width width #:height [height])
  #:defaults ([string?
   (define/generic super-print gen-print)
   (define (gen-print s [port (current-output-port)])
 (fprintf port "String: ~a" s))
   (define (gen-port-print port s)
 (super-print s port))
   (define (gen-print* s [port (current-output-port)]
   #:width w #:height [h 0])
 (fprintf port "String (~ax~a): ~a" w h s))]))

(define-simple-macro (pstruct struct-name (accessors ...) #:methods gen [body 
...])
  #:with sv (datum->syntax #'struct-name 'struct-values)
  #:with ooo (quote-syntax ...)
  (struct struct-name (accessors ...)
#:methods gen
[(define-syntax-rule (sv (fld ooo) v)
   (define-struct-fields struct-name (fld ooo) v))
 body ...]))
  
(pstruct test (a b c)
  #:methods gen:printable
  [(define (gen-print ps [out (current-output-port)])
 (struct-values (a) ps)
 (print a out))])
(gen-print (test 1 2 3))

On Aug 18, 2015, at 12:20 AM, Deren Dohoda  wrote:

> Thanks for your help Alexander. I did have this much working alright in a 
> different manner. What I guess I wanted was that this syntax was introduced 
> per struct so that the same syntax worked for all interface-structs. That is, 
> if I 
> (interface-struct test (a b c) 
>   [(define (some-interface-function ...))
> ...]) =>
> (struct test (a b c)
>   #:methods gen:???
>   [(define-struct-fields (field:id ...) ...)
>(define (some-interface-function ...) ...) ...])
> 
> Essentially all it had to do was grab the struct name automatically, just one 
> more level of indirection. It seemed straightforward but in my example code 
> the methods defined for the generic interface were not seen.
> 
> Deren 
> 
> On Tue, Aug 18, 2015 at 12:07 AM, Alexander D. Knauth  
> wrote:
> Are you looking for a macro like this:
> #lang racket
> (require syntax/parse/define (for-syntax racket/syntax))
> (define-simple-macro (define-struct-fields struct:id (field:id ...) v:expr)
>   #:with s (generate-temporary #'struct)
>   #:with [struct-field ...]
>   (for/list ([field (in-list (syntax->list #'(field ...)))])
> (format-id #'struct "~a-~a" #'struct field))
>   (begin
> (define s v)
> (define field (struct-field s))
> ...))
> ;; testing it out
> (struct test (a b c))
> (define x (test 1 2 3))
> (define-struct-fields test (a b) x)
> a
> b
> 
> Or do you want it even more automatic than that?
> 
> On Aug 17, 2015, at 11:29 PM, Deren Dohoda  wrote:
> 
>> Suppose I have a struct which implements a generic interface. I'll copy and 
>> paste the interface from the guide for the example. What I'd like to do is 
>> have automatically-introduced syntax which allows you to skip a lot of the 
>> struct-accessor forms. So for instance, for a struct like
>> (struct test (a b c))
>> 
>> I'd like, in a method, to be able to say
>> (define (some-method genericable)
>>   (define-accessors (a b)))
>> Which is essentially a (define-values ...) expression, taking care of the 
>> messy work of typing out all the accessor methods like (test-a genericable).
>> 
>> I have this example, which doesn't raise any syntax errors, and looks 
>> exactly like I'd expect from the macro stepper's output, yet fails when run:
>> 
>> #lang racket/base
>> (require (for-syntax racket/base)
>>  racket/generic)
>> 
>> (define-generics printable
>> (gen-print printable [port])
>> (gen-port-print port printable)
>> (gen-print* printable [port] #:width width #:height [height])
>> #:defaults ([string?
>>  (define/generic super-print gen-print)
>>  (define (gen-print s [port (current-output-port)])
>>(

Re: [racket-users] macro making a struct with a macro

2015-08-17 Thread Alexander D. Knauth
Are you looking for a macro like this:
#lang racket
(require syntax/parse/define (for-syntax racket/syntax))
(define-simple-macro (define-struct-fields struct:id (field:id ...) v:expr)
  #:with s (generate-temporary #'struct)
  #:with [struct-field ...]
  (for/list ([field (in-list (syntax->list #'(field ...)))])
(format-id #'struct "~a-~a" #'struct field))
  (begin
(define s v)
(define field (struct-field s))
...))
;; testing it out
(struct test (a b c))
(define x (test 1 2 3))
(define-struct-fields test (a b) x)
a
b

Or do you want it even more automatic than that?

On Aug 17, 2015, at 11:29 PM, Deren Dohoda  wrote:

> Suppose I have a struct which implements a generic interface. I'll copy and 
> paste the interface from the guide for the example. What I'd like to do is 
> have automatically-introduced syntax which allows you to skip a lot of the 
> struct-accessor forms. So for instance, for a struct like
> (struct test (a b c))
> 
> I'd like, in a method, to be able to say
> (define (some-method genericable)
>   (define-accessors (a b)))
> Which is essentially a (define-values ...) expression, taking care of the 
> messy work of typing out all the accessor methods like (test-a genericable).
> 
> I have this example, which doesn't raise any syntax errors, and looks exactly 
> like I'd expect from the macro stepper's output, yet fails when run:
> 
> #lang racket/base
> (require (for-syntax racket/base)
>  racket/generic)
> 
> (define-generics printable
> (gen-print printable [port])
> (gen-port-print port printable)
> (gen-print* printable [port] #:width width #:height [height])
> #:defaults ([string?
>  (define/generic super-print gen-print)
>  (define (gen-print s [port (current-output-port)])
>(fprintf port "String: ~a" s))
>  (define (gen-port-print port s)
>(super-print s port))
>  (define (gen-print* s [port (current-output-port)]
>  #:width w #:height [h 0])
>(fprintf port "String (~ax~a): ~a" w h s))]))
> 
> (define-syntax (pstruct stx)
>   (syntax-case stx ()
> ((_ struct-name (accessors ...) [body ...])
>  (with-syntax ((sv (datum->syntax stx 'struct-values)))
>  #'(struct struct-name (accessors ...)
>  #:methods gen:printable
>  [(define-syntax (sv stx)
> (syntax-case stx ()
>   ((_ (acc (... ...)))
>(let ((accs (for/list ((id (syntax->datum #'(acc (... ...)
>  (string->symbol (format "~a-~a" 'struct-name 
> id)
>  (with-syntax ((s (datum->syntax stx 'ps))
>(as (datum->syntax stx accs)))
>#'(define-values (acc (... ...)) (apply values (map 
> (λ(proc) (proc s)) as
>   body ...])
>   
> (pstruct test (a b c)
>   [(define (gen-print ps)
>  (struct-values (a))
>  a)])
> 
> Welcome to DrRacket, version 6.2 [3m].
> Language: racket/base [custom]; memory limit: 1024 MB.
> > (gen-print (test 1 2 3))
> . . gen-print: not implemented for #
> 
> How am I going wrong here? 
> 
> Thanks,
> Deren
> 
> -- 
> 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] pkg version exceptions: ranges of versions?

2015-08-16 Thread Alexander D. Knauth
Is there a way to create a version exception for a range of versions, instead 
of for a single version?

-- 
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 wrap a #lang module for the REPL?

2015-08-15 Thread Alexander D. Knauth
Based on this experiment, the double-quoted sub should be the right thing, and 
the single-quoted inside the datum->syntax with another quote in the require 
and provide forms shouldn't work.

Just like this works:
#lang racket
(require syntax/parse/define)
(define-simple-macro (m x)
  #:with req-spec (datum->syntax #'x ''sub)
  (begin
(module sub racket/base
  (provide y)
  (define y 3))
(require req-spec)))
(m x)
y

But this doesn't:
#lang racket
(require syntax/parse/define)
(define-simple-macro (m x)
  #:with req-spec (datum->syntax #'x 'sub)
  (begin
(module sub racket/base
  (provide y)
  (define y 3))
(require 'req-spec)))
(m x)
y

On Aug 16, 2015, at 12:09 AM, Matthew Butterick  wrote:

> No, the double-quoted ''sub doesn't work (triggers bad-syntax error). 
> 
> Nor does this (with quotes added to `sub-id` within the `require` and 
> `provide` forms):
> 
> (define-syntax my-module-begin
>   (lambda (stx)
> (syntax-case stx ()
>   [(_ body ...)
>(with-syntax ([sub-id (datum->syntax stx 'sub)])
>  #'(#%module-begin
> (module sub-id racket/base
>   (define x 2)
>   (provide x))
> (require 'sub-id)
>     (provide (all-from-out 'sub-id))
>         body ...))])))
> 
> On Sat, Aug 15, 2015 at 9:56 PM, Alexander D. Knauth  
> wrote:
> 
> On Aug 15, 2015, at 11:53 PM, Alexander D. Knauth  
> wrote:
> 
> > Does this work?
> > (define-syntax my-module-begin
> >  (lambda (stx)
> >(syntax-case stx ()
> >  [(_ body ...)
> >   (with-syntax ([sub-id (datum->syntax stx ''sub)])
> > #'(#%module-begin
> > (module sub-id racket/base
> >   (define x 2)
> >   (provide x))
> > (require sub-id)
> > (provide (all-from-out sub-id))
> > body ...))])))
> 
> I just realized that's not your example, so anyway, does modifying your 
> example to use (datum->syntax stx ''sub) instead of (datum->syntax stx 'sub) 
> work?
> 
> 

-- 
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 wrap a #lang module for the REPL?

2015-08-15 Thread Alexander D. Knauth

On Aug 15, 2015, at 11:53 PM, Alexander D. Knauth  wrote:

> Does this work?
> (define-syntax my-module-begin
>  (lambda (stx)
>(syntax-case stx ()
>  [(_ body ...)
>   (with-syntax ([sub-id (datum->syntax stx ''sub)])
> #'(#%module-begin
> (module sub-id racket/base
>   (define x 2)
>   (provide x))
> (require sub-id)
> (provide (all-from-out sub-id))
> body ...))])))

I just realized that's not your example, so anyway, does modifying your example 
to use (datum->syntax stx ''sub) instead of (datum->syntax stx 'sub) work?

-- 
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 wrap a #lang module for the REPL?

2015-08-15 Thread Alexander D. Knauth

On Aug 15, 2015, at 9:50 PM, Matthew Butterick  wrote:

> BTW, is it possible to extend your solution to macro-introduced imports from 
> a submodule?
> 
> In the original case, the identifier name was known in advance:

> But suppose instead the identifiers come from a submodule. I see from the 
> docs for `all-from-out` that "macro-introduced imports are not re-exported, 
> unless the module-path was introduced at the same time", so it feels like it 
> should go something like this, though this doesn't work (there's a difference 
> between the unquoted and quoted name that I'm not capturing).
> 
> (define-syntax my-module-begin
>   (lambda (stx)
> (syntax-case stx ()
>   [(_ body ...)
>(with-syntax ([sub-id (datum->syntax stx 'sub)])
>  #'(#%module-begin
>  (module sub-id racket/base
>(define x 2)
>(provide x))
>  (require sub-id)
>  (provide (all-from-out sub-id))
>  body ...))])))

Does this work?
(define-syntax my-module-begin
  (lambda (stx)
(syntax-case stx ()
  [(_ body ...)
   (with-syntax ([sub-id (datum->syntax stx ''sub)])
 #'(#%module-begin
 (module sub-id racket/base
   (define x 2)
   (provide x))
 (require sub-id)
 (provide (all-from-out sub-id))
 body ...))])))


> On Aug 15, 2015, at 6:21 PM, Matthew Butterick  wrote:
> 
>> Of your suggestions, I couldn't get `syntax-local-introduce` to work, but 
>> `datum->syntax` did. That made the macro-introduced identifier accessible at 
>> the REPL. Thanks.
>> 
>> However, I also wanted to set up the #lang so that DrRacket would 
>> automatically print the value of `id` when it ran the file. I noticed I 
>> could do this by introducing a `(module+ test ...)` in the #lang itself that 
>> prints `id` (because by default, DrRacket automatically runs test 
>> submodules). Thus obviating the need for a wrapper module.
>> 
>> 
>> 
>> 
>> 
>> On Aug 15, 2015, at 5:08 PM, Matthew Butterick  wrote:
>> 
>>> Probably the wiser option. I'll see if I can adapt that solution.
>>> 
>>> 
>>> On Aug 15, 2015, at 4:31 PM, Alexander D. Knauth  
>>> wrote:
>>> 
>>>> What kind of funny stuff?
>>>> By the way, this sounds sort of like this
>>>> http://www.mail-archive.com/racket-users@googlegroups.com/msg28020.html
>>>> Solution: 
>>>> http://www.mail-archive.com/racket-users@googlegroups.com/msg28031.html
>>>> 
>>>> Although it could be a completely different problem, I don't know.
>>>> 
>>>> On Aug 15, 2015, at 6:22 PM, Matthew Butterick  wrote:
>>>> 
>>>>> I have a #lang that does some funny stuff with #%module-begin (maybe too 
>>>>> funny), the result being that when I run it in DrRacket, the `provide`d 
>>>>> identifiers aren't visible at the top level:
>>>>> 
>>>>> (module my-lang-module my-lang
>>>>> ...
>>>>> (define id 42)
>>>>> (provide id))
>>>>> 
>>>>>> id
>>>>> id : undefined;
>>>>> cannot reference undefined identifier
>>>>> 
>>>>> 
>>>>> I've found a simple cure (maybe too simple) whereby I wrap my-lang-module 
>>>>> with the usual racket/base module, which satisfies DrRacket:
>>>>> 
>>>>> 
>>>>> (module repl-wrapper racket/base
>>>>> (module my-lang-module my-lang
>>>>> ...
>>>>> (define id 42)
>>>>> (provide id))
>>>>> (require 'my-lang-module)
>>>>> (provide (all-from-out 'my-lang-module))
>>>>> 
>>>>>> id
>>>>> 42
>>>>> 
>>>>> 
>>>>> Question: is there an approved way to make this #lang-wrapping happen for 
>>>>> the REPL, and only for the REPL? AFAICT `#%top-interaction` is not the 
>>>>> cure, because it wraps the commands coming off the REPL (as opposed to 
>>>>> the code in the definitions window). 
>>>>> 
>>>>> -- 
>>>>> 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] how to wrap a #lang module for the REPL?

2015-08-15 Thread Alexander D. Knauth

On Aug 15, 2015, at 8:21 PM, Matthew Butterick  wrote:

> Of your suggestions, I couldn't get `syntax-local-introduce` to work, but 
> `datum->syntax` did. That made the macro-introduced identifier accessible at 
> the REPL. Thanks.
> 
> However, I also wanted to set up the #lang so that DrRacket would 
> automatically print the value of `id` when it ran the file. I noticed I could 
> do this by introducing a `(module+ test ...)` in the #lang itself that prints 
> `id` (because by default, DrRacket automatically runs test submodules). Thus 
> obviating the need for a wrapper module.

I think a better way of doing that would be using a runtime-config module as in:
http://docs.racket-lang.org/guide/module-runtime-config.html
Or I think you can also do that with a #%configure-runtime sudmodule (or 
something like that)?

> On Aug 15, 2015, at 5:08 PM, Matthew Butterick  wrote:
> 
>> Probably the wiser option. I'll see if I can adapt that solution.
>> 
>> 
>> On Aug 15, 2015, at 4:31 PM, Alexander D. Knauth  
>> wrote:
>> 
>>> What kind of funny stuff?
>>> By the way, this sounds sort of like this
>>> http://www.mail-archive.com/racket-users@googlegroups.com/msg28020.html
>>> Solution: 
>>> http://www.mail-archive.com/racket-users@googlegroups.com/msg28031.html
>>> 
>>> Although it could be a completely different problem, I don't know.
>>> 
>>> On Aug 15, 2015, at 6:22 PM, Matthew Butterick  wrote:
>>> 
>>>> I have a #lang that does some funny stuff with #%module-begin (maybe too 
>>>> funny), the result being that when I run it in DrRacket, the `provide`d 
>>>> identifiers aren't visible at the top level:
>>>> 
>>>> (module my-lang-module my-lang
>>>> ...
>>>> (define id 42)
>>>> (provide id))
>>>> 
>>>>> id
>>>> id : undefined;
>>>> cannot reference undefined identifier
>>>> 
>>>> 
>>>> I've found a simple cure (maybe too simple) whereby I wrap my-lang-module 
>>>> with the usual racket/base module, which satisfies DrRacket:
>>>> 
>>>> 
>>>> (module repl-wrapper racket/base
>>>> (module my-lang-module my-lang
>>>> ...
>>>> (define id 42)
>>>> (provide id))
>>>> (require 'my-lang-module)
>>>> (provide (all-from-out 'my-lang-module))
>>>> 
>>>>> id
>>>> 42
>>>> 
>>>> 
>>>> Question: is there an approved way to make this #lang-wrapping happen for 
>>>> the REPL, and only for the REPL? AFAICT `#%top-interaction` is not the 
>>>> cure, because it wraps the commands coming off the REPL (as opposed to the 
>>>> code in the definitions window). 
>>>> 
>>>> -- 
>>>> 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] how to wrap a #lang module for the REPL?

2015-08-15 Thread Alexander D. Knauth
What kind of funny stuff?
By the way, this sounds sort of like this
http://www.mail-archive.com/racket-users@googlegroups.com/msg28020.html
Solution: 
http://www.mail-archive.com/racket-users@googlegroups.com/msg28031.html

Although it could be a completely different problem, I don't know.

On Aug 15, 2015, at 6:22 PM, Matthew Butterick  wrote:

> I have a #lang that does some funny stuff with #%module-begin (maybe too 
> funny), the result being that when I run it in DrRacket, the `provide`d 
> identifiers aren't visible at the top level:
> 
> (module my-lang-module my-lang
>  ...
>  (define id 42)
>  (provide id))
> 
>> id
> id : undefined;
> cannot reference undefined identifier
> 
> 
> I've found a simple cure (maybe too simple) whereby I wrap my-lang-module 
> with the usual racket/base module, which satisfies DrRacket:
> 
> 
> (module repl-wrapper racket/base
>  (module my-lang-module my-lang
>...
>(define id 42)
>(provide id))
>  (require 'my-lang-module)
>  (provide (all-from-out 'my-lang-module))
> 
>> id
> 42
> 
> 
> Question: is there an approved way to make this #lang-wrapping happen for the 
> REPL, and only for the REPL? AFAICT `#%top-interaction` is not the cure, 
> because it wraps the commands coming off the REPL (as opposed to the code in 
> the definitions window). 
> 
> -- 
> 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] Export indentation preferences in a package's info.rkt?

2015-08-09 Thread Alexander D. Knauth
I would really like to have such a feature.  

On Aug 9, 2015, at 1:23 PM, Jack Firth  wrote:

> I find it irritating when I have to repeatedly add various macros exported by 
> libraries to their proper group in the Indenting section of DrRacket's 
> settings so that they're properly formatted. Is there a way for a package's 
> info.rkt to specify default indentation preferences for it's macros for 
> DrRacket to make sense of? If not, would that be something easy enough to do 
> and useful enough to be worth doing?
> 
> -- 
> 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] Communicating between macros *without* mutation, problems with multiple modules?

2015-08-07 Thread Alexander D. Knauth
Oh, thanks!
That makes sense.

On the off chance that you have an idea, is there a good way of doing this that 
doesn't require b being able to see c?

On Aug 7, 2015, at 10:23 PM, Matthew Flatt  wrote:

> That's an interesting attempt to exploit the mutation inherent in a
> recursive definition context to build a reference chain.
> 
> It doesn't work across module boundaries because the recursive binding
> context doesn't extend across that boundary. The binding structure
> created by your example is something like
> 
> (let ()
>   (define (a) b)
>   (define (b) c)
>   (let ()
> (define (c) )
> ))
> 
> Here, the body of `a` can refer to `b`, because they're in the same
> recursive definition context. The body of `b` cannot refer to `c`,
> however, because `c` is in a different context (although the body of
> `c` can see `b`). An importing module is analogous to the more nested
> context above.
> 
> 
> The way you wrote the example, it may seem that `(add id b)` is somehow
> able to reference the definition in `(add id c) `, but that's not the
> case. The `(add id c)` is able to refer to things in "test1.rkt", and
> it also prints itself, so '(a b c) show up together. Since the `(add id
> b)` doesn't see `(add id c)`, the pieces that `(add id d)` can see
> point back to the same identifier as when `(add id c)` traverses them,
> so you end up with a duplicate definition of that identifier. That is,
> the `next-next` identifier created by `(add id b)` is never bound in
> the same was that `c` is never bound above for `(define (b) c)`.
> 
> 
> At Fri, 7 Aug 2015 22:02:48 -0500, "Alexander D. Knauth" wrote:
>> Hi. I have been trying to create a macro that communicates without using 
>> mutation, but I'm having problems with communicating across multiple 
>> modules.  
>> 
>> I have three files:
>> 
>> macro.rkt:
>> #lang racket
>> (provide start add)
>> (require (for-syntax syntax/parse racket/match racket/syntax))
>> (begin-for-syntax
>>  ;; (thing stx-lst next-id)
>>  ;; stx-lst : Syntax ; will be quoted
>>  ;; next-id : Identifier ; points to the next identifier, which is or will 
>> be 
>> the next thing
>>  ;;   if the next thing exists, then this one is old
>>  (struct thing (stx-lst next-id) #:transparent)
>>  ;; get-thing : Identifier -> thing
>>  (define (get-thing id)
>>(follow-next-things (syntax-local-value id)))
>>  ;; follow-next-things : thing -> thing
>>  (define (follow-next-things v)
>>(match v
>>  [(thing _ next-id)
>>   (define v* (syntax-local-value (syntax-local-introduce next-id) (λ () 
>> #f)))
>>   (cond [v* (follow-next-things v*)]
>> [else v])])))
>> (define-syntax start
>>  (syntax-parser
>>[(start id)
>> #:with next (generate-temporary #'id)
>> #'(define-syntax id (thing #'() #'next))]))
>> (define-syntax add
>>  (syntax-parser
>>[(add id new-stx)
>> #:do [(match-define (thing stx next-id) (get-thing #'id))]
>> #:with (old-stx ...) (syntax-local-introduce stx)
>> #:with next (syntax-local-introduce next-id)
>> #:with next-next (generate-temporary #'id)
>> (printf "macro.rkt add\n  next: ~v\n" #'next)
>> #'(begin
>> (define-syntax next (thing #'(old-stx ... new-stx) #'next-next))
>> '(old-stx ... new-stx))]))
>> 
>> test1.rkt:
>> #lang racket
>> (provide id)
>> (require "macro.rkt")
>> (start id)
>> (add id a) ; '(a)
>> (add id b) ; '(a b)
>> 
>> test2.rkt:
>> #lang racket
>> (require "macro.rkt" "test1.rkt")
>> (add id c) ; this works fine, produces '(a b c) when run
>> ;(add id d) ; module: duplicate definition for identifier
>> 
>> If I uncomment the last line of test2.rkt, it produces that duplicate 
>> definition error.
>> 
>> I'm guessing that the second use of add in test2.rkt isn't picking up the 
>> next-id definition put there by the first use of add in test2.rkt.
>> 
>> When I run test1.rkt in DrRacket it prints out:
>> macro.rkt add
>>  next: .#
>> macro.rkt add
>>  next: .#
>> '(a)
>> '(a b)
>> 
>> The first 4 lines were printed out by the add macro at compile time, and the 
>> last 2 are the run time results.
>> 
>> When I run test2.rkt in DrRacket it prints out:
>> macro.rkt add
>>  next: .#
>>

[racket-users] Communicating between macros *without* mutation, problems with multiple modules?

2015-08-07 Thread Alexander D. Knauth
Hi. I have been trying to create a macro that communicates without using 
mutation, but I'm having problems with communicating across multiple modules.  

I have three files:

macro.rkt:
#lang racket
(provide start add)
(require (for-syntax syntax/parse racket/match racket/syntax))
(begin-for-syntax
  ;; (thing stx-lst next-id)
  ;; stx-lst : Syntax ; will be quoted
  ;; next-id : Identifier ; points to the next identifier, which is or will be 
the next thing
  ;;   if the next thing exists, then this one is old
  (struct thing (stx-lst next-id) #:transparent)
  ;; get-thing : Identifier -> thing
  (define (get-thing id)
(follow-next-things (syntax-local-value id)))
  ;; follow-next-things : thing -> thing
  (define (follow-next-things v)
(match v
  [(thing _ next-id)
   (define v* (syntax-local-value (syntax-local-introduce next-id) (λ () 
#f)))
   (cond [v* (follow-next-things v*)]
 [else v])])))
(define-syntax start
  (syntax-parser
[(start id)
 #:with next (generate-temporary #'id)
 #'(define-syntax id (thing #'() #'next))]))
(define-syntax add
  (syntax-parser
[(add id new-stx)
 #:do [(match-define (thing stx next-id) (get-thing #'id))]
 #:with (old-stx ...) (syntax-local-introduce stx)
 #:with next (syntax-local-introduce next-id)
 #:with next-next (generate-temporary #'id)
 (printf "macro.rkt add\n  next: ~v\n" #'next)
 #'(begin
 (define-syntax next (thing #'(old-stx ... new-stx) #'next-next))
 '(old-stx ... new-stx))]))

test1.rkt:
#lang racket
(provide id)
(require "macro.rkt")
(start id)
(add id a) ; '(a)
(add id b) ; '(a b)

test2.rkt:
#lang racket
(require "macro.rkt" "test1.rkt")
(add id c) ; this works fine, produces '(a b c) when run
;(add id d) ; module: duplicate definition for identifier

If I uncomment the last line of test2.rkt, it produces that duplicate 
definition error.

I'm guessing that the second use of add in test2.rkt isn't picking up the 
next-id definition put there by the first use of add in test2.rkt.

When I run test1.rkt in DrRacket it prints out:
macro.rkt add
  next: .#
macro.rkt add
  next: .#
'(a)
'(a b)

The first 4 lines were printed out by the add macro at compile time, and the 
last 2 are the run time results.

When I run test2.rkt in DrRacket it prints out:
macro.rkt add
  next: .#
'(a)
'(a b)
'(a b c)

But then if I uncomment the last line:
macro.rkt add
  next: .#
macro.rkt add
  next: .#
module: duplicate definition for identifier in: id3
With this at the bottom:
module: duplicate definition for identifier at: id3 in: (define-syntaxes (id3) 
(thing (syntax (a b d)) (syntax id2)))

The message at the bottom shows that the (add id d) isn't picking up the 
next-id definition put there by the (add id c), so that it puts out (a b d) 
instead of (a b c d), and tries to define the same next-id that the previous 
(add id c) already defined.

What's happening here?

I know about the separate compilation guarantee, but don't think that could be 
the problem, since it works perfectly when add is used only once in test2.rkt.

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.


Re: [racket-users] #lang languages and REPL

2015-08-07 Thread Alexander D. Knauth

On Aug 7, 2015, at 4:35 PM, Alexander D. Knauth  wrote:

> The definition of x in `my-module-begin` doesn't work because it comes from 
> the macro's scope, not from the module's scope.
> See 
> http://docs.racket-lang.org/reference/syntax-model.html#%28part._macro-introduced-bindings%29
> 
> If you really need to use that approach instead of what I suggested above, 
> you should be able use either syntax-local-introduce or datum->syntax.
> You could try building off of one of these: (not tested)
> 
> (require syntax/parse/define)
> ;; one option, using syntax-local-introduce:
> (define-simple-macro (my-module-begin body ...)
>   #:with x-id (syntax-local-introduce #'x)
>   (#%module-begin
>(define x 2)

Sorry I meant (define x-id 2)

>body ...))
> ;; another option, using syntax-local-introduce:
> (define-syntax my-module-begin
>   (lambda (stx)
> (syntax-case stx ()
>   [(_ body ...)
>(with-syntax ([x-id (syntax-local-introduce #'x)])
>  #'(#%module-begin
>  (define x 2)

And here too, (define x-id 2)

>  body ...))])))
> ;; another option, using datum->syntax:
> (define-syntax my-module-begin
>   (lambda (stx)
> (syntax-case stx ()
>   [(_ body ...)
>(with-syntax ([x-id (datum->syntax stx 'x)])
>  #'(#%module-begin
>  (define x 2)

And here, (define x-id 2)

>  body ...))])))
> 
> Hope this helps!
> 
> 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.


Re: [racket-users] #lang languages and REPL

2015-08-07 Thread Alexander D. Knauth

On Aug 7, 2015, at 4:15 PM, Deren Dohoda  wrote:

> I​ have a minimal example that reproduces the behavior and I can track it 
> down to the fact that I do not export "define" and the file which uses the 
> new #lang does not define anything, except through a #%module-begin rewrite.

You shouldn't need a #%module-begin rewrite either though. (cont. below)

> If the file written in the new #lang has access to define and defines 
> anything, then indeed it shows up. Please forgive any gmail formatting:
> 
> TEST/
> --test.rkt​
> --test-lang/
> test-lang.rkt
> lang/
> --reader.rkt
> 
> I add the TEST directory to PLTCOLLECTS.
> 
> reader.rkt:
> #lang s-exp syntax/module-reader
> "test-lang/test-lang.rkt"
> 
> test-lang.rkt:
> #lang racket/base
> (provide (rename-out (my-module-begin #%module-begin))
>  #%app #%top #%datum #%top-interaction
>  require displayln)
> 
> (define-syntax-rule (my-module-begin body ...)
>   (#%module-begin
>(define x 2)
>(provide x)
>body ...))

I don't think that's what you want to do.

What you probably want is this:

test-lang.rkt:
#lang racket/base
(provide #%module-begin ; from racket/base
 #%app #%top #%datum #%top-interaction
 require displayln
 x)

(define x 2)

Then the repl for test.rkt should work. (cont. below)

> test.rkt:
> #lang test-lang
> (displayln 2)
> 
> Run "test.rkt"
> Welcome to DrRacket, version 6.2 [3m].
> Language: test-lang [custom]; memory limit: 4096 MB.
> 2
> > x
> . . x: undefined;
>  cannot reference an identifier before its definition
> > (require "test.rkt")
> > x
> 2
> ​;
> 
> It seems to be because of the definition of x in my-module-begin. But I don't 
> understand why this doesn't work.

The definition of x in `my-module-begin` doesn't work because it comes from the 
macro's scope, not from the module's scope.
See 
http://docs.racket-lang.org/reference/syntax-model.html#%28part._macro-introduced-bindings%29

If you really need to use that approach instead of what I suggested above, you 
should be able use either syntax-local-introduce or datum->syntax.
You could try building off of one of these: (not tested)

(require syntax/parse/define)
;; one option, using syntax-local-introduce:
(define-simple-macro (my-module-begin body ...)
  #:with x-id (syntax-local-introduce #'x)
  (#%module-begin
   (define x 2)
   body ...))
;; another option, using syntax-local-introduce:
(define-syntax my-module-begin
  (lambda (stx)
(syntax-case stx ()
  [(_ body ...)
   (with-syntax ([x-id (syntax-local-introduce #'x)])
 #'(#%module-begin
 (define x 2)
 body ...))])))
;; another option, using datum->syntax:
(define-syntax my-module-begin
  (lambda (stx)
(syntax-case stx ()
  [(_ body ...)
   (with-syntax ([x-id (datum->syntax stx 'x)])
     #'(#%module-begin
 (define x 2)
 body ...))])))

Hope this helps!

Alex Knauth

> Thanks for any insight here, I seem to have a bad mental model of what's 
> happening,
> Deren​
> 
> 
> On Fri, Aug 7, 2015 at 4:32 PM, Alexander D. Knauth  
> wrote:
> That sounds weird. You shouldn't need to do anything special with 
> #%top-interaction or anything, so I'm not sure what's going on.
> 
> How are you defining it?  Can you show us some of the source code?
> 
> On Aug 7, 2015, at 1:09 PM, Deren Dohoda  wrote:
> 
> > I have a #lang I'm working on and everything seems to be going very well. 
> > One thing I don't understand, though, is that when a file written in this 
> > language is opened in DrRacket and Run, I still have to (require 
> > "file.rkt") in the REPL before I am able to use anything provided by the 
> > file.
> >
> > I assume that I am neglecting to do something somewhere related to the use 
> > of #%top-interaction, because when I fail to provide this from the 
> > implementation of the language, I cannot run the file in DrRacket at all. 
> > But merely adding it to the provide expression doesn't do what I expect.
> >
> > Any help?
> >
> > Deren
> >
> > --
> > 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] is this a bug?

2015-08-07 Thread Alexander D. Knauth

On Aug 7, 2015, at 12:27 PM, Michael Titke  wrote:

> I always suspected this to be a logical joke of forcing people to write their 
> own quantifiers and to not let them fall for predicate logic.
> 
> The best thing about a logic scheme declaring everything but really 
> everything to be true when it is not false are expressions like the following:
> (when (cond (#f 'true)) 'what-is-true?) => 'what-is-true?

The confusing thing about your example, I think, is that cond returns # 
if none of the clauses match, when it would be slightly less bug-prone if it 
raised an error in that case.

> Yes, even unspecified is not false but it could have been. But that was not 
> specified. ;-)

Do you mean #?  I think it's great that # is a truthy value, 
because it allows things like:

(and
  (some-predicate ...)
  (some-effect-returning-void ...)
  (some-predicate ...)
  (some-effect-returning-void ...)
  ...)

Or possibly one of those effects could return void on success, but false on a 
failure, which would cause the `and` expression to stop and return false, 
signaling a failure. That's one nice use of that, at least. 

Also the simpler the true/false separation is, the better, in my opinion. 


-- 
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] #lang languages and REPL

2015-08-07 Thread Alexander D. Knauth
That sounds weird. You shouldn't need to do anything special with 
#%top-interaction or anything, so I'm not sure what's going on.

How are you defining it?  Can you show us some of the source code?

On Aug 7, 2015, at 1:09 PM, Deren Dohoda  wrote:

> I have a #lang I'm working on and everything seems to be going very well. One 
> thing I don't understand, though, is that when a file written in this 
> language is opened in DrRacket and Run, I still have to (require "file.rkt") 
> in the REPL before I am able to use anything provided by the file.
> 
> I assume that I am neglecting to do something somewhere related to the use of 
> #%top-interaction, because when I fail to provide this from the 
> implementation of the language, I cannot run the file in DrRacket at all. But 
> merely adding it to the provide expression doesn't do what I expect.
> 
> Any help?
> 
> Deren
> 
> -- 
> 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] is this a bug?

2015-08-06 Thread Alexander D. Knauth
I believe this pull request is about solving that problem:
https://github.com/plt/racket/pull/928
Either through modifying `and` and `or`, or providing variations that can be 
used with apply and foldr (or other higher-order functions).

On Aug 6, 2015, at 10:09 AM, sagyo12341...@gmail.com wrote:

> In racket, the proc apply-or is needed.
> 
>> (or #f 1 2 #f 3 4 #f)
> 1
>> (apply or (list #f 1 2 #f 3 4 #f))
> . or: bad syntax in: or
>> (define (apply-or lst) (foldr or #t lst))
> . or: bad syntax in: or
>> (define (apply-or lst) (foldr (lambda (x y) (or x y)) #t lst))
>> (apply-or (list #f 1 2 #f 3 4 #t))
> 1
>> (foldl (lambda (x y) (or x y)) #t (list #f 1 2 #t 3 4 #t))
> #t
> 
> -- 
> 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] Distinct instantiations of modules

2015-08-06 Thread Alexander D. Knauth
I think namespace-attach-module is one way to do this:

#lang racket
(module a racket
  (define ns (make-base-namespace))
  (namespace-attach-module (current-namespace) 'racket/promise ns)
  (parameterize ((current-namespace ns)) (namespace-require 'racket))
  (define *promise? (namespace-variable-value 'promise? #t #f ns))
  (*promise? (lazy 1)))
(require 'a) ; #t


On Aug 1, 2015, at 8:03 PM, Jos Koot  wrote:

> Some (I think many) modules define struct types and provide the constructors 
> and predicates of these structs. A predicate of an instance of such a module 
> does not recognize a struct made by a distinct instance of the same module. 
> For example:
>  
> #lang racket
> (module a racket
>  (define ns (make-base-namespace))
>  (parameterize ((current-namespace ns)) (namespace-require 'racket))
>  (define *promise? (namespace-variable-value 'promise? #t #f ns))
>  (*promise? (lazy 1)))
> (require 'a) ; -> #f where I would want #t
>  
> I know there is a solution for this problem:
>  
> #lang racket
> (module b racket
>  (define-namespace-anchor id)
>  (define ns (namespace-anchor->namespace id))
>  (void (parameterize ((current-namespace ns)) (namespace-anchor->namespace 
> id)))
>  (define *promise? (namespace-variable-value 'promise? #t #f ns))
>  (*promise? (lazy 1)))
> (require 'b) ; -> #t as wanted 
> Nevertheless, is there any chance to modify things such that once a module 
> has been instantiated, each new require of that module gives the same 
> instantiation?
> May be there are reasons not to do so, but I do not know why not.
>  
> Your opinion would be much appreciated.
> Thanks,
> Jos Koot
>  
>  
>  
> 
> -- 
> 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] A couple of questions about Neil's html reader/writer

2015-07-29 Thread Alexander D. Knauth
Would it be easier using match?

(define (xexpr->tok-tree an-xexpr)
  (match as-xexpr
['()
 '()]
[(not (cons _ _))
 (tok-make ...)]
[(list tag)
 (list tag)]
[(list-rest tag (? is-at-list at-list) r2)
 ]
))

On Jul 29, 2015, at 7:56 AM, Thomas Lynch 
 wrote:

> I wrote primitive conversion routines to bring the xexpr or Neil's xexpr into 
> ... oh gosh, my parser token format, which by coincidence is very close.  
> Just playing with this now .. In my target format token children are always 
> other tokens.  All values given as attributes in value tokens.  I use an 
> empty list if there are no attributes.  The conversion routines are very 
> simple, though I'm just playing with this, there will be other cases I 
> missed, I suspect:
> 
>  (define (xexpr->tok-tree an-xexpr)
> (define (is-at-list e)
>   (and
> (pair? e)
> (pair? (car e
> (cond
>   [(null? an-xexpr) an-xexpr]
>   [(not (pair? an-xexpr)) (tok-make 'tok:value `((value ,an-xexpr)))] ; 
> actually diff toks for diff types
>   [else
> (let(
>   [tag (car an-xexpr)]
>   [r1  (cdr an-xexpr)]
>   )
>   (cond
> [(null? r1) an-xexpr]
> [else
>   (let(
> [first-element (car r1)]
> [r2 (cdr r1)]
> )
> (cond
>   [(is-at-list first-element) (cons tag (cons first-element 
> (map xexpr->tok-tree r2)))]
>   [else (cons tag (cons '() (map xexpr->tok-tree r1)))]
>   ))]))]))
> 
> (define (test-xexpr-tok-tree-0)
>   (equal?
> (xexpr->tok-tree
>   '(html (head (title "My Title"))
>  (body ((bgcolor "white"))
>(h1 "My Heading")
>(p ((style "default")) "This is a paragraph.")
>(p "This is another paragraph."
> '(html
>()
>(head () (title () (tok:value ((value "My Title")
>(body
>  ((bgcolor "white"))
>  (h1 () (tok:value ((value "My Heading"
>  (p ((style "default")) (tok:value ((value "This is a paragraph."
>  (p () (tok:value ((value "This is another paragraph.")
>)))
> 
> 
> On Wed, Jul 29, 2015 at 7:05 AM, Matthew Butterick  wrote:
> Yes, more or less. In an X-expression, an attribute list is the only element 
> that's a list made of sublists. A list of embedded X-expressions, OTOH, will 
> start with a symbol. To look at it another way,
> 
>> (cons symbol (list xexpr ...))
> 
> really amounts to
> 
>> (list symbol xexpr ...)
> 
> 
> which is just
> 
>> (list symbol (list (list symbol string) ...) xexpr ...)
> 
> 
> but without the attribute list, cf.
> 
> '(p "foo" "bar")
> 
> '(p ((style "default")) "foo" "bar")
> 
> A recurring annoyance in X-expressions is distinguishing these two cases on 
> input, because the second element can be either an attribute list or nested 
> X-expression. You can use `xexpr-drop-empty-attributes` to force an attribute 
> list (even empty). My `txexpr` package also has utilities for handling them.
> 
> 
>> 
>> Here is the syntax for an xexp from xexp? in the reference:
>> 
>>   xexpr  =   string
>>  |   (list symbol (list (list symbol string) ...) 
>> xexpr ...)
>>  |   (cons symbol (list xexpr ...))
>>  |   symbol
>>  |   valid-char?
>>  |   cdata
>>  |   misc
>> 
>> And in this latter syntax, how is the attribute list distinguished from a 
>> list of embedded xexps? Is it due to the nesting in the attribute list?
> 
> 
> 
> 
> 
> -- 
> 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 : Local Definition

2015-07-24 Thread Alexander D. Knauth

On Jul 25, 2015, at 12:20 AM, Alexander D. Knauth  wrote:

> 
> On Jul 24, 2015, at 11:29 PM, sagyo12341...@gmail.com wrote:
> 
>> Nice to meet you.
>> 
>> 
>> I'm a racket beginner and I'm not a English speaker. Please forgive my poor 
>> skills.
>> 
>> In racket tutorials or HtDP, it uses some local definitions, as follows:
>> 
>> (define (f x)
>> (local [((define g x) (add1 x))]
>>   (f (g x.
>> 
>> I'm not sure about the difference from the code:
>> 
>> (define (f x)
>> (define (g x) (add1 x))
>> (f (g x))).
>> 
>> Please help me. Thank you.
>> 
>> Taro
> 
> Other than the misplaced paren typo in the first bit of code, these will do 
> exactly the same thing.

It's a matter of style. (Unless of course you're in an HTDP language that 
doesn't support internal definitions.)

There are times when I prefer local, for instance, when I want to clearly 
separate the definitions from the last expression, or when I want to indent the 
definitions more than the last expression.  

But there are also many times when an internal definition context is just more 
convenient, since comes with less keystrokes, less parens, and less 
indentation, and a bit more flexibility, especially if I want to put some 
debugging or error checking code in 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.


Re: [racket-users] Question : Local Definition

2015-07-24 Thread Alexander D. Knauth

On Jul 24, 2015, at 11:29 PM, sagyo12341...@gmail.com wrote:

> Nice to meet you.
> 
> 
> I'm a racket beginner and I'm not a English speaker. Please forgive my poor 
> skills.
> 
> In racket tutorials or HtDP, it uses some local definitions, as follows:
> 
> (define (f x)
>  (local [((define g x) (add1 x))]
>(f (g x.
> 
> I'm not sure about the difference from the code:
> 
> (define (f x)
>  (define (g x) (add1 x))
>  (f (g x))).
> 
> Please help me. Thank you.
> 
> Taro

Other than the misplaced paren typo in the first bit of code, these will do 
exactly the same thing.

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.


Re: [racket-users] Macro to extract select subexpressions into other locations

2015-07-21 Thread Alexander D. Knauth
Oh. I checked that that the expressions were accumulating in the definition of 
extract-expression, but I didn't check that it expanded in the right order to 
do what you want.

So this doesn't actually work. 

On Jul 21, 2015, at 3:08 PM, Alexander D. Knauth  wrote:

> Here's a macro that does something similar:
> 
> #lang at-exp racket
> 
> (require (for-syntax syntax/parse
> racket/contract
> ))
> 
> (begin-for-syntax
>  (define (get-extracted-exprs-box extracted-exprs-id)
>(syntax-local-value extracted-exprs-id))
>  (define (get-extracted-exprs extracted-exprs-id)
>(unbox (get-extracted-exprs-box extracted-exprs-id)))
>  (define (box-update! b f)
>(set-box! b (f (unbox b
>  (define (add-extracted-expr! extracted-exprs-id new-expr)
>(box-update! (get-extracted-exprs-box extracted-exprs-id)
> (λ (lst) (append lst (list (syntax-local-introduce 
> new-expr)))
> 
> (define-syntax extract-expression
>  (syntax-parser
>[(extract-expression expr:expr extracted-exprs-id:id)
> (add-extracted-expr! #'extracted-exprs-id #'expr)
> #'expr]))
> 
> (define-syntax with-extract-expressions
>  (syntax-parser
>[(with-extract-expressions stx-expr:expr ...)
> #:with [extracted-exprs macro-id:id ...]
> (generate-temporaries #'[extracted-expressions stx-expr ...])
> #'(begin
> (define-syntax extracted-exprs (box '()))
> (begin
>   (define-syntax macro-id
> (lambda (stx)
>   (stx-expr #'extracted-exprs)))
>   (macro-id))
> ...)]))
> 
> (define (square x) (* x x))
> 
> (with-extract-expressions
> (lambda (exprs)
>   (with-syntax ([exprs exprs])
> #'(module+ test
> (require rackunit)
> (check-equal? (extract-expression (square 5) exprs) 25)
> (check-equal? (extract-expression (square -5) exprs) 25
> (lambda (exprs)
>   (with-syntax ([(expr ...) (get-extracted-exprs exprs)])
> #'(module+ doc
> (require scribble/manual
>  scribble/eval)
> (define evaluator (make-base-eval))
> @defproc[(square [x real?]) real?]{
>   Returns the square of @racket[x], the result of
>   multiplying @racket[x] by itself.
>   @examples[#:eval evaluator expr ...]}
> 
> 
> On Jul 20, 2015, at 8:03 PM, Jack Firth  wrote:
> 
>> I'm trying to create a way to automatically turn test cases into examples. 
>> I'd like a macro that turns this:
>> 
>> (extract-expressions
>> (module+ test
>>  (check-equal? (extract-expression (square 5)) 25)
>>  (check-equal? (extract-expression (square -5)) 25))
>> (module+ doc
>>  @defproc[(square [x real?]) real?]{
>>Returns the square of @racket[x], the result of
>>multiplying @racket[x] by itself.
>>@examples[#:eval evaluator (include-extracted-expressions)]}))
>> 
>> into this:
>> 
>> (begin
>> (module+ test
>>   (check-equal? (square 5) 25))
>> (module+ doc
>>   @defproc[(square [x real?]) real?]{
>> Returns the square of @racket[x], the result of
>> multiplying @racket[x] by itself.
>> @examples[#:eval evaluator (square 5) (square -5)]}))
>> 
>> That's the general idea anyway. I want to be able to gather arbitrary 
>> expressions inside a region and "copy" them into some other marked place 
>> inside the expressions. How exactly do I go about doing this, and how should 
>> I do it "properly"?
>> 
>> -- 
>> 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] Macro to extract select subexpressions into other locations

2015-07-21 Thread Alexander D. Knauth
Here's a macro that does something similar:

#lang at-exp racket

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

(begin-for-syntax
  (define (get-extracted-exprs-box extracted-exprs-id)
(syntax-local-value extracted-exprs-id))
  (define (get-extracted-exprs extracted-exprs-id)
(unbox (get-extracted-exprs-box extracted-exprs-id)))
  (define (box-update! b f)
(set-box! b (f (unbox b
  (define (add-extracted-expr! extracted-exprs-id new-expr)
(box-update! (get-extracted-exprs-box extracted-exprs-id)
 (λ (lst) (append lst (list (syntax-local-introduce 
new-expr)))

(define-syntax extract-expression
  (syntax-parser
[(extract-expression expr:expr extracted-exprs-id:id)
 (add-extracted-expr! #'extracted-exprs-id #'expr)
 #'expr]))

(define-syntax with-extract-expressions
  (syntax-parser
[(with-extract-expressions stx-expr:expr ...)
 #:with [extracted-exprs macro-id:id ...]
 (generate-temporaries #'[extracted-expressions stx-expr ...])
 #'(begin
 (define-syntax extracted-exprs (box '()))
 (begin
   (define-syntax macro-id
 (lambda (stx)
   (stx-expr #'extracted-exprs)))
   (macro-id))
 ...)]))

(define (square x) (* x x))

(with-extract-expressions
 (lambda (exprs)
   (with-syntax ([exprs exprs])
 #'(module+ test
 (require rackunit)
 (check-equal? (extract-expression (square 5) exprs) 25)
 (check-equal? (extract-expression (square -5) exprs) 25
 (lambda (exprs)
   (with-syntax ([(expr ...) (get-extracted-exprs exprs)])
 #'(module+ doc
 (require scribble/manual
  scribble/eval)
 (define evaluator (make-base-eval))
 @defproc[(square [x real?]) real?]{
   Returns the square of @racket[x], the result of
   multiplying @racket[x] by itself.
   @examples[#:eval evaluator expr ...]}


On Jul 20, 2015, at 8:03 PM, Jack Firth  wrote:

> I'm trying to create a way to automatically turn test cases into examples. 
> I'd like a macro that turns this:
> 
> (extract-expressions
> (module+ test
>   (check-equal? (extract-expression (square 5)) 25)
>   (check-equal? (extract-expression (square -5)) 25))
> (module+ doc
>   @defproc[(square [x real?]) real?]{
> Returns the square of @racket[x], the result of
> multiplying @racket[x] by itself.
> @examples[#:eval evaluator (include-extracted-expressions)]}))
> 
> into this:
> 
> (begin
>  (module+ test
>(check-equal? (square 5) 25))
>  (module+ doc
>@defproc[(square [x real?]) real?]{
>  Returns the square of @racket[x], the result of
>  multiplying @racket[x] by itself.
>  @examples[#:eval evaluator (square 5) (square -5)]}))
> 
> That's the general idea anyway. I want to be able to gather arbitrary 
> expressions inside a region and "copy" them into some other marked place 
> inside the expressions. How exactly do I go about doing this, and how should 
> I do it "properly"?
> 
> -- 
> 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] Macro introduce identifiers in the new expander

2015-07-20 Thread Alexander D. Knauth
I don't really know what's going on, but this might help:

;; It seems to be introducing the definition correctly, but not the use:
;; this works
(let ()
  (def) ; no difference between (def) and (define id 5)
  id)

;; this doesn't
(let ()
  (def)
  (use)) ; but there is a difference between (use) and id

;; and this doesn't either
(let ()
  (define id 5)
  (use))

On Jul 20, 2015, at 12:35 PM, Spencer Florence  wrote:

> Hello,
> 
> I'm trying to update some code to the new expander. The below code works on 
> 6.2 but fails on the new expander with an unbound identifier error. 
> 
> #lang racket
> (require (for-syntax syntax/parse))
> 
> ;; a standard context for identifiers
> (define-for-syntax ctx #'ctx)
> 
> ;; create an ID with the context `ctx`, and the current
> ;; expander mark (so that the mark is canceled later),
> ;; and the location loc
> (define-for-syntax (make-id loc)
>   (syntax-local-introduce
>(datum->syntax ctx 'id loc)))
> 
> ;; This introduces a binding
> (define-syntax (def stx)
>   (syntax-parse stx
> [(def)
>  (with-syntax ([id (make-id #'here)])
>#'(define id 5))]))
> 
> ;; this attempts to use the binding introduced by `def`
> (define-syntax (use stx)
>   (syntax-parse stx
> [(use)
>  (with-syntax ([id (make-id #'here)])
>#'id)]))
> 
> ;; this works
> #;
> (begin
>   (def)
>   (use))
> 
> ;; this fails
> (let ()
>   (def)
>   (use))
> 
> -- 
> 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] Current snapshot: problem with generic interfaces and contracts

2015-07-19 Thread Alexander D. Knauth

On Jul 19, 2015, at 10:34 PM, Alexander D. Knauth  wrote:

> This is a simplified example of something that worked in racket version 
> 6.2.0.4 from 2015-06-08, but is now broken in version 6.2.900.4 from 
> 2015-07-17.
> 
> gen-foo.rkt:
> #lang racket
> (provide gen:foo foo? foo/c (contract-out [bar (foo? . -> . any/c)]))
> (require racket/generic)
> (define-generics foo
>  (bar foo))
> 
> contract.rkt:
> #lang racket
> (require "gen-foo.rkt")
> (define (foo/c* c)
>  (foo/c
>   [bar (foo? . -> . c)]))
> 
> This works fine in the snapshot from last month, but in the current one, it 
> fail with this error:

That should have been, "fails" with this error:

> . redirect-generics: bar is not a method of generic interface gen:foo in: bar
> 
> One way to get around this is to export an uncontracted version from 
> gen-foo.rkt, and possibly put the `bar` contract in a separate, third module, 
> but why would this be broken now?
> 
> 
> -- 
> 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] Current snapshot: problem with generic interfaces and contracts

2015-07-19 Thread Alexander D. Knauth
This is a simplified example of something that worked in racket version 6.2.0.4 
from 2015-06-08, but is now broken in version 6.2.900.4 from 2015-07-17.

gen-foo.rkt:
#lang racket
(provide gen:foo foo? foo/c (contract-out [bar (foo? . -> . any/c)]))
(require racket/generic)
(define-generics foo
  (bar foo))

contract.rkt:
#lang racket
(require "gen-foo.rkt")
(define (foo/c* c)
  (foo/c
   [bar (foo? . -> . c)]))

This works fine in the snapshot from last month, but in the current one, it 
fail with this error:
. redirect-generics: bar is not a method of generic interface gen:foo in: bar

One way to get around this is to export an uncontracted version from 
gen-foo.rkt, and possibly put the `bar` contract in a separate, third module, 
but why would this be broken now?


-- 
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] Is there a sequence combinator with a for*-like behavior?

2015-07-12 Thread Alexander D. Knauth
I'm wondering if there's anything I can use so that

(for/whatever ([(v1 v2 v3) (in-for*-sequence seq1 seq2 seq3)])
  )

Would be equivalent to

(for*/whatever ([v1 seq1] [v2 seq2] [v3 seq3])
  )

The reason I want this because with using for*, I'm constrained by the syntax, 
and I can't use apply when given a list of sequences that I want to combine in 
a for*-like manner.

If I understand correctly, this is similar to what cartesian-product from 
unstable/list does, so another way to put it would be asking if there is a 
sequence version cartesian-product.
http://docs.racket-lang.org/unstable/list.html#%28def._%28%28lib._unstable%2Flist..rkt%29._cartesian-product%29%29

Also a related question, is there a sequence equivalent to take on lists?

I found stream-tail and sequence-tail, which if I understand correctly are 
analogous to drop, but I couldn't find a take variant.


-- 
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 specify fallbacks for generic interfaces without going into an infinite loop?

2015-07-06 Thread Alexander D. Knauth
Thanks!

On Jul 6, 2015, at 9:53 PM, Jon Zeppieri  wrote:

> Use define/generic:
> 
> #lang racket/base
> 
> (require racket/generic)
> 
> (define-generics foo
>  (a foo) (b foo) (c foo)
>  #:fallbacks
>  [(define/generic gen-a a)
>   (define/generic gen-b b)
> 
>   (define (a foo)
> (displayln "a-fallback")
> (gen-b foo))
>   (define (b foo)
> (displayln "b-fallback")
> (gen-a foo))])
> 
> (struct foo-struct ()
>  #:methods gen:foo
>  [(define (a foo) 1)])
> 
> (b (foo-struct))
> 
> 
> On Mon, Jul 6, 2015 at 9:50 PM, Alexander D. Knauth
>  wrote:
>> What is the proper way to do this?
>> 
>> This goes into an infinite loop:
>> 
>> #lang racket/base
>> 
>> (require racket/generic)
>> 
>> (define-generics foo
>>  (a foo) (b foo) (c foo)
>>  #:fallbacks
>>  [(define (a foo)
>> (displayln "a-fallback")
>> (b foo))
>>   (define (b foo)
>> (displayln "b-fallback")
>> (a foo))])
>> 
>> (struct foo-struct ()
>>  #:methods gen:foo
>>  [(define (a foo) 1)])
>> 
>> (b (foo-struct))
>> 
>> 
>> --
>> 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] How to specify fallbacks for generic interfaces without going into an infinite loop?

2015-07-06 Thread Alexander D. Knauth
What is the proper way to do this?

This goes into an infinite loop:

#lang racket/base

(require racket/generic)

(define-generics foo
  (a foo) (b foo) (c foo)
  #:fallbacks
  [(define (a foo)
 (displayln "a-fallback")
 (b foo))
   (define (b foo)
 (displayln "b-fallback")
 (a foo))])

(struct foo-struct ()
  #:methods gen:foo
  [(define (a foo) 1)])

(b (foo-struct))


-- 
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] help please on git/github pull request

2015-07-02 Thread Alexander D. Knauth

On Jul 2, 2015, at 1:53 PM, John Clements  wrote:

> 
>> On Jul 2, 2015, at 7:31 AM, Alexander D. Knauth  wrote:

>> After you resolve them you will (I think) need to `git add` the files that 
>> you resolved conflicts for, then
>> `git rebase --continue`, and then when the rebase is finished, `git push -f 
>> origin topic-branch`.
> 
> Also, I think you eventually want to get things back onto the master branch, 
> right? After rebasing, you should be able to check out master again, then do 
> a 
> 
> git merge —ff-only topic-branch
> 
> at which point you should be able to push cleanly.

Um, I'm going by Greg Hendershott's advice in his "guide for infrequent 
contributors to Racket," but
wouldn't you not want to do that, because that would mess up the master branch 
and make it a dirty fork?

http://www.greghendershott.com/2013/04/a-guide-for-infrequent-contributors-to-racket.html#waiting-is-the-hardest-part

> In the meantime, you might be tempted to merge your topic branch into your 
> own master. Don’t!
> 
> If you were to do that, your master would cease being a nice clean mirror of 
> the upstream master. Remember how no one likes a dirty fork, so we’re 
> diligently using git pull --ff-only upstream master?


-- 
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] help please on git/github pull request

2015-07-02 Thread Alexander D. Knauth

On Jul 2, 2015, at 6:34 AM, Tim Brown  wrote:

> Folks,
> 
> I have two pull requests related to my separation of "net/url-string"
> from "net/url".
> 
> plt/racket #948  implementation of the separation
> racket/net #4test and documentation of the above
> 
> My problem is that I have been working on other things, and these are
> now not able to be merged into the master. (I've tried "get pull
> --ff-only..." as per Greg Hendershott's crib sheet)

Did you try `git pull --ff-only` from your topic branch, or from the master 
branch?

> How do I resolve this?

You probably need to checkout the master branch, then do git pull --ff-only 
upstream master,
then checkout your topic branch, and then `git rebase -i master`, find the 
conflicts, and resolve them.

After you resolve them you will (I think) need to `git add` the files that you 
resolved conflicts for, then
 `git rebase --continue`, and then when the rebase is finished, `git push -f 
origin topic-branch`.

Hope this helps!
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.


Re: [racket-users] generalised set! in Racket

2015-07-01 Thread Alexander D. Knauth

On Jul 1, 2015, at 4:27 AM, Alexey Cherkaev  wrote:

> Hi all,
> 
> Thanks to all replies, at the moment I would tend to agree that generalised 
> `set!` might not be such a great idea after all:
> The notion of 'place' is essentially a pointer to a memory location, but it 
> is not the first-class citizen: the following expressions are not equivalent: 
> (let ((x (aref v 5))) (set! x 100)) and (set! (aref v 5) 100), and it might 
> be the place for confusion.
> The syntax part of it, `(set! (what-ever ...) new-value)`, however, I don't 
> mind: `set!` is a special form/macro after all, not a procedure. No one would 
> demand the procedural clarity from `let` or `define`. The question is rather 
> if it worth having yet another special form.
The syntax part of it is what srfi/17 does, and anyone who requires srfi/17 
hopefully understands that it’s another special form, and that the (what-ever 
…) is not actually an expression, and hopes that people reading the code will 
also understand that. Because of the first point, it’s best that it’s in a 
separate library like srfi/17, not available by default, because that avoids 
confusion unless you require srfi/17 on purpose. 

> Summarising the points above, what if instead of `set!` there is a more 
> general abstraction 'location’:

Side note: Such a `location` abstraction doesn’t have to be all about 
mutability.

There is a purely functional version of this concept in Jack Firth's `lenses` 
package, which says that
lenses are functions that take a data structure and returns two values;
 the first being the “view,” or the value at that location,
 and the second being the “context” of that value, represented as a function 
that acts as a functional “setter,”
and these lenses are functional and compose-able.

http://pkg-build.racket-lang.org/doc/lenses@lenses/index.html
https://github.com/jackfirth/lenses

Also, because lenses return two values, they don't have to allocate a new 
structure every time, which (I think) means slightly better performance.

-- 
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] generalised set! in Racket

2015-06-30 Thread Alexander D. Knauth

On Jun 30, 2015, at 5:34 PM, 'John Clements' via Racket Users 
 wrote:

> Specifically, one of the basic ideas of algebraic languages is that programs 
> are compositional. Specifically, if I write (a (b x) c), then the meaning of 
> this term depends on the meanings of a, (b x), and c. That is, I can combine 
> these three values to get the result. Generalized set! breaks this intuition. 
> Specifically, (set! (aref x 0 1) 13) does not depend on the value of (aref x 
> 0 1). Rather, it pulls apart this term and uses its subterm’s meanings.

Actually, this makes a lot of sense to me and is probably the best argument 
I’ve heard for why lvalues can be a bad idea.
(and some time ago I read the discussion on SRFI 17, just for fun looking at 
the reasoning on both sides)
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.


Re: [racket-users] generalised set! in Racket

2015-06-29 Thread Alexander D . Knauth

On Jun 29, 2015, at 5:56 AM, Alexey Cherkaev  wrote:

> For example, I was thinking of defining syntax to access my implementation of 
> multidimensional arrays
> as
> 
> (define-syntax aref
>  (syntax-rules (set!)
>[(set! (aref ?a ?i ...) ?v) (array-set! ?a ?i ... ?v)]
>[(aref ?a ?i ...) (array-ref ?a ?i ...)]))
> 
> but obviously it won't work now as `set!` expects the `id` not an expression 
> (`syntax-id-rules` won't work either as `aref` is not an `id`).


#lang racket
(require srfi/17 math/array)
(define (aref a . is)
  (array-ref a (list->vector is)))
(set! (setter aref)
  (λ (a . is+v)
(match-define (list is ... v) is+v)
(array-set! a (list->vector is) v)))
(define a (mutable-array #[#[1 2] #[3 4]]))
(aref a 0 1)
(set! (aref a 0 1) 20)
(aref a 0 1)

If you wanted, you could also define your own version of set! that does what 
you want, which (I think) you would need to do if you needed aref to be a macro.


-- 
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] Fast way to map over a list many times, changing ONE element each time?

2015-06-26 Thread Alexander D. Knauth
Is there a split-at-reverse anywhere, equivalent to split-at except that the 
first return value is reversed?
If not, should that be added somewhere like srfi/1?

I’m asking because wanted to be able to write functions like:

(define ((drop-lens n) lst)
  (define-values [fst-lst rst-lst] (split-at-reverse lst n))
  (values rst-lst (λ (x) (append-reverse fst-lst x

(define ((list-ref-lens i) lst)
  (match-define-values [fst-lst val:rst-lst] (split-at-reverse lst i))
  (match-define (cons val rst-lst) val:rst-lst)
  (values val (λ (x) (append-reverse fst-lst (cons x rst-lst)

These are lenses as used in this package:
https://github.com/jackfirth/lenses

I wrote my own version of split-at-reverse, but I’m wondering if it should be 
put in something like srfi/1 as a companion to append-reverse, or if it perhaps 
already is in some other library.

Alex Knauth

On Jun 19, 2015, at 4:28 PM, Jens Axel Søgaard  wrote:

> A more efficient version using append-reverse from srfi/1.
> 
> #lang racket
> (require (only-in srfi/1 append-reverse))
> 
> (define (list-splits xs)
>   (define (loop ys zs)  ; xs = (append (reverse ys) yz)
> (match zs
>   ['()  '()]
>   [(cons z zs*) (cons (list ys zs)
>   (loop (cons z ys) zs*))]))
>   (loop '() xs))
> 
> 
> (define (map-once f xs)
>   (for/list ([ys+zs (list-splits xs)])
> (match ys+zs
>   [(list ys '()) '()]
>   [(list ys (cons z zs)) (append-reverse ys (cons (f z) zs))])))
> 
> (list-splits  '(1 2 3))
> (map-once sqr '(1 2 3))
> 
> 
> 2015-06-19 22:07 GMT+02:00 Jens Axel Søgaard :
> #lang racket
> (define (list-splits xs)
>   (define (loop ys zs)  ; xs = (append (reverse ys) yz)
> (match zs
>   ['()  '()]
>   [(cons z zs*) (cons (list ys zs)
>   (loop (cons z ys) zs*))]))
>   (loop '() xs))
> 
> 
> (define (map-once f xs)
>   (for/list ([ys+zs (list-splits xs)])
> (match ys+zs
>   [(list ys '()) '()]
>   [(list ys (cons z zs)) (append (reverse ys) (cons (f z) zs))])))
> 
> (list-splits  '(1 2 3))
> (map-once sqr '(1 2 3))
> 
> 
> 2015-06-19 22:05 GMT+02:00 Jon Zeppieri :
> It's unlikely that an implementation using continuations would be
> faster than one that does not.
> 
> An idiomatic solution might look like:
> 
> (define (map-once fn xs)
>   (for/list ([i (in-range (length xs))])
> (for/list ([(x j) (in-indexed (in-list xs))])
>   (cond [(= i j) (fn x)]
> [else x]
> 
> 
> But it's not terribly fast.
> If you're willing to use vectors instead of lists, then maybe:
> 
> (define (map-once fn xs)
>   (build-vector (vector-length xs)
> (λ (i)
>   (define v (vector-copy xs))
>   (vector-set! v i (fn (vector-ref v i)))
>   v)))
> 
> 
> On Fri, Jun 19, 2015 at 3:24 PM, Luke Miles  wrote:
> > Say I have a list ls and I want to produce a list of
> > lists where the i'th list has the i'th element of ls tripled,
> > but all other elements are the same.
> >
> > e.g. '(3 5 7) => '((9 5 7) (3 15 7) (3 5 21))
> >
> > What is a fast way to do this?
> >
> >
> > I could do a loop with appending.
> > (define (map-once f ls)
> >   (let M ([sooner null] [later ls])
> > (if (null? later) null
> >   (cons (append sooner (list (f (car later))) (cdr later))
> > (M (append sooner (list (car later))) (cdr later))
> >
> > -> (map-once sqr '(4 5 6))
> > '((16 5 6) (4 25 6) (4 5 36))
> >
> > Unfortunately, this is very slow & messy.
> > I have to do 2 big appends for every element is the return list.
> >
> >
> > Here is a cleaner-looking, but still slow way:
> > (define (list-set ls i new-val)
> >   (let-values ([(sooner later) (split-at ls i)])
> > (append sooner (list new-val) (cdr later
> >
> > (define (map-once f ls)
> >   (for/list ([i (in-naturals)]
> >  [elm (in-list ls)])
> > (list-set ls i (f elm
> >
> >
> > I'm thinking a good implementation might use continuations somehow?
> >
> > Maybe of vector-set (without the exclamation point) existed, I could use it?
> >
> > --
> > 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.
> 
> 
> 
> -- 
> -- 
> Jens Axel Søgaard
> 
> 
> 
> 
> -- 
> -- 
> 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 

Re: [racket-users] try a new macro expander

2015-06-25 Thread Alexander D. Knauth
Another weird error:
#lang racket/base
(require racket/stxparam (for-syntax racket/base))
(define-syntax-parameter add (make-rename-transformer #'+))
(define-syntax add1 (make-rename-transformer #'add))
add1

;add1: identifier's binding is ambiguous
;  context.:
;  matching binding.:
;  matching binding.:
;  => add context.:
;  => add matching binding.:
;  matching binding.: in: add1

I found this because of this Travis CI build failure:
https://travis-ci.org/AlexKnauth/infix-macro/jobs/68245124#L164

On Jun 25, 2015, at 12:31 AM, Matthew Flatt  wrote:

> Yes, I overlooked `splicing-local`, and I'll repair it. Thanks for the
> report!
> 
> At Wed, 24 Jun 2015 20:27:39 -0400, "Alexander D. Knauth" wrote:
>> I’ve just found something that I expected to work, but didn’t:
>> 
>> #lang racket/base
>> (require racket/splicing (for-syntax racket/base))
>> (splicing-local
>>[(define x 1)]
>>  (define-syntax outer-x (make-rename-transformer #'x)))
>> outer-x
>> 
>> ;. outer-x: unbound identifier in module in: outer-x
>> 
>> This works in the current expander, but fails in the scope-set expander.
>> 
>> It does work for splicing-let and splicing-letrec though.
>> 
>> I found it because I rely on it in this macro here:
>> https://github.com/AlexKnauth/my-object/blob/master/my-object/stuff.rkt#L25
>> And Travis CI was giving me this error:
>> https://travis-ci.org/AlexKnauth/my-object/jobs/68248192#L209
>> 
>> On Jun 22, 2015, at 8:25 AM, Matthew Flatt  wrote:
>> 
>>> At Thu, 21 May 2015 07:15:14 -0600, Matthew Flatt wrote:
>>>> Otherwise, be prepared for me to come back in a few
>>>> weeks and lobby for moving to a new macro expander.
>>> 
>>> Here's the proposal: let's switch on July 16. "Switch" means that I'd
>>> merge the new macro expander to the master branch of the development
>>> repository.
>>> 
>>> Thanks to those who have tried the new expander and reported back!
>>> Meanwhile, I've expanded the write-up and filled out the formal model
>>> (at the same URL as before).
>> 
>> 
>> -- 
>> 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] try a new macro expander

2015-06-24 Thread Alexander D. Knauth
I’ve just found something that I expected to work, but didn’t:

#lang racket/base
(require racket/splicing (for-syntax racket/base))
(splicing-local
[(define x 1)]
  (define-syntax outer-x (make-rename-transformer #'x)))
outer-x

;. outer-x: unbound identifier in module in: outer-x

This works in the current expander, but fails in the scope-set expander.

It does work for splicing-let and splicing-letrec though.

I found it because I rely on it in this macro here:
https://github.com/AlexKnauth/my-object/blob/master/my-object/stuff.rkt#L25
And Travis CI was giving me this error:
https://travis-ci.org/AlexKnauth/my-object/jobs/68248192#L209

On Jun 22, 2015, at 8:25 AM, Matthew Flatt  wrote:

> At Thu, 21 May 2015 07:15:14 -0600, Matthew Flatt wrote:
>> Otherwise, be prepared for me to come back in a few
>> weeks and lobby for moving to a new macro expander.
> 
> Here's the proposal: let's switch on July 16. "Switch" means that I'd
> merge the new macro expander to the master branch of the development
> repository.
> 
> Thanks to those who have tried the new expander and reported back!
> Meanwhile, I've expanded the write-up and filled out the formal model
> (at the same URL as before).


-- 
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] Closing big-bang windows

2015-06-21 Thread Alexander D. Knauth

On Jun 21, 2015, at 10:18 PM, Neil Toronto  wrote:

> I'm working on a `big-bang3d` game intended to expose shortcomings in 
> universe-style programs when used at a larger scale than in the classroom. 
> Here are my main criticisms so far:
> 
> 1. Adding new state is painful. Every time I add a little bit to track
>something - a cooldown timer, camera momentum, a list of planes the
>player collided against - I have to change a lot of unrelated code.

> For #1, I think we need nicer ways to reach deep into heterogeneous data 
> structures to read from and update them. Refactoring data structures only 
> goes so far. Game state is a big, messy thing with a lot of interaction that 
> defies neatly compartmentalized trees.

For this problem, I wonder if using compose-able functional lenses like this 
would be a good solution:
https://github.com/jackfirth/lenses
http://pkg-build.racket-lang.org/doc/lenses@lenses/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.


Re: [racket-users] Defining contracts sanely

2015-06-21 Thread Alexander D. Knauth

On Jun 21, 2015, at 5:41 AM, Aidan Gauland  wrote:

> Say I want to define a flat contract for the "freshness" field of my
> fish class, so I define a contract for it like so:
> 
> (define/contract fish-freshness/c
>  (-> any/c
>  boolean?)
>  (flat-named-contract 'fish-freshness/c
>(lambda (x)
>  (not (eq? #f (member x '(fresh frozen edible rotten)))
> 
> Am I barking up the wrong tree here, or is this perfectly sensible?
> 
> Regards,
> Aidan Gauland

If this does what you want, it’s fine, but the define/contract is probably 
unnecessary, and
(define fish-freshness/c
  (flat-named-contract ‘fish-freshness/c
(lambda (x)
  (not (eq? ….)
Should do what you want.

The flat-named-contract is also probably unnecessary (though it can be useful 
if the name isn’t just a symbol), so
(define (fish-freshness/c x)
  (not (eq? ….)))
Will also do what you want.

And finally, another way of doing this would be:
(define fish-freshness/c (or/c ‘fresh ‘frozen ‘edible ‘rotten))

Or if you prefer giving the contract a better name for error messages:
(define fish-freshness/c
  (flat-named-contract ‘fish-freshness/c (or/c ‘fresh ‘frozen ‘edible ‘rotten)))

Any one of these is “sane” as long as they work, and it depends on which one 
you think looks more readable, makes you’re intent clear, and gives error 
messages that make sense.

I just finished this when I saw Matthias Felleisen’s reply.  I’m sending it 
anyway.


-- 
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] Macro-introducing macros with inter-macro communication channel

2015-06-20 Thread Alexander D. Knauth

On Jun 19, 2015, at 7:44 PM, Thomas Dickerson  
wrote:

> I was intending for that example to have the variables be defined outside the 
> macro, but being able to create the (set! ...) forms outside should mean I 
> could also hypothetically create let/define-values forms. This is why I 
> originally specified being able to effect generation of both prologue + 
> epilogue code.

I figured this out for code that will be expanded after the body:

#lang racket/base

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

;; (syntax-parameter-value vars) : (U #f (MutableSetof Identifier))
(define-syntax-parameter vars #f)

(define-syntax Accum
  (lambda (stx)
(syntax-parse stx
  [(Accum x:id dx:expr)
   (define vs (syntax-parameter-value #'vars))
   (unless (set-mutable? vs)
 (raise-syntax-error #f "cannot be used outside Loop" stx))
   (set-add! vs (syntax-local-introduce #'x))
   #'(set! x (+ x dx))])))

(define-syntax set-accums-zero!
  (syntax-parser
[(set-accums-zero!)
 #:with [x ...]
 (map syntax-local-introduce (set->list (syntax-parameter-value #'vars)))
 #'(begin (set! x 0) ...)]))

(define-syntax Loop
  (syntax-parser
[(Loop up-to-expr:expr body:expr ...+)
 #'(syntax-parameterize ([vars (mutable-set)])
 (let ([up-to up-to-expr])
   (letrec
   ([loop
 (lambda (n)
   body
   ...
   (if (< n up-to)
   (loop (add1 n))
   (void)))])
 (set-accums-zero!)
 (loop 0]))

(let ([x "x"] [y "y"] [z "z"])
  (Loop 10
(begin
  (define-values 
[dx dy dz] 
(values 1 2 3))
  (printf "x = ~v, y = ~v, z = ~v\n" x y z)
  (Accum x dx)
  (Accum y dy)
  (Accum z dz

To generate a let outside of that you’d probably need to do some kind of 
local-expand, but I’m not sure.


> On Friday, June 19, 2015 at 6:47:15 PM UTC-4, Alex Knauth wrote:
>> Are the x, y, and z variables meant to be defined outside the macro by the 
>> user as in:
>> (let ([x “something”] [y “something else”] [z “and something else”])
>>   (Loop ….))
>> ?
>> 
>> 
>> Or should the Loop macro create a (let ([x 0] [y 0] [z 0]) ….) for you 
>> instead?
>> 
>> 
>> On Jun 19, 2015, at 5:58 PM, Thomas Dickerson  wrote:
>> 
>> 
>> Sure, here's a toy example.
>> 
>> This code:
>> 
>> 
>> (Loop 10
>>   (begin
>> (define-values 
>>   [dx dy dz] 
>>   (values 0 0 0))
>> ; Some calculation here
>> (Accum x dx)
>> (Accum y dy)
>> (Accum z dz)))
>> 
>> Should desugar into this code:
>> (letrec 
>> ([loop 
>>   (lambda (n) 
>> (begin
>>   (define-values 
>> [dx dy dz] 
>> (values 0 0 0))
>>   ; Some calculation here
>>   (set! x (+ x dx))
>>   (set! y (+ y dy))
>>   (set! z (+ z dz)))
>> (if (< n 10)
>> (loop (+ 1 n))
>> (void)))])
>>   (set! x 0)
>>   (set! y 0)
>>   (set! z 0)
>>   (loop 0))
>> 
>> 
>> And in general, every unique id occuring in an (Accum id delta) in the loop 
>> body should result in (set! id 0) in the prologue.
>> 
>> 
>> Also, some context to avoid unproductive side-conversation: I'm using 
>> Racket's macro facility to do pre-compilation of a totally different 
>> language. The fully-expanded program in this case is going to be a call to a 
>> function that rewrites Racket syntax objects into strings in the syntax of 
>> something which isn't Racket. This means that I really want my original 
>> question answered, rather than suggestions to solve a different problem that 
>> happens to accomplish the same thing for this toy example. The critical 
>> pieces here are that Accum only be defined within the body of a Loop, and 
>> that it be able to communicate outwards to effect the code generation of the 
>> specific instantiation of Loop in which it appears.
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> Thomas Dickerson
>> 
>> Brown University
>> Department of Computer Science
>> 
>> 115 Waterman St, 4th Floor
>> 
>> Providence, RI 02912
>> 
>> 802-458-0637
>> 
>> 
>> 
>> On Fri, Jun 19, 2015 at 3:22 PM, Ryan Culpepper  wrote:
>> On 06/19/2015 03:07 PM, Thomas Dickerson wrote:
>> 
>> 
>> Hi All,
>> 
>> 
>> 
>> I'm trying to figure out how best to implement the following pattern of 
>> macro behavior:
>> 
>> 
>> 
>> Let's say we are writing Loop macro that implements a looped computation 
>> over a specified body. I would like to then be able to
>> 
>> (a) introduce additional Loop-specific macros that are defined only within 
>> the scope of the body
>> 
>> (b) are able to coordinate with the outer macro so as to alter its 
>> generation of prologue and epilogue code.
>> 
>> 
>> 
>> My best guess here is some

Re: [racket-users] Reporting Simple Bugs and Fixing Them

2015-06-20 Thread Alexander D. Knauth

On Jun 20, 2015, at 12:39 PM, Kartik Singhal  wrote:

> On Friday, June 19, 2015 at 7:14:56 AM UTC+5:30, Alex Knauth wrote:
>> Also, if you’re interested, I found this blog post helpful:
>> http://www.greghendershott.com/2013/04/a-guide-for-infrequent-contributors-to-racket.html
>> Although for the HTDP student languages you’d want to think “racket/htdp” 
>> when it says “plt/racket”, and you’d skip the `make` steps. 
>> (If it were something other than documentation typos, you’d want to use the 
>> package system instead for that, but that doesn’t apply here)
> 
> 
> Thanks for sharing link to this blog post, I found Tutorial: Contributing to 
> Racket[1] helpful as well, in building the latest racket source locally.
> 
> But I can't find any instructions for how to build/install latest DrRacket 
> after cloning it from GitHub and link it with my fresh racket build. I looked 
> at 'Building Installers' section at [2], but that looks needlessly 
> complicated for my need -- I just want to generate a build for my local 
> machine (Mac OS X) for small hacks to DrRacket IDE.
> 
> Perhaps I need to use the package system as you mention, but it's not clear 
> what is the correct way of doing that.

The way I’ve done it for things like DrRacket is to get a recent snapshot 
installation from one of http://pre.racket-lang.org/installers/, and then 
cloning my fork of the drracket repository (or another repo) on my computer (if 
I haven’t already).
After that, I have a normal directory, and I can use the normal `raco pkg 
update path/to/drracket/drracket/`, or the DrRacket package manager with that 
path, to update the package to point to that directory in my clone of the 
repository.

That has worked for me, although there could be better ways of doing it.  
There’s the raco pkg update --clone option, for instance, but I haven’t used 
that yet.

> [1]: http://blog.racket-lang.org/2012/11/tutorial-contributing-to-racket.html
> [2]: https://github.com/plt/racket/blob/master/INSTALL.txt

-- 
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] Macro-introducing macros with inter-macro communication channel

2015-06-19 Thread Alexander D. Knauth
Are the x, y, and z variables meant to be defined outside the macro by the user 
as in:
(let ([x “something”] [y “something else”] [z “and something else”])
  (Loop ….))
?

Or should the Loop macro create a (let ([x 0] [y 0] [z 0]) ….) for you instead?

On Jun 19, 2015, at 5:58 PM, Thomas Dickerson  
wrote:

> Sure, here's a toy example.
> 
> This code:
> (Loop 10
>   (begin
> (define-values 
>   [dx dy dz] 
>   (values 0 0 0))
> ; Some calculation here
> (Accum x dx)
> (Accum y dy)
> (Accum z dz)))
> 
> Should desugar into this code:
> (letrec 
> ([loop 
>   (lambda (n) 
> (begin
>   (define-values 
> [dx dy dz] 
> (values 0 0 0))
>   ; Some calculation here
>   (set! x (+ x dx))
>   (set! y (+ y dy))
>   (set! z (+ z dz)))
> (if (< n 10)
> (loop (+ 1 n))
> (void)))])
>   (set! x 0)
>   (set! y 0)
>   (set! z 0)
>   (loop 0))
> 
> And in general, every unique id occuring in an (Accum id delta) in the loop 
> body should result in (set! id 0) in the prologue.
> 
> Also, some context to avoid unproductive side-conversation: I'm using 
> Racket's macro facility to do pre-compilation of a totally different 
> language. The fully-expanded program in this case is going to be a call to a 
> function that rewrites Racket syntax objects into strings in the syntax of 
> something which isn't Racket. This means that I really want my original 
> question answered, rather than suggestions to solve a different problem that 
> happens to accomplish the same thing for this toy example. The critical 
> pieces here are that Accum only be defined within the body of a Loop, and 
> that it be able to communicate outwards to effect the code generation of the 
> specific instantiation of Loop in which it appears.
> 
> 
> Thomas Dickerson
> 
> Brown University
> Department of Computer Science
> 115 Waterman St, 4th Floor
> Providence, RI 02912
> 
> 802-458-0637
> 
> On Fri, Jun 19, 2015 at 3:22 PM, Ryan Culpepper  wrote:
> On 06/19/2015 03:07 PM, Thomas Dickerson wrote:
> Hi All,
> 
> I'm trying to figure out how best to implement the following pattern of macro 
> behavior:
> 
> Let's say we are writing Loop macro that implements a looped computation over 
> a specified body. I would like to then be able to
> (a) introduce additional Loop-specific macros that are defined only within 
> the scope of the body
> (b) are able to coordinate with the outer macro so as to alter its generation 
> of prologue and epilogue code.
> 
> My best guess here is some use of local-expand with 
> syntax-local-bind-syntaxes, or perhaps syntax-parameterize, but I can't quite 
> work out the appropriate constructions.
> 
> I've been able to implement something similar using syntax-case functions on 
> syntax objects at phase-0, by essentially implementing my own namespace for 
> macros and passing it as an explicit argument, but this loses the hygiene 
> benefits of coordinating with expand.  I had an offline discussion with 
> Shriram yesterday in which he suggested looking into ways to reify the 
> expansion-time namespace, but obviously current-namespace does the wrong 
> thing here.
> 
> Can you provide a small example program and describe how you want it to 
> behave?
> 
> Ryan
> 
> 
> 
> -- 
> 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] Reporting Simple Bugs and Fixing Them

2015-06-18 Thread Alexander D. Knauth

You could probably use either one, but a github pull request would be more 
helpful, I think.

Also, if you’re interested, I found this blog post helpful:
http://www.greghendershott.com/2013/04/a-guide-for-infrequent-contributors-to-racket.html
Although for the HTDP student languages you’d want to think “racket/htdp” when 
it says “plt/racket”, and you’d skip the `make` steps. 
(If it were something other than documentation typos, you’d want to use the 
package system instead for that, but that doesn’t apply here)

On Jun 18, 2015, at 8:55 PM, Jeffrey Edgington  wrote:

> Greetings,
> 
> Recently while looking through the documentation on the Student Languages,
> I noticed a few mispelled words.
> 
> (sorry for the beginner questions that follow)
> 
> Are issues such as this reported through the Bug Report Form under Help?
> 
> (I only saw a few bugs of this type listed on bugs.racket-lang.org)
> 
> Or do people just fix them and ask for it to be added in Git?
> 
> I ask because I am hoping to understand and “walk through” the process using 
> a 
> simple case so I can start to contribute (even in some small way) to this 
> community.
> 
> Thank you!
> 
> Jeffrey Edgington
> 
> -- 
> 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] DrRacket rendering issues OS X

2015-06-17 Thread Alexander D. Knauth
One data point:
I’m using DrRacket version 6.2.0.4--2015-06-08 with OS X Version 10.9.5, and if 
I remember correctly it was a Racket plus Tests 64-bit installation.
I tried those steps, and it worked fine, with no weird black areas, though I do 
remember occasionally getting similar small black areas in the past, covering 
just the tab bar or something like that, and when I moved my mouse over it it 
fixed itself? I’m not sure if I remember that correctly, and I’m not sure if 
that could be related to what you got, because that wasn’t with full screen or 
the mission control screen, and I could not produce that consistently.

On Jun 17, 2015, at 12:25 PM, Andrew Kent  wrote:

> Good day all!
> 
> First, I just wanted to say DrRacket is *amazing* and thank all who have 
> helped it become what it is today! I'm currently using it to work on Typed 
> Racket and it is a godsend.
> 
> Right now, unfortunately, I am having some problems w/ DrRacket rendering in 
> OS X -- I am getting large black areas appearing in full screen mode in 
> DrRacket. They seem pretty serious/severe, and I was curious if anyone else 
> has seen this behavior?
> 
> PDF w/ screenshots & some attempt to describe problem(s):
> https://drive.google.com/file/d/0B-HcU1nZPrwJWXFNbEdOV0doeUE/view?usp=sharing
> 
> Steps that seem to recreate issue:
> 1) Open DrRacket
> 2) Make it full screen by clicking green button at top left of DrRacket
> 3) Open OS X ‘Mission Control’ (cmd+up or 3-finger-swipe up on touchpad) 4) 
> Close OS X ‘Mission Control’ (cmd+down or 3-finger-swipe downon
> touchpad) nd
> 5) Repeat 3-4 a couple times (after the 2 time it seemed to consistently
> happen on my machine)
> 
> - This worked whether or not I was plugged into the external monitor
> - the snapshots reproduced the issue on were the Racket plus Tests | Mac OS X 
> | 32-bit Intel distribution for version 6.2.0.4 (20150609-bf12a2b) & version 
> 6.2.0.4 (20150617-97827ac)
> - I’m running the latest OS X Yosemite (Version 10.10.3 (14D136)) on a early 
> 2013 13” MacBook Air
> 
> 
> Best,
> Andrew
> 
> -- 
> 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] 3d-syntax and sharing values between "read-time" and run-time?

2015-06-15 Thread Alexander D. Knauth
I just tried doing something for Asumu Takikawa’s `#lang clojure` with reading 
sets.

In the reader module #{1 2 3} is read, and the reader returns a syntax object 
created with
(datum->syntax … (list->set …) …)

And then if I write (quote #{1 2 3}), it actually works?

I’m a bit pleasantly surprised, because I was pretty sure this would fail with 
some kind of error related to 3d-syntax.

Is there a reason why this should always work?

Or is there a situation where this will sometimes fail?


-- 
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] iso-recursive types not allowed in TR?

2015-06-15 Thread Alexander D. Knauth

On Jun 13, 2015, at 8:18 AM, Hendrik Boom  wrote:
> On Fri, Jun 12, 2015 at 06:06:05PM -0700, 'John Clements' via users-redirect 
> wrote:
>> On Jun 12, 2015, at 5:52 PM, Alexander D. Knauth  
>> wrote:
>>> On Jun 12, 2015, at 8:30 PM, 'John Clements' via users-redirect 
>>>  wrote:
>>> 
>>>> (define-type (HuffJsexpr T)
>>>> (U T (HashTable Symbol HuffJsexpr)))
>>> 
>>> Do you mean this?
>>> (define-type (HuffJsexpr T)
>>> (U T (HashTable Symbol (HuffJsexpr T

>> Actually, I also can’t believe that TR allowed me to use a type constructor 
>> without an argument like that.
> 
> Maybe the type definitions need to be type-checked, too?
> 
> -- hendrik

I was thinking about this and I was coming up with an explanation of why it 
wouldn’t work (the way TR is currently set up), but then I realized there could 
be a way of doing this that makes sense without restructuring TR, so …

First, the reason I thought it might not work: In TR a type constructor and a 
polymorphic type are the same thing. And that makes sense because it makes 
sense to instantiate polymorphic types as if they were type constructors.
But that means that when it comes across a type constructor, it sees it as a 
polymorphic type, so it doesn’t raise a type error.

But type constructors like this don’t always make sense as polymorphic types, 
because polymorphic types only really make sense when there is something in the 
value with that type that can take some kind of input, like a function, some 
data structure containing a function, an object, or even something that could 
be mutable, I guess? I’m not sure. Anyway that could be something that TR could 
check for in this kind of thing, but it seems like it could be complicated? 
Again I’m not sure.

Or would it be simpler to just separate type constructors from polymorphic 
types completely, but allow polymorphic types to be used as type constructors 
as well for backwards compatibility?  But that could involve …

Actually, I was I about to say that would probably involve restructuring a lot 
of the type checker, but then I thought maybe type constructors could be a 
container type that contains a “polymorphic” type, and when it is “applied" the 
type-checker would just ignore this and look at the “polymorphic” type inside, 
but in a situation that requires an actual “non-constructor” type, it would 
raise a type error?  But then what if you wanted to define a type constructor 
that accepts type constructors as arguments (a higher-order type-constructor)?  
Again, it seems like this could also be complicated?

I’m not sure what the best thing to do is. 

Would bounded polymorphism help to solve this?  Or would it require another 
whole type system for types and type constructors?

Sorry if this doesn’t make much sense. I’m sending it anyway.


-- 
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] iso-recursive types not allowed in TR?

2015-06-13 Thread Alexander D. Knauth

On Jun 13, 2015, at 12:18 AM, 'John Clements' via users-redirect 
 wrote:

> Okay, I shouldn’t change topics, but while I’ve got you (guys): it looks like 
> (module+ test …) now works in TR, but not when there are imported bindings… 
> suppose I have foo.rkt:

I’ve run into similar problems with module+ before as you did below, but I 
found that something like this has worked so far:
(module* test racket/base
  (require (submod “..”) rackunit)
  … tests here …
  )

But anyway, I think I remember asking on the list and it being some problem 
with, and it might have been a problem with it being confused about whether the 
tests were typed or untyped?
http://lists.racket-lang.org/users/archive/2014-July/063668.html
http://lists.racket-lang.org/users/archive/2014-July/063669.html
http://lists.racket-lang.org/users/archive/2014-July/063670.html

But some time after that I found that (module* test racket/base …) worked.

> #lang typed/racket
> 
> (provide [struct-out Z])
> 
> (define-struct Z ([a : Number]))
> 
> … and then try to import it in a test+:
> 
> #lang typed/racket
> 
> (require "foo.rkt")
> 
> (Z 3)
> 
> (module+ test
>  (Z 3))
> 
> this leads to this error message:
> 
> Type Checker: missing type for identifier;
> consider using `require/typed' to import it
>  identifier: make-Z
>  from module: (submod foo.rkt #%contract-defs-reference .. #%contract-defs) 
> in: make-Z
> 
> I tried various require/typed combinations, but only managed to get an error 
> on `make-Z1`, which doesn’t sound like forward progress.
> 

-- 
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] iso-recursive types not allowed in TR?

2015-06-12 Thread Alexander D. Knauth

On Jun 12, 2015, at 8:30 PM, 'John Clements' via users-redirect 
 wrote:

> Here’s the type I want to write:
> 
> (define-type (HuffJsexpr T)
>  (U T (HashTable Symbol HuffJsexpr)))


Do you mean this?
(define-type (HuffJsexpr T)
  (U T (HashTable Symbol (HuffJsexpr T

#lang typed/racket
(define-type (HuffJsexpr T)
  (U T (HashTable Symbol (HuffJsexpr T
(: x : (HuffJsexpr String))
(define x
  #hash([a . "a string"]
[b . #hash([c . #hash()]
   [d . "another string"])]
[e . #hash([f . "and another"])]))

-- 
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] System Scheme (RnRS): Shared Secret Generator

2015-06-12 Thread Alexander D. Knauth

On Jun 12, 2015, at 9:35 AM, Michael Titke  wrote:

> On 12/06/2015 13:21, Konrad Hinsen wrote:

>> Seeding is provided for two use cases: 1) Reproducibility, ... 2) "Real" 
>> randomization, by setting the seed from some unpredictable source, such as 
>> the system time. In both cases, the idea is to set the seed once at the 
>> beginning of a program run.

> With your idea in #2 I would reliably produce known sequences depending on 
> only 256 original states. 

>> The statistical properties of the pseudo-random sequence hold only for an 
>> unperturbed sequence, i.e. without changing the seed. If you set the seed 
>> every time you ask for a random number, your random sequence becomes simply 
>> some complicated function of your input seed, whose statistical properties 
>> are hard to predict and most probably not what you want.

> If you want to look at the system and do a black box test then the result 
> would be:

> true randomness / noise -> Racket's randomness implementation with one 
> initial state -> one of 256 known sequences

If you want one of 65536 known sequences, you can get 2 bytes of initial 
randomness to start though, right?
And if you want one of 16777216 known sequences, you can use 3 bytes, and so on?
Increase the seed space?

> true randomness / noise -> GNU-Guile's randomness implementation -> noise
> 
> BTW the basic formula of cryptography is: Message |+| Randomness -> Randomness
> Now replace Randomness with Racket and try to ...

-- 
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 bug with racket/gui

2015-06-02 Thread Alexander D. Knauth
I have never worked with a canvas% before (I have worked with a lot of other 
racket gui stuff), so I have no idea what’s going on, but watch what happens 
with this:
#lang racket
(require racket/gui/base)
(define frame (new frame%
   [label "Example"]
   [width 300]
   [height 300]))
(define canvas
  (new canvas% [parent frame]))
(define dc (send canvas get-dc))
(send frame show #t)
(sleep 1)
(send dc draw-rectangle 30 20 10 40)

And even better, with this:
#lang racket
(require racket/gui/base)
(define frame (new frame%
   [label "Example"]
   [width 300]
   [height 300]))
(define canvas
  (new canvas% [parent frame]))
(define dc (send canvas get-dc))
(send frame show #t)
(sleep 1)
(send dc draw-rectangle 30 20 10 40)
(sleep 2)


On Jun 2, 2015, at 3:17 PM, John Smith  wrote:

> Alexis,
> Thank you for the speedy answer.
> I think I correctly implemented what you described. See attached.
> In the new code, no error is thrown but the rectangle is not drawn.
> Reorderings of displaying the window and drawing the rectangle appear to have 
> no effect.
> The only way I can get anything to show up is if I enter it in the REPL once 
> the code is executed.
> 
> Any idea what might be causing this?
> 
> -Luke
> 
> -- 
> 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] How to check for existing definitions

2015-05-31 Thread Alexander D. Knauth

On May 24, 2015, at 3:20 AM, Michael Tiedtke  
wrote:

> I can of course use /version/ to check for Racket's version but this doesn't 
> take
> patches or third party libraries/modules into account.


I was just re-reading this, and for your particular use case this has been 
answered already by Laurent, but:

One way to do this kind of thing for normal identifiers is to use this:

http://www.greghendershott.com/2014/06/fallback-when-required-function-not-available.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] Capturing sets of options in a splicing syntax class?

2015-05-27 Thread Alexander D. Knauth

Does this work for what you want to do?

#lang racket
(require syntax/parse)
(define-syntax ~opts
  (pattern-expander
   (lambda (stx)
 (syntax-case stx ()
   [(opts [kw id] ...)
(with-syntax ([ooo (quote-syntax ...)])
  #'(~seq (~or (~optional (~and (~seq kw) (~seq id ooo)) #:defaults 
([(id 1) '()]))
   ...)
  ooo))]
(define-splicing-syntax-class options
  [pattern (~opts [#:a a?] [#:b b?] [#:c c?] [#:d d?])
#:attr a/b #'(a? ... b? ...)
#:attr c/d #'(c? ... d? ...)])
(syntax-parse #'(#:a #:d #:b)
  [(opts:options)
   #'(opts.a/b opts.c/d)])


On May 27, 2015, at 1:03 AM, Alexis King  wrote:

> When using syntax/parse, is there a good way to do something like this?
> 
> (define-splicing-syntax-class options
>  (pattern (~seq (~or (~optional (~seq (~and #:a a?)))
>  (~optional (~seq (~and #:b b?)))
>  (~optional (~seq (~and #:c c?)))
>  (~optional (~seq (~and #:d d?
> ...)
>   #:attr a/b #'(a? b?)
>   #:attr c/d #'(c? d?)))
> 
> When using the above syntax class to parse #'(#:a #:d #:b), then the a/b 
> attribute should be #'(#:a #:b) and the c/d attribute should be #'(#:d). 
> However, this doesn't work, of course, because if one of the options isn't 
> defined, the attribute will be #f, and the attribute binding will fail.
> 
> I can get around that by doing something like this:
> 
> (define-splicing-syntax-class options
>  (pattern (~seq (~or (~optional (~seq (~and #:a a?)))
>  (~optional (~seq (~and #:b b?)))
>  (~optional (~seq (~and #:c c?)))
>  (~optional (~seq (~and #:d d?
> ...)
>   #:attr a/b #`(#,@(if (attribute a?) #'(a?) #'())
> #,@(if (attribute b?) #'(b?) #'()))
>   #:attr c/d #`(#,@(if (attribute c?) #'(c?) #'())
> #,@(if (attribute d?) #'(d?) #'()
> 
> But that's rather long-winded and verbose. Even better would be a way to 
> group the clauses within the pattern, something like this:
> 
> (define-splicing-syntax-class options
>  (pattern (~seq (~or (~and (~seq (~optional (~seq (~and #:a a?)))
>  (~optional (~seq (~and #:b b?
>a/b)
>  (~and (~seq (~optional (~seq (~and #:c c?)))
>  (~optional (~seq (~and #:d d?
>c/d))
> ...)))
> 
> But that obviously doesn't work, and I'm not sure what it would do even if it 
> compiled.
> 
> Anyway, is there a more concise way to do this? I know it's relatively easy 
> using `template` from syntax/parse/experimental/template, but this is going 
> into the Typed Racket code, so we're intentionally avoiding a dependency on 
> that.
> 
> Alexis
> 
> -- 
> 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] How to check for existing definitions

2015-05-27 Thread Alexander D. Knauth

On May 27, 2015, at 6:13 AM, Michael Tiedtke  
wrote:

> I'm a little bit astonished that Racket doesn't offer a defined? primitve 
> when it's not
> possible to implement it with macros because of the strange compile-time 
> behavior.

Here’s a fairly useless macro that can tell if a given identifier is defined or 
not:
#lang racket
(require (for-syntax racket/base syntax/parse))
(define-syntax defined?
  (syntax-parser
[(defined? x:id)
 (if (identifier-binding #'x)
 #'#t
 #'#f)]))
(defined? x)
(define y 3)
(defined? y)
(let ([x 4])
  (defined? x))


> Where compile time sound to me like put all the interned things together, 
> call it
> byte code and dump it into a file.

Well, there’s expansion time, which is the part of “compile time” in which 
macros expand, and in racket that’s often what people are talking about when 
they say compile time.

Racket is a lot more useful because you would never get an error about an 
unbound identifier at runtime, because it can always tell during compile time 
whether it’s bound or not.  And this makes things like `defined?` fairly 
useless at runtime, because that information is useful during expansion time 
instead.  That’s why functions like identifier-binding and syntax-local-value 
are provided.



-- 
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] Flower Garden: Open Flowers

2015-05-25 Thread Alexander D. Knauth
You could also try other options for package sources, which includes things 
like .zip files and .plt files, in addition to github repositories.
http://docs.racket-lang.org/pkg/Package_Concepts.html#%28part._concept~3asource%29

I have no experience with using anything other than a github repository though.

You could also look at these:
https://www.youtube.com/watch?v=jnPf6S0_6Xw
http://con.racket-lang.org/2013/

On May 25, 2015, at 3:30 AM, Michael Tiedtke  
wrote:

> 
> Il giorno 23/mag/2015, alle ore 19.28, Matthias Felleisen ha scritto:
> 
>> 
>> Why don't you put this into github and register it with the package server? 
>> 
> 
> Well, I tried to download git for my Mac twice. Two times it was interrupted
> after half of the 20MB version control monster had been downloaded. So,
> there won't be any repository on github because the webmob around G, my
> adblocker and ... some years ago downloads tended to fail at 99.99%.
> 
> Never mind.
> 
> Then I created the package as a plt file and uploaded it to the /planet/ 
> server.
> Still it does not appear in the catalog of Dr. Racket's package manager while 
> it
> can be found with the web interface. But it doesn't show the nice description
> I put into the description field.
> 
> -- 
> 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] test amazes me

2015-05-24 Thread Alexander D. Knauth
Look at what this does:
#lang racket
(require test-engine/racket-tests)
(check-expect 1 1)
(check-expect 2 2)
(check-expect 3 3)
(check-expect (displayln "hello") (displayln "world"))
(test)
(test)
Welcome to DrRacket, version 6.2.0.3--2015-05-17(542b960/a) [3m].
Language: racket [custom]; memory limit: 8182 MB.
world
hello
All 4 tests passed!
world
hello
All 8 tests passed!
> 

The test expressions are each evaluated twice, and each test passes a second 
time.

I imagine this could be considered useful if for instance the tests depended on 
a mutable value and that value was mutated in between the runs of test, but was 
that the intention? I don’t know.

Also it appears to evaluate the second expression first and the first 
expression second. Weird.


On May 24, 2015, at 6:42 PM, Jos Koot  wrote:

> #lang racket
>  
> (module a racket
>  (require test-engine/racket-tests)
>  (check-expect 1 1)
>  (test))
>  
> (module b racket
>  (require test-engine/racket-tests)
>  (check-expect 2 2)
>  (test))
>  
> (require 'a 'b)
>  
> This gives me:
>  
> Welcome to DrRacket, version 6.2.900.3--2015-05-16(e8b52f6/a) [3m].
> Language: racket [custom]; memory limit: 2000 MB.
> The only test passed!
> All 3 tests passed!
>  
> Apparently test does not clear the list of tests already done.
> But even then I am surprised by seeing THREE tests passed.
> Without clearing the accumulated tests, I would expect:
> All TWO tests passed!
>  
> Should test not eliminate the tests already done from the list of tests to be 
> gathered in future?
> And how come (require 'a 'b) does THREE tests, not TWO?
>  
> Is is not a big problem. I am just curious.
> Thanks,
> Jos
>  
>  
>  
>  
>  
>  
> 
> -- 
> 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] Typed racket equivalent of Haskell newtype?

2015-05-24 Thread Alexander D. Knauth
Also opaque types might help you:
http://docs.racket-lang.org/ts-reference/special-forms.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._require%2Ftyped%29%29
http://docs.racket-lang.org/ts-reference/type-ref.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fbase-types-extra..rkt%29._.Opaque%29%29

If you wanted sub-typing too, then refinement types would help, except I don’t 
think they work yet.

An example of using them for radians and degrees:

untyped-radians-degrees.rkt:
#lang racket/base
(provide radians? real->radians radians->real
 degrees? real->degrees degrees->real
 radians->degrees degrees->radians)
(require racket/math)
(define (radians? v) (real? v))
(define (real->radians x) x)
(define (radians->real x) x)
(define (degrees? v) (real? v))
(define (real->degrees x) x)
(define (degrees->real x) x)

typed-radians-degrees.rkt:
#lang typed/racket/base
(require/typed/provide "untyped-radians.rkt"
   [#:opaque Radians radians?]
   [real->radians [Real -> Radians]]
   [radians->real [Radians -> Real]]
   [#:opaque Degrees degrees?]
   [real->degrees [Real -> Degrees]]
   [degrees->real [Degrees -> Real]]
   [radians->degrees [Radians -> Degrees]]
   [degrees->radians [Degrees -> Radians]])

try-radians-degrees.rkt:
#lang typed/racket/base
(require "typed-radians-degrees.rkt")
(: d-90 : Degrees)
(define d-90 (real->degrees 90.0))
; type mismatch!
(: r-PI : Radians)
(define r-PI (real->degrees 180.0))


On May 23, 2015, at 11:34 PM, Stuart Hungerford  
wrote:

> On Sunday, 24 May 2015 12:50:48 UTC+10, Matthias Felleisen  wrote:
> 
>> Stuart, would a predicated refinement type work for you: 
>> 
>> -- 
>> http://docs.racket-lang.org/ts-reference/special-forms.html?q=define-predicate#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._make-predicate%29%29
> 
> Looking into that now--many thanks.
> 
> Stu  
> 
> 
> 

-- 
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] Is there a way to access test submodule from repl in DrRacket?

2015-05-23 Thread Alexander D. Knauth
Is there a way to access definitions in the test submodule from the repl in 
DrRacket as if I were in the repl of the test submodule?

I tried these and they didn’t work:

#lang racket
(require racket/enter)
(module+ test
  (define x 3))

> (enter! (submod "try-repl-submod-test.rkt" test))
> x
x: undefined;
 cannot reference an identifier before its definition
> (current-namespace (module->namespace '(submod "try-repl-submod-test.rkt" 
> test)))
> x
x: undefined;
 cannot reference an identifier before its definition

Using require works if I explicitly provide it from x from the test submodule, 
but I was hoping to be able to access it as if I were in the repl of the test 
submodule.  


-- 
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] Typed racket equivalent of Haskell newtype?

2015-05-23 Thread Alexander D. Knauth
As far as I know, this doesn’t exist in typed racket currently, but I’m 
wondering:  (I’m thinking of seeing if I can implement this when I have time 
this summer)

How should sub-typing interact with this?
Should it be a completely separate type, not related by sub-typing at all, or 
should the new type be a subtype of the representation type?
What should happen if values with these types crossed into untyped code? 
What should happen if an untyped program passes a normal flonum to a function 
that was supposed to accept Radians?
Would you want to be able to supply a predicate to check properties of the 
values of the new type? 

If you want them to be completely separate types, then I think what you have 
with struct will work fine, and the link you provided does say that Haskell 
newtypes are similar to using data with a single variant with a single field.

Although if it matters to you there will be the extra overhead of allocating 
the structs, accessing the fields and that kind of thing, which could be 
avoided if a newtype-like feature existed.

Alex Knauth


On May 23, 2015, at 4:21 PM, Stuart Hungerford  
wrote:

> Hi,
> 
> Is there an idiomatic Typed Racket equivalent to the Haskell concept of 
> newtypes?
> 
> https://www.haskell.org/tutorial/moretypes.html
> 
> That is, some way to have separate types that share a common structure? 
> 
> For example I'd like to define "Radians" and "Degrees" types that are both 
> implemented as Flonums but have Typed Racket raise a type error when a 
> Radians value is used where a Degrees value is expected. I can see using 
> single field structs might work:
> 
> (struct: Radians ([a : Flonum]))
> 
> (struct: Degrees ([a : Flonum]))
> 
> ; type checks
> (: d-90 : Degrees)
> (define d-90 (Degrees 90.0))
> 
> ; type mismatch!
> (: r-PI : Radians)
> (define r-PI (Degrees 180.0))
> 
> 
> Is there a better way of working with the Typed Racket idioms to do this kind 
> of thing?
> 
> Thanks,
> 
> Stu

-- 
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 versus racket/base

2015-05-23 Thread Alexander D. Knauth
It sounds to me like you're understanding this perfectly.
racket provides all of racket/base for-syntax.

On May 23, 2015, at 1:52 PM, Jos Koot  wrote:

> This works:
>  
> #lang racket
> (define-syntax (x y) (syntax-case y () (_ (syntax (quote monkey)
> x ; -> monkey
>  
> This does not work
>  
> #lang racket/base
> (define-syntax (x y) (syntax-case y () (_ (syntax (quote monkey)
>  
> gives the expansion time error:
>  
> syntax-case: unbound identifier in the transformer environment;
>  also, no #%app syntax transformer is bound in: syntax-case
>  
> This does work:
>  
> #lang racket/base
> (require (for-syntax (only-in racket/base syntax syntax-case)))
> (define-syntax (x y) (syntax-case y () (_ (syntax (quote monkey)
> x ; -> monkey
>  
> And this works too:
>  
> #lang racket/base (syntax-case #'x () #''monkey) -> monkey
>  
> This puzzles me. Both syntax-case and syntax are provided by both racket/base 
> and racket.
> It is as though racket provides syntax and syntax-case for syntax too and 
> that syntax/base does not.
> Probably I am misunderstanding things, but what?
>  
> Thanks, Jos
> 
> -- 
> 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] Is there a way for a function to tell how many values it's caller expects? (the continuation expects?)

2015-05-22 Thread Alexander D. Knauth
Is there a way for a function to tell how many values it’s caller expects it to 
return?

I’ve tried this and it didn’t work:
#lang racket
(define (show-k-arity)
  (let/ec k
(error 'print-k-arity "the arity of k is ~v" (procedure-arity k
(let-values ([(x y) (show-k-arity)]) (void))


-- 
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] disappeeraing binding arrows

2015-05-22 Thread Alexander D. Knauth
Oh, I thought you were talking about the arrows within the *use* of stx-case. 
I just realized they don’t work within the *definition* of the second version 
of stx-case.
That is weird.

On May 22, 2015, at 3:37 PM, Alexander D. Knauth  wrote:

> For me the arrows seem to work fine for both versions.
> I tried it with racket version 6.1.1 and a racket snapshot build version 
> 6.2.0.3--2015-05-17.
> Which arrows aren’t working for you?
> 
> On May 22, 2015, at 1:40 PM, Jos Koot  wrote:
> 
>> Below two versions of a very stripped version of a macro I have made.
>> In version 1 background expansion and check-syntax show binding arrows 
>> within macro stx-case.
>> However, in version 2 the arrows are not shown.
>> How come?
>> Thanks, Jos
>>  
>> #lang racket
>>  
>> (require (for-syntax racket))
>>  
>> ;;; version 1
>>  
>> (begin-for-syntax
>>  (define-syntax (stx-case stx) ; Here background expansion and macro stepper
>>   (syntax-case stx ()  ; do show binding arrows in stx-case.
>>((_ stx-expr clause ...)
>> (with-syntax
>>  ((+ (datum->syntax stx '+))
>>   (- (datum->syntax stx '-))
>>   (* (datum->syntax stx '*))
>>   (/ (datum->syntax stx '/)))
>>#'(syntax-case stx-expr (+ - * /) clause ...))
>>  
>> (define-syntax (a stx)
>>  (stx-case stx
>>   ((_ +) #''plus)
>>   ((_ -) #''minus)
>>   ((_ *) #''mult)
>>   ((_ /) #''div)
>>   ((_ x) #''x)))
>>  
>> ;;; version 2
>>  
>> (define-syntax (b stx)
>>  (define-syntax (stx-case stx) ; Here background expansion and macro stepper
>>   (syntax-case stx ()  ; do NOT show binding arrows in stx-case.
>>((_ stx-expr clause ...)
>> (with-syntax
>>  ((+ (datum->syntax stx '+))
>>   (- (datum->syntax stx '-))
>>   (* (datum->syntax stx '*))
>>   (/ (datum->syntax stx '/)))
>>#'(syntax-case stx-expr (+ - * /) clause ...)
>>  (stx-case stx
>>   ((_ +) #''plus)
>>   ((_ -) #''minus)
>>   ((_ *) #''mult)
>>   ((_ /) #''div)
>>   ((_ x) #''x)))
>>  
>> ; Both a and b work correctly:
>>  
>> (a +)
>> (a else)
>> (b -)
>> (b else)
>> 
>> -- 
>> 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] disappeeraing binding arrows

2015-05-22 Thread Alexander D. Knauth
For me the arrows seem to work fine for both versions.
I tried it with racket version 6.1.1 and a racket snapshot build version 
6.2.0.3--2015-05-17.
Which arrows aren’t working for you?

On May 22, 2015, at 1:40 PM, Jos Koot  wrote:

> Below two versions of a very stripped version of a macro I have made.
> In version 1 background expansion and check-syntax show binding arrows within 
> macro stx-case.
> However, in version 2 the arrows are not shown.
> How come?
> Thanks, Jos
>  
> #lang racket
>  
> (require (for-syntax racket))
>  
> ;;; version 1
>  
> (begin-for-syntax
>  (define-syntax (stx-case stx) ; Here background expansion and macro stepper
>   (syntax-case stx ()  ; do show binding arrows in stx-case.
>((_ stx-expr clause ...)
> (with-syntax
>  ((+ (datum->syntax stx '+))
>   (- (datum->syntax stx '-))
>   (* (datum->syntax stx '*))
>   (/ (datum->syntax stx '/)))
>#'(syntax-case stx-expr (+ - * /) clause ...))
>  
> (define-syntax (a stx)
>  (stx-case stx
>   ((_ +) #''plus)
>   ((_ -) #''minus)
>   ((_ *) #''mult)
>   ((_ /) #''div)
>   ((_ x) #''x)))
>  
> ;;; version 2
>  
> (define-syntax (b stx)
>  (define-syntax (stx-case stx) ; Here background expansion and macro stepper
>   (syntax-case stx ()  ; do NOT show binding arrows in stx-case.
>((_ stx-expr clause ...)
> (with-syntax
>  ((+ (datum->syntax stx '+))
>   (- (datum->syntax stx '-))
>   (* (datum->syntax stx '*))
>   (/ (datum->syntax stx '/)))
>#'(syntax-case stx-expr (+ - * /) clause ...)
>  (stx-case stx
>   ((_ +) #''plus)
>   ((_ -) #''minus)
>   ((_ *) #''mult)
>   ((_ /) #''div)
>   ((_ x) #''x)))
>  
> ; Both a and b work correctly:
>  
> (a +)
> (a else)
> (b -)
> (b else)
> 
> -- 
> 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] test submodules vs tests in separate file

2015-05-22 Thread Alexander D. Knauth

On May 22, 2015, at 8:19 AM, Robby Findler  wrote:

> Contracts mediate boundaries between parts of your program and sometimes 
> tests should go across the boundary (to help test the contracts) and 
> sometimes they should go inside (to test internal functions). You have to 
> pick one or the other with a given test module tho. 

Wouldn’t just this:
(module+ test
  (require (submod “..”))
  ; tests here
  )

Allow both of those things?

#lang racket
(provide
 (contract-out
   ; convert a fahrenheit temperature to a celsius
  [fahrenheit->celsius (-> (and/c number? (>=/c -459.67)) number?)]))
(define (fahrenheit->celsius f)
  (multiply-by-5/9 (- f 32)))
(define (multiply-by-5/9 x) ; not provided
  (* 5/9 x))
(module+ test
  (require rackunit (submod "..")) ; the (submod "..") makes it enforce the 
contracts
  (check-equal? (fahrenheit->celsius -40) -40)
  (check-equal? (fahrenheit->celsius 32) 0)
  (check-equal? (fahrenheit->celsius 212) 100)
  ;; this checks that it raises a contract-error
  (check-exn exn:fail:contract?
 (λ () (fahrenheit->celsius -500)))
  ;; this checks the internal unprovided function
  (check-equal? (multiply-by-5/9 18) 10)
  )


-- 
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] test submodules vs tests in separate file

2015-05-22 Thread Alexander D. Knauth
If you want to have the contracts enforced in the test submodule, all you have 
to do is add (require (submod “..”)) to the submodule.

You don’t need to use define/contract, and you don’t need to use module* 
instead of module+.

You can just use

#lang racket
(provide
 (contract-out
   ; convert a fahrenheit temperature to a celsius
  [fahrenheit->celsius (-> (and/c number? (>=/c -459.67)) number?)]))
(define (fahrenheit->celsius f)
 (/ (* 5 (- f 32)) 9))
(module+ test
  (require rackunit (submod "..")) ; the (submod "..") makes it enforce the 
contracts
  (check-equal? (fahrenheit->celsius -40) -40)
  (check-equal? (fahrenheit->celsius 32) 0)
  (check-equal? (fahrenheit->celsius 212) 100)
  ;; this checks that it raises a contract-error
  (check-exn exn:fail:contract?
 (λ () (fahrenheit->celsius -500


On May 22, 2015, at 7:58 AM, Atticus  wrote:

>> Yes, there is :
>> http://docs.racket-lang.org/style/Units_of_Code.html?q=define%2Fcontract#%28part._.Contracts%29
> 
> Thank you for the link. The "How to Program Racket" Guide will be really
> helpful.
> 
> But I must admit I'm a little confused. Looking at the *fahrenheit* example 
> in the
> Guide:
> 
> 
> #lang racket
> 
> (provide
>  (contract-out
>; convert a fahrenheit temperature to a celsius
>[fahrenheit->celsius (-> number? number?)]))
> 
> (define (fahrenheit->celsius f)
>  (/ (* 5 (- f 32)) 9))
> 
> (module+ test
>  (require rackunit)
>  (check-equal? (fahrenheit->celsius -40) -40)
>  (check-equal? (fahrenheit->celsius 32) 0)
>  (check-equal? (fahrenheit->celsius 212) 100))
>  
> 
> This example implies that the contracts are enforced in the test
> submodule (contrary to Matthews example) but modifing the example shows
> that this is not the case:
> 
> 
> (provide
>  (contract-out
>; convert a fahrenheit temperature to a celsius
>[fahrenheit->celsius (-> integer? integer?)]))
> 
> (define (fahrenheit->celsius f)
>  (/ (* 5 (- f 32)) 9))
> 
> (module+ test
>  (require rackunit)
>  (check-equal? (fahrenheit->celsius -40) -40)
>  (check-equal? (fahrenheit->celsius 32) 0)
>  (check-equal? (fahrenheit->celsius 212.1) 100.06))
> 
> 
> This is not very clear and confusing. If I would read the guide and I
> didn't know about Matthews example I would assume that the test in the
> modified example fails.
> 
> My conclusion is:
> When using contracts with submodules use define/contract instead of
> (provide (contract-out ...))
> 
> 
>> black-box tests are always embedded in documentation so that
>> if the documentation does not show errors, then the system is reasonably
>> correct (for bugs that already found).
>> source code can keep elegant, and leave all the dirty things to scribble.
> 
> This is a really nice idea. Thanks for sharing.
> 
> 
> WarGrey Gyoudmon Ju  writes:
> 
>> On Fri, May 22, 2015 at 5:41 PM, Atticus  wrote:
>> 
>>> 
>>> Imho it would be nice if there was a small hint in the documentation
>>> about that case, perhaps there is and I didn't see it?
>> 
>> 
>> Yes, there is :
>> http://docs.racket-lang.org/style/Units_of_Code.html?q=define%2Fcontract#%28part._.Contracts%29
>> 
>> 
>> In practice, I design tests in a system level abstraction.
>> 
>> black-box tests are always embedded in documentation so that
>> if the documentation does not show errors, then the system is reasonably
>> correct (for bugs that already found).
>> source code can keep elegant, and leave all the dirty things to scribble.
>> 
>> I almost do not write white-box tests since Racket and Typed Racket itself
>> has already formal enough,
>> moreover these tests or verifications can also be moved to documentation if
>> needed.
> 
> -- 
> 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] Scribble abstraction to attach styles

2015-05-21 Thread Alexander D. Knauth
I don’t know if there’s a better more general solution, but does this do what 
you want?
@(define exercise-style (make-style "exercise" (list (attributes '([style . 
"margin-left: 0em"])
@(define question-style (make-style "question" (list (attributes '([style . 
"margin-left: 0em"])
@(define answer-style (make-style "answer" (list (attributes '([style . 
"margin-left: 0em"])

On May 21, 2015, at 2:12 PM, Shriram Krishnamurthi  wrote:

> Thanks for these replies. Sorry I'm only now getting to them: Google failed 
> to notify me of them.
> 
> The problem with using (nested ...) is that it indents its content even when 
> I don't use the 'inset style. Therefore, if I have (as I do)
> 
> @exercise{@question{...}}
> 
> everything in the exercise ends up nested one level, and the question ends up 
> nested two levels. That's why I rejected the use of `nested` and was looking 
> for alternate solutions.
> 
> How can I get `nested` to not indent? I have exactly what you suggested:
> 
> (define (exercise . t) (nested #:style question-style t))
> (define (question . t)  (nested #:style question-style t))
> 
> where
> 
> (define exercise-style (make-style "exercise" null))
> (define question-style (make-style "question" null))
> 
> and this still leads to the indentation.
> 
> -- 
> 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] Doing pattern matching by reader macro

2015-05-20 Thread Alexander D. Knauth
Here’s one way to do something like that with a macro:
https://github.com/AlexKnauth/define-match-spread-out/blob/master/define-match-spread-out/main.rkt
And using it:
https://github.com/AlexKnauth/define-match-spread-out/blob/master/define-match-spread-out/tests/test.rkt


On May 18, 2015, at 9:39 AM, Mianlai Zhou  wrote:

> Hi Matthias,
> 
> Thanks for answer. However, this is not what I wanted:
> 
> I want to persist that I can write the code below (where "define" can be 
> changed to other name):
> 
> (define (f #t) 2)
> (define (f #f) 3)
> (define (f _) 0)
> 
> to do what I want to do.
> 
> So how should I define my "define" in order to do it? Your answer is perfect 
> but it is a different form
> from my original code above.
> 
> Could you give me an answer? Thanks.
> 
> M.
> 
> On Mon, May 18, 2015 at 9:20 PM, Matthias Felleisen  
> wrote:
> 
> #lang racket
> 
> (define/match (f n)
>   [(#t) 2]
>   [(#f) 3]
>   [(_) 0])
> 
> (list (f #t) (f #f) (f "where's my homework"))
> 
> 
> On May 18, 2015, at 9:04 AM, Mianlai Zhou  wrote:
> 
> > Hi Racketeers,
> >
> > I am a new user of Racket.
> >
> > I would want to be able to write the following segment of code:
> >
> > (define (f #t) 2)
> > (define (f #f) 3)
> > (define (f  _) 0)
> >
> > My intention is to define a function f, such that given an argument #t it 
> > will produce 2, or in
> > case given an argument #f it will produce 3. For any other value (shown by 
> > underscore), it
> > will give 0. This is done by pattern matching.
> >
> > Obviously, I cannot do this straightforward, because in current Racket the 
> > definitions in the
> > prior lines will be overshadowed by definitions given in the lines after. 
> > Moreover, I cannot give
> > the real values of argument, #t, #f and underscore, directly. If I do want 
> > to write the code as
> > shown above, probably I have to use reader macro. The question now is, how 
> > to do it? How to
> > implement a pattern-matching-style syntax by means of reader macro?
> >
> > Thank you all for helping me, a real new beginner in Racket language.
> >
> > M.
> >
> > --
> > 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] Re: Specifying a contract for the end of a list

2015-05-20 Thread Alexander D. Knauth
Would an append/c combinator be a good generalization of this?

I’ve already made an append/c combinator that works with just flat-contracts, 
but is there a good way to make it work for chaperone contracts?

https://github.com/AlexKnauth/match-string/blob/master/match-string/main.rkt#L205
http://pkg-build.racket-lang.org/doc/match-string/index.html#%28def._%28%28lib._match-string%2Fmain..rkt%29._append%2Fc%29%29

Also if any of you happen to look at this and have any suggestions, that would 
be great.

On May 20, 2015, at 8:43 PM, Philip Blair  wrote:

> On Tuesday, May 19, 2015 at 12:23:34 AM UTC-4, Alexis King wrote:
>> I've recently wanted a contract that lets me check the last element of a 
>> (potentially improper) list, ignoring the other elements. To do this in a 
>> general sense, I came up with this.
>> 
>> (define (listof* init/c last/c)
>>  (flat-named-contract
>>   `(listof* ,(contract-name init/c) ,(contract-name last/c))
>>   (flat-rec-contract listof* last/c (cons/c init/c listof*
>> 
>> That definition can then be used like this.
>> 
>> (define/contract num-tail
>>  (listof* any/c number?)
>>  '(a b c . 4))
>> 
>> The use-case I've found most helpful, though, is combining it with listof 
>> contracts to check sequences within lists or at the end of the lists.
>> 
>> (define/contract num-tail-proper
>>  (listof* any/c (list/c number?))
>>  '(a b c 4))
>> 
>> This works, but it only works with flat contracts. Would it be possible to 
>> generalize this to work with all contracts? Also, would this sort of 
>> combinator make sense in the standard library? The name I've used probably 
>> wouldn't be usable (since it could be confused with list*of), but I think 
>> the functionality is helpful.
> 
> I think what you are aiming for can be done using chaperone contracts 
> (Documentation link: http://goo.gl/y7W6Nu). Does the attached file seem to 
> demonstrate what you are looking for?
> 
> -- 
> 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] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Alexander D. Knauth

On May 18, 2015, at 1:19 AM, Michael Tiedtke  
wrote:

> I'm new to Racket but even R5RS is rather clear about this issue:
> 
> (citation from doc/r5rs/r5rs-std/r5rs-Z-H-9.html)
>> (eq? 2 2)   ===>  unspecified

In Racket, (eq? 2 2) is specified as true.

It says here:
http://docs.racket-lang.org/reference/numbers.html

> A fixnum is an exact integer whose two’s complement representation fit into 
> 31 bits on a 32-bit platform or 63 bits on a 64-bit platform; furthermore, no 
> allocation is required when computing with fixnums. See also the 
> racket/fixnum module, below.
> 
> Two fixnums that are = are also the same according to eq?. Otherwise, the 
> result of eq?applied to two numbers is undefined, except that numbers 
> produced by the default reader in read-syntax mode are interned and therefore 
> eq? when they are eqv?.

And about symbols, they should always be eq? if they are interned, which they 
always are unless they are produced by a function like gensym or 
string->uninterned-symbol.  The symbol=? predicate uses eq? to compare the 
symbols.


-- 
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] little problem with comma (unquote)

2015-05-14 Thread Alexander D. Knauth
Do you want this:
#lang racket

(define f 'insertar-empleado)
(define exp `(embed/url ,f))
(define (make-func)
 (define str 
   `(define (func)
  ,(list 'unquote exp)))
 str)
(display (make-func))
?

On May 14, 2015, at 2:41 PM, Héctor Mc  wrote:

> Hi for all
> I'm trying generate a function from other function, in this case is a little 
> part of it (expression) that need print a comma within it. In the example 
> show below need print the comma before (embed/url ,f). that is say 
> ,(embed/url insertar-empleado) but is something I can't to make.
> 
> I have this.
> 
> #lang racket
> 
> (define f 'insertar-empleado)
> (define exp `(embed/url ,f))
> (define (make-func)
>  (define str 
>`(define (func)
>   ,exp))
>  str)
> (display (make-func))
> 
> and result this (define (func) (embed/url insertar-empleado)) and I need
> (define (func) ,(embed/url insertar-empleado)).
> 
> I treated with  (' quote) (`quasiquote) and (, unquote) but no reach the 
> result.  
> 
> This is all, thanks in advance for read and help me.

-- 
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] Getting a sandboxed evaluator to work with a custom #lang's reader

2015-05-12 Thread Alexander D. Knauth
I managed to put this together:
https://github.com/AlexKnauth/scribble-code-examples

On May 12, 2015, at 7:10 AM, Alexis King  wrote:

> Continuing my attempts to make a working meta-language, I'm now working on 
> improving the documentation. I'd like to be able to use “interaction” from 
> scribble/eval with a custom evaluator, but I'm having trouble getting a 
> custom evaluator to work with my language.
> 
> I've tried using (make-module-evaluator "#lang curly-fn racket/base"), but 
> that only enables the curly-fn reader for reading the initial program, not 
> the additional input passed to the evaluator.
> 
> I have managed to do this sort of thing to get it working.
> 
> (parameterize ([sandbox-output 'string]
>   [sandbox-error-output 'string]
>   [sandbox-reader
>(λ (in)
>  (parameterize ([current-readtable (make-curly-fn-readtable)])
>(reverse
> (let loop ([acc null])
>   (define r (read-syntax in (current-input-port)))
>   (if (eof-object? r) acc (loop (cons r acc)))])
>  (make-module-evaluator "#lang curly-fn racket/base"))
> 
> That works, but I'm wondering if there's a better way.

-- 
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] Getting a sandboxed evaluator to work with a custom #lang's reader

2015-05-12 Thread Alexander D. Knauth
Is there a way to show examples in scribble docs that uses code?
If there’s not, would something like this be good:
@code-examples[#:lang “at-exp racket”]|{
(+ 1 2)
@+[1 2]
}|

Renders as:
Examples:
  > (+ 1 2)
  3
  > @+[1 2]
  3
?

On May 12, 2015, at 7:10 AM, Alexis King  wrote:

> Continuing my attempts to make a working meta-language, I'm now working on 
> improving the documentation. I'd like to be able to use “interaction” from 
> scribble/eval with a custom evaluator, but I'm having trouble getting a 
> custom evaluator to work with my language.
> 
> I've tried using (make-module-evaluator "#lang curly-fn racket/base"), but 
> that only enables the curly-fn reader for reading the initial program, not 
> the additional input passed to the evaluator.
> 
> I have managed to do this sort of thing to get it working.
> 
> (parameterize ([sandbox-output 'string]
>   [sandbox-error-output 'string]
>   [sandbox-reader
>(λ (in)
>  (parameterize ([current-readtable (make-curly-fn-readtable)])
>(reverse
> (let loop ([acc null])
>   (define r (read-syntax in (current-input-port)))
>   (if (eof-object? r) acc (loop (cons r acc)))])
>  (make-module-evaluator "#lang curly-fn racket/base"))
> 
> That works, but I'm wondering if there's a better way.
> 
> -- 
> 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 doesn't my readtable extension work in the REPL?

2015-05-11 Thread Alexander D. Knauth

On May 11, 2015, at 4:22 PM, Alexis King  wrote:

> I’ve gotten my curly-fn meta-language working, and it works great within a 
> module. However, evaluating #{+ 2} within the REPL just evaluates as a plain 
> old vector, ignoring my readtable extension.
> 
> What gives? Using @-expression syntax in the REPL works just fine when using 
> the at-exp meta-language, which seems pretty similar to my approach.

To do that, you’d have to use language-info as described in:
http://docs.racket-lang.org/guide/module-runtime-config.html

The at-exp language does that with this code here:
https://github.com/plt/racket/blob/master/pkgs/at-exp-lib/at-exp/lang/reader.rkt#L34
https://github.com/plt/racket/blob/master/pkgs/at-exp-lib/at-exp/lang/language-info.rkt
https://github.com/plt/racket/blob/master/pkgs/at-exp-lib/at-exp/lang/runtime-config.rkt


Also, have you seen
https://github.com/AlexKnauth/afl
The afl language supports #λ(...), #fn(…) and #lambda(…) in the repl by doing a 
similar thing:
https://github.com/AlexKnauth/afl/blob/master/afl/lang/reader.rkt#L28
https://github.com/AlexKnauth/afl/blob/master/afl/lang/language-info.rkt
https://github.com/AlexKnauth/afl/blob/master/afl/lang/runtime-config.rkt


-- 
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] testing with scope-set expander on Travis CI?

2015-05-10 Thread Alexander D. Knauth
I want to test some of my packages on travis with the Matthew Flatt's scope-set 
expander.

Right now I’m using Greg Hendershott’s way of setting up the .travis.yml, 
described here:
http://www.greghendershott.com/2013/07/using-travis-ci-for-racket-projects.html

I tried modifying that to support the scope-set snapshot here:
https://github.com/AlexKnauth/travis-racket/tree/scope-set
But testing that on travis fails with this error:
https://travis-ci.org/AlexKnauth/travis-racket/jobs/61987612
Running ./racket-scope-snapshot.sh to install Racket:
./racket-scope-snapshot.sh: line 1: syntax error near unexpected token `newline'
./racket-scope-snapshot.sh: line 1: `'
The command "cat travis-racket/install-racket.sh | bash" failed and exited with 
2 during .
Your build has been stopped.

First, is there a better way, second, has anybody already done something like 
this, and third, if the answer to the first two were no, how do I get this to 
work?  What am I doing wrong?


-- 
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] another strange typed racket error

2015-05-09 Thread Alexander D. Knauth
I have been getting an error with one of my packages, and I finally figured out 
a minimal example of how it breaks.

If I have these files:

tr-submod-error/lib.rkt:
#lang typed/racket
(provide x)
(define x : Natural 3)
(module* untyped racket/base
  (require (submod ".."))
  (provide (all-from-out (submod ".."

tr-submod-error/main-lib.rkt:
#lang typed/racket/base
(provide (all-from-out "lib.rkt"))
(require "lib.rkt")
(module* untyped racket/base
  (provide (all-from-out (submod "lib.rkt" untyped)))
  (require (submod "lib.rkt" untyped)))

tr-submod-error/untyped-lib.rkt:
#lang racket/base
(require (submod "main-lib.rkt" untyped))
(provide (all-from-out (submod "main-lib.rkt" untyped)))

tr-submod-error/test.rkt:
#lang racket/base
(require tr-submod-error/untyped-lib) ; absolute path
x

When I run test.rkt, it gives me this error message:
. . ../../../../../Applications/Racket/April-24/Racket 
v6.2.0.2/collects/racket/private/reqprov.rkt:79:13: 
syntax-local-module-exports: unknown module
  module name: #

Also typing x in the repl of untyped-lib.rkt gives me the same error message, 
although putting it in the file doesn’t.

If I switch the absolute path in test.rkt to a relative path, then it works.
If I omit the x in test.rkt, it seems to work, but then it gives me this error 
as soon as I try to use x.
If I change untyped-lib.rkt to refer directly to lib.rkt instead of going 
through main-lib.rkt, then it works. (why should that have anything to do with 
it?)

The showing the macro stepper for test.rkt shows this:
(module test racket/base
  (#%module-begin
   (require tr-submod-error/untyped-lib)
   (let ()
 (local-require (only-in (submod (lib "tr-submod-error/lib.rkt") untyped 
#%contract-defs) (x x)))
 x)))
But if I change the absolute path to a relative one, it works, and shows this:
(module test racket/base
  (#%module-begin
   (require "untyped-lib.rkt")
   (let ()
 (local-require
  (only-in (submod "lib.rkt" untyped ".." #%contract-defs-reference ".." 
#%contract-defs) (x x)))
 x)))

So what’s happening here?
Why is it working differently depending on whether it’s an absolute or relative 
module path?
Why should the extra module in between matter when all it does is re-provide it?


-- 
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 typed-racket contract error

2015-05-08 Thread Alexander D. Knauth
I also get a similar error message with this:
#lang racket/base
(require typed/racket/base)
(require/typed racket/math [pi Real])

. . ../../Applications/Racket/April-24/Racket 
v6.2.0.2/collects/racket/contract/private/blame.rkt:143:0: pi: broke its 
contract
  promised: #f
  produced: 3.141592653589793
  in: #f
  contract from: (interface for pi)
  blaming: (interface for pi)
   (assuming the contract is correct)
  at: unsaved-editor:3.28

So should require/typed produce a syntax error about being used in an untyped 
context?

On May 8, 2015, at 5:44 PM, Alexander D. Knauth  wrote:

> This doesn’t happen if I change the language of the submodule to 
> typed/racket/base, so I’m guessing this is because require/typed isn’t meant 
> to be used in untyped code.  
> 
> So should require/typed produce a syntax error when it’s used in untyped code 
> like this?
> 
> On May 8, 2015, at 5:30 PM, Sam Tobin-Hochstadt  wrote:
> 
>> This appears to be a bug -- my guess is that the contract isn't
>> actually generated, and thus turns into `#f` -- that's what
>> `require/typed` expands to, before TR inserts the real contract.
>> 
>> Sam
>> 
>> On Fri, May 8, 2015 at 5:26 PM, Alexander D. Knauth
>>  wrote:
>>> I have this file:
>>> #lang typed/racket
>>> (provide x)
>>> (define x : Natural 3)
>>> (module* main racket/base
>>> (require typed/racket/base)
>>> (require/typed (submod "..")
>>>[x Natural]))
>>> 
>>> I get this strange error message:
>>> . . ../../../../../Applications/Racket/April-24/Racket 
>>> v6.2.0.2/collects/racket/contract/private/blame.rkt:143:0: x: broke its 
>>> contract
>>> promised: #f
>>> produced: 3
>>> in: #f
>>> contract from: (interface for x)
>>> blaming: (interface for x)
>>>  (assuming the contract is correct)
>>> at: /Users/Alex/Documents/DrRacket/tr-submod-error/lib.rkt:7.18
>>> 
>>> What?
>>> 
>>> I just realized I meant to use require/untyped-contract instead of 
>>> require/typed, but still, what?
>>> 
>>> 
>>> --
>>> 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] strange typed-racket contract error

2015-05-08 Thread Alexander D. Knauth
This doesn’t happen if I change the language of the submodule to 
typed/racket/base, so I’m guessing this is because require/typed isn’t meant to 
be used in untyped code.  

So should require/typed produce a syntax error when it’s used in untyped code 
like this?

On May 8, 2015, at 5:30 PM, Sam Tobin-Hochstadt  wrote:

> This appears to be a bug -- my guess is that the contract isn't
> actually generated, and thus turns into `#f` -- that's what
> `require/typed` expands to, before TR inserts the real contract.
> 
> Sam
> 
> On Fri, May 8, 2015 at 5:26 PM, Alexander D. Knauth
>  wrote:
>> I have this file:
>> #lang typed/racket
>> (provide x)
>> (define x : Natural 3)
>> (module* main racket/base
>>  (require typed/racket/base)
>>  (require/typed (submod "..")
>> [x Natural]))
>> 
>> I get this strange error message:
>> . . ../../../../../Applications/Racket/April-24/Racket 
>> v6.2.0.2/collects/racket/contract/private/blame.rkt:143:0: x: broke its 
>> contract
>>  promised: #f
>>  produced: 3
>>  in: #f
>>  contract from: (interface for x)
>>  blaming: (interface for x)
>>   (assuming the contract is correct)
>>  at: /Users/Alex/Documents/DrRacket/tr-submod-error/lib.rkt:7.18
>> 
>> What?
>> 
>> I just realized I meant to use require/untyped-contract instead of 
>> require/typed, but still, what?
>> 
>> 
>> --
>> 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] strange typed-racket contract error

2015-05-08 Thread Alexander D. Knauth
I have this file:
#lang typed/racket
(provide x)
(define x : Natural 3)
(module* main racket/base
  (require typed/racket/base)
  (require/typed (submod "..")
 [x Natural]))

I get this strange error message:
. . ../../../../../Applications/Racket/April-24/Racket 
v6.2.0.2/collects/racket/contract/private/blame.rkt:143:0: x: broke its contract
  promised: #f
  produced: 3
  in: #f
  contract from: (interface for x)
  blaming: (interface for x)
   (assuming the contract is correct)
  at: /Users/Alex/Documents/DrRacket/tr-submod-error/lib.rkt:7.18

What?

I just realized I meant to use require/untyped-contract instead of 
require/typed, but still, what?


-- 
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] performance with freeze from 2htdp/image on very complex images

2015-05-06 Thread Alexander D. Knauth
Good news! With the add-line change that freeze operation on that huge fractal 
finished!
time(img-expr): cpu time: 1552529 real time: 1567217 gc time: 576576
time(freeze(img)) : cpu time: 26904587 real time: 79234417 gc time: 20568080

What is that, about 7 and a half hours of cpu time, about 22 hours of real 
time, and about 5.7 hours of gc time?
Compared to not even finishing after running for 3 days though, that’s great!

https://github.com/AlexKnauth/koch-snowflake/commit/aed7e1ba864ea8a56f3fe296bc684e65d5ee9aa0


On May 5, 2015, at 10:06 AM, Robby Findler  wrote:

> One of the issues is that the racket/draw version is not doing the
> cropping that the 2htdp/image version is doing. Changing the
> "scene+line" call in utils.rkt to "add-line" cuts the freeze time in
> half for me (using size 242 instead of 728 in the time.rkt file). I
> didn't check to see if lines go outside the shape, but if they do, you
> might consider just using some arithmetic comparisons there in
> util.rkt instead.
> 
> With that change, then I see the time for freezing being the same as
> the time for the racket/draw version to draw. I tried to find ways to
> speed up the construction of the image, but I didn't find anything
> that makes a useful change. It seems like just constructing the data
> structure that represents the shape has a basic cost and I didn't find
> any simple ways to improve the situation inside the library. (I tried
> to cut some corners in add-line but to no avail.)
> 
> Sorry,
> Robby
> 
> 
> 
> On Mon, May 4, 2015 at 10:33 PM, Alexander D. Knauth
>  wrote:
>> 
>> On May 4, 2015, at 6:02 PM, Robby Findler 
>> wrote:
>> 
>> Another approach here would be to help me do performance debugging of
>> 2htdp/image :). You could write the code directly as imperative calls
>> to the dc<%> interface and see how that compares. If there's a
>> significant difference, that suggests we might be able to find a way
>> to speed up 2htdp/image.
>> 
>> 
>> I tried doing that, and here’s what I got:
>> (time (snowflake/inner-fractal 728))  : cpu time: 14775 real time: 14874
>> gc time: 2304
>> (time (freeze img1))  : cpu time: 377110 real time:
>> 377867 gc time: 198343
>> (time (snowflake/inner-fractal/draw 728)) : cpu time: 24257 real time: 24267
>> gc time: 5852
>> Where snowflake/inner-fractal uses 2htdp/image, the result of that call is
>> defined as img1, and snowflake/inner-fractal/draw uses racket/draw.
>> The program that produces this output is here:
>> https://github.com/AlexKnauth/koch-snowflake/blob/master/try-draw/time.rkt
>> 
>> 
> 
> -- 
> 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] Syntax parameters and renaming

2015-05-06 Thread Alexander D. Knauth
In case you find it interesting, here’s a macro in the implementation of 
syntax-parse that is similar in spirit:
http://git.racket-lang.org/plt/blob/HEAD:/racket/collects/syntax/parse/private/runtime.rkt#l42

On May 6, 2015, at 1:21 AM, Jack Firth  wrote:

> I find that 99% of the time when I'm using syntax parameters, I'm just using 
> them with make-rename-transformer to implement macro-dependent keyword-like 
> things, such as `aif` and `it`. So I made a small helper macro 
> syntax-parameterize-rename:
> 
> (syntax-parameterize-rename ([param #'foo]) ...)
> 
> expands to
> 
> (syntax-parameterize ([param (make-rename-transformer #'foo)]) ...)
> 
> It seems weird to put it in a package when it's so heavily tied to the core 
> syntax-parameterize form. I've added it to my fork of the Racket repo. Would 
> anyone else find this useful enough to warrant a pull request? The code is at 
> https://github.com/jackfirth/racket/tree/stx-param-rename
> 
> -- 
> 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] performance with freeze from 2htdp/image on very complex images

2015-05-05 Thread Alexander D. Knauth

On May 5, 2015, at 10:06 AM, Robby Findler  wrote:

> One of the issues is that the racket/draw version is not doing the
> cropping that the 2htdp/image version is doing. Changing the
> "scene+line" call in utils.rkt to "add-line" cuts the freeze time in
> half for me (using size 242 instead of 728 in the time.rkt file). I
> didn't check to see if lines go outside the shape, but if they do, you
> might consider just using some arithmetic comparisons there in
> util.rkt instead.

At first, I was using add-line, but then switched to scene+line because at 
first the lines were sometimes going outside the shape, and when that happened 
on the left (or the top), it would effectively shift the whole image to the 
right, but it would still draw the next line too far left, shifting the rest of 
the image even more right, and I ended up with an image with a little bit of 
what I wanted on the far right, and a little bit of what I wanted on the far 
left, and in between a trail of tiny lines oriented in weird directions.  

I had kind of assumed that scene+line might be faster because it could be 
“translated” into just adding a line to a bitmap, while I thought add-line 
would be slightly more expensive because it had to adjust the bounding box when 
it went outside the image, but I guess I was wrong.

So thanks for the suggestion!  

> With that change, then I see the time for freezing being the same as
> the time for the racket/draw version to draw.

That’s not what I see for size 728:
(time (snowflake/inner-fractal 728))  : cpu time: 14822 real time: 14847 gc 
time: 2327
(time (freeze img1))  : cpu time: 197506 real time: 197911 
gc time: 102407
(time (snowflake/inner-fractal/draw 728)) : cpu time: 23638 real time: 23646 gc 
time: 5495
Where before it was:
(time (snowflake/inner-fractal 728))  : cpu time: 14775 real time: 14874 gc 
time: 2304
(time (freeze img1))  : cpu time: 377110 real time: 377867 
gc time: 198343
(time (snowflake/inner-fractal/draw 728)) : cpu time: 24257 real time: 24267 gc 
time: 5852

So it did significantly reduce the time for freezing it, but it’s still about 8 
times slower than using racket/draw.

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.


Re: [racket-users] performance with freeze from 2htdp/image on very complex images

2015-05-04 Thread Alexander D. Knauth

On May 4, 2015, at 6:02 PM, Robby Findler  wrote:

> Another approach here would be to help me do performance debugging of
> 2htdp/image :). You could write the code directly as imperative calls
> to the dc<%> interface and see how that compares. If there's a
> significant difference, that suggests we might be able to find a way
> to speed up 2htdp/image.

I tried doing that, and here’s what I got:
(time (snowflake/inner-fractal 728))  : cpu time: 14775 real time: 14874 gc 
time: 2304
(time (freeze img1))  : cpu time: 377110 real time: 377867 
gc time: 198343
(time (snowflake/inner-fractal/draw 728)) : cpu time: 24257 real time: 24267 gc 
time: 5852
Where snowflake/inner-fractal uses 2htdp/image, the result of that call is 
defined as img1, and snowflake/inner-fractal/draw uses racket/draw.
The program that produces this output is here: 
https://github.com/AlexKnauth/koch-snowflake/blob/master/try-draw/time.rkt


-- 
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] performance with freeze from 2htdp/image on very complex images

2015-05-04 Thread Alexander D. Knauth

On May 4, 2015, at 6:02 PM, Robby Findler  wrote:

> It certainly can lose sharpness if you scale (as the freezing process
> is basically just rendering them into bitmaps and then drawing the
> bitmaps and scaling the bitmaps looses quality because the scaling for
> process of bitmaps doesn't have the geometric information to work
> with).

Sorry, that’s not what I mean’t by sharpness.  I mean that the tips of the 
fractal look rounded to me; probably something to do with the bounding boxes of 
rotated images, and how they interact when put beside one another?  Anyway it 
looked to me like something that could mess up how the layers lined up, so 
that’s why I used the approach I did. 

> It seems like, with fractals, the fact that you have self-similarity
> means that you can have repeated images in a dag-like structure (like
> the example on the webpage) where freezing might help.

But since they’re all rotated from one another, would it still help? 
The documentation says it doesn’t help when it will be rotated, and I can 
imagine why.

> Another approach here would be to help me do performance debugging of
> 2htdp/image :). You could write the code directly as imperative calls
> to the dc<%> interface and see how that compares. If there's a
> significant difference, that suggests we might be able to find a way
> to speed up 2htdp/image.

I think once I finish this English paper that’s what I’ll do.

> You'd use something like this:
> 
> #lang racket/gui
> 
> (define (draw-it dc w h)
>  ;; fractal drawing code goes here
>  (send dc draw-ellipse (/ w 4) (/ h 4) (/ w 2) (/ h 2)))
> 
> (define f (new frame% [label ""] [width 200] [height 200]))
> (define c (new canvas% [parent f]
>   [paint-callback
>(λ (c dc)
>  (define-values (w h) (send c get-client-size))
>  (send dc set-smoothing 'aligned)
>  (draw-it dc w h))]))
> (send f show #t)


-- 
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] performance with freeze from 2htdp/image on very complex images

2015-05-04 Thread Alexander D. Knauth

On May 4, 2015, at 12:49 AM, gfb  wrote:

> Those are beautiful.

Thanks!

> First, make sure in Choose Language / Show Details that it's set to "No 
> debugging or profiling", and that "Preserve stacktrace" not set.

Already have that, but thanks for checking.

> The 2htdp/image library has immutable images, so the image you're creating 
> contains all the line drawing "unexecuted" until you display or freeze it.
> 
> There's a lot of symmetry, so rather than passing an image as a parameter can 
> you express the algorithm as returning one of the component images at each 
> level, then rotating and combining it with itself? As long as the result is 
> symmetric that will create a rather narrow Direct Acyclic Graph of images.

I thought about doing that, and that’s what an example in the docs does, but I 
didn’t because I was afraid I would lose precision of exactly where the lines 
go, and since most of these fractals have multiple layers, that’s important.
>From the example in the docs, at the smaller scales it doesn’t look sharp or 
>accurate to me, and would it really improve performance? Since they would be 
>all rotated from each other, I don’t think I would be able to reuse 
>computations very much.

> You can then also experiment with freezing some of those intermediate images, 
> especially at the top levels where rotating a bitmap might be faster than 
> executing the drawing actions in a rotated co-ordinate system. But that's 
> speculation, not experience.

The documentation for freeze says that freeze isn’t going to be helpful for 
images that will be scaled or rotated?
If it were a serpinski carpet, I think this could probably help a lot, but for 
what I’m doing, I don’t think it would.

> Other than that, consider drawing directly into a mutable bitmap% from 
> racket/draw, or explore images/flomap.

I haven’t looked at images/flomap yet, but it looks interesting. 

> Then there are the possibilities of Typed Racket optimizations, and profiling 
> and the Optimization Coach in general.

I didn’t want to try typed racket because 2htdp/image isn’t written in typed 
racket, so there would be contract checks on every image function call. If I 
have time to try images/flomap that won’t be a problem though.
I didn’t want to try profiling because in my experience it slows things way 
down, and I don’t want to do that on code that already takes at least three 
days to run.
I’ve already tried optimization coach on my code, but it didn’t have much help 
to give.


On May 4, 2015, at 7:01 AM, Robby Findler  wrote:

> Just in case: freezing an image requires actually rendering it but 
> constructing the image doesn't (it just builds a tree/dag matching fairly 
> closely to the image operations you used). So the time for constructing the 
> images can be pretty different than freezing them. 
> 
> Drawing a frozen image is a bitmap copy (and can be faster than rendering it 
> if it is a complex image) so freezing the intermediate ones might help if 
> intermediate ones are drawn many times. 

That’s why I started freezing these fractals. They were taking a long time to 
draw in DrRacket, and then taking a long time to save as an image file on my 
computer. So freezing them meant that it took a long time to freeze them, but 
after that both drawing them in DrRacket and saving them to my computer were 
quick. Plus I could use time to see how long it took to construct it versus 
freeze it.

The way I have it right now, I have a recursive function which uses a bunch of 
calls to scene+line, so I don’t have any points where there are intermediate 
images that are drawn many times that it would be helpful to freeze. I could 
restructure it to do that, but from the example in the docs, it looks like I’d 
loose sharpness, and the ability to control exactly where everything is, so 
that the things in all the different layers line up properly.


-- 
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] performance with freeze from 2htdp/image on very complex images

2015-05-03 Thread Alexander D. Knauth
I’m trying to use 2htdp/image to generate images of fractals.  

But while generating the images is “relatively” quick, it is freezing the 
images that’s taking a long time.
For the most complicated one, I started it running two nights ago, and the 
freeze operation on it still hasn’t finished.
For the next worst one, it takes about 21 times longer to freeze it than it 
takes to generate it.

Why is it taking so long to freeze these images, and is there anything I can do 
about it, like create the images in a certain way or give hints?

The code that generates these fractals is here:
https://github.com/AlexKnauth/koch-snowflake
(and it is racket code, in case you’re wondering)

For relatively small/simple fractals, freezing it takes anywhere from 1.5 to 
3.9 times longer than creating it.
For this one, freezing it takes a bit more than 3.5 times longer than creating 
it.
time(img-expr): cpu time: 186 real time: 185 gc time: 26
time(freeze(img)) : cpu time: 668 real time: 667 gc time: 31
For this, about 3.9 times longer:
time(img-expr): cpu time: 141 real time: 141 gc time: 22
time(freeze(img)) : cpu time: 549 real time: 549 gc time: 20

For a more complex fractal, about 21 times longer:
time(img-expr): cpu time: 18722 real time: 18807 gc time: 4304
time(freeze(img)) : cpu time: 400357 real time: 405312 gc time: 214723
And for this, about 18 times longer:
time(img-expr): cpu time: 8425 real time: 8547 gc time: 1203
time(freeze(img)) : cpu time: 152594 real time: 153001 gc time: 64968
And for this, about 17.8 times longer:
time(img-expr): cpu time: 27232 real time: 27264 gc time: 4254
time(freeze(img)) : cpu time: 485319 real time: 504408 gc time: 210964

For the worst one:
time(img-expr): cpu time: 2177463 real time: 2455108 gc time: 1189933
time(freeze(img)) : hasn’t finished yet
For this one, I started it two nights ago, and it’s still running.


-- 
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] Rosetta Code: Level 1st (that's FIRST) with TCL

2015-04-29 Thread Alexander D. Knauth
Would it make sense to implement solutions for #lang sweet-exp racket ?

Alex Knauth

On Apr 28, 2015, at 7:38 PM, Tim Brown  wrote:

> Folks,
> 
> I've just done a quick burst of cherry picking tasks on Rosetta
> Code (www.rosettacode.org). I took a quick look at:
> * http://rosettacode.org/wiki/Category:Tcl
> and
> *  http://rosettacode.org/wiki/Category:Racket
> 
> And they both have the line:
> "The following 845 pages are in this category, out of 845 total. "
> 
> I *think* that means that both Tcl and Racket have 845 tasks impemented,
> but short of walking down a printout with a pen (and it's far to late to
> be doing that) -- I do believe that Tcl and Racket are now jointly the
> most popular programming languages on Rosetta Code.
> 
> WELL DONE AND THANKS TO EVERYONE WHO HAS CONTRIBUTED (especially Racket)
> CODE ONTO ROSETTA CODE!
> 
> And many, many thanks to the Racket team for producing a language which 
> is now demonstrably as competent as any. (Although we all knew that before
> anyway, didn't we?)
> 
> Tim

-- 
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] Racketeer - Continuous Testing Plugin for DrRacket

2015-04-26 Thread Alexander D. Knauth
Well probably check-equal?, check-match, check-pred, check, and check-exn would 
be the main ones, with check-equal? probably being the most important, but what 
would be really cool would be something that could generalize over all rackunit 
checks, so that even checks defined with define-check, define-simple-check, and 
define-binary-check will work.
Maybe some of these could help?:
http://docs.racket-lang.org/rackunit/internals.html
http://docs.racket-lang.org/rackunit/internals.html#%28part._.Functions_to_.Run_.Tests%29

On Apr 26, 2015, at 7:44 PM, Mira Leung  wrote:

> On Sunday, April 26, 2015 at 6:18:41 AM UTC-7, Alex Knauth wrote:
>> Wow this is awesome!
>> Can you get to support rackunit too?
> 
> 
> Thanks Alex. Which rackunit test variants would you prioritize? 
> 
> -- 
> 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: off-topic --- Re: [racket-users] Racketeer - Continuous Testing Plugin for DrRacket

2015-04-26 Thread Alexander D. Knauth

On Apr 26, 2015, at 2:39 PM, Matthias Felleisen  wrote:

> 
> On Apr 26, 2015, at 9:18 AM, Alexander D. Knauth wrote:
> 
>> I wanted to see if it could work for tests within (module+ test …), and it 
>> does (even though check-expect doesn’t, which is weird for check-expect but 
>> awesome for this)
> 
> 
> Keep in mind that check-expect is supposed to work well for BSL, which is for 
> students who never programmed before. 

I know, but what’s weird about it is that without racketeer, the error message 
says:
. check-expect: found a test that is not at the top level in: (check-expect 1 2)
When the check-expect form is at the top level of the test submodule:
#lang racket
(require test-engine/racket-tests)
(module* test #f
  (check-expect 1 2))
And also that it works when the require form is inside the (module* test #f …) 
body:
#lang racket
(module* test #f
  (require test-engine/racket-tests)
  (check-expect 1 2)
  (test))
Why would it work for the second one but not the first one, and why would it 
give that error message?  That’s what I thought was weird.


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


  1   2   3   4   5   >