Re: [racket-users] Idiomatic way to include numbers in a map?

2017-03-03 Thread David Storrs
That's very cool.  Thank you, Matthew.

On Fri, Mar 3, 2017 at 6:50 PM, Matthew Butterick  wrote:

>
> On Mar 2, 2017, at 9:17 AM, David Storrs  wrote:
>
> I could, it's just extremely more verbose and therefore obfuscates what's
> actually going on as compared to the 'map' form.
>
>
> Why not turn it into a macro that preserves your preferred notation:
>
>
> #lang racket
> (struct foo (a b c) #:transparent)
> (define lst-A '(a b))
> (define lst-B '(d e))
>
> (require (for-syntax syntax/parse))
> (define-syntax (map-index stx)
>   (syntax-parse stx
> #:datum-literals (current-index)
> [(_ proc xs ... current-index ys ...)
>  (with-syntax ([(x-it ...) (generate-temporaries #'(xs ...))]
>[(y-it ...) (generate-temporaries #'(ys ...))])
>#'(for/list ([x-it (in-list xs)] ... [y-it (in-list ys)] ...
> [index (in-naturals)])
>(proc x-it ... index y-it ...)))]))
>
> (map-index
>  foo
>  lst-A
>  lst-B
>  current-index) ; ; (list (foo 'a 'd 0) (foo 'b 'e 1))
>
> (map-index
>  foo
>  current-index
>  lst-A
>  lst-B) ; (list (foo 0 'a 'd) (foo 1 'b 'e))
>
> --
> 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] change 'random' contract to allow zero in first position?

2017-03-03 Thread Ben Greenman
https://github.com/racket/racket/pull/1626

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


[racket-users] Re: create keyword in syntax

2017-03-03 Thread Dan Liebgold
On Friday, March 3, 2017 at 3:47:15 PM UTC-8, Dan Liebgold wrote:
> Is there something like format-id that can create a keyword in a syntax 
> transformer?
> 

Searching the interwebs yielded this:

  ;; identifier->keyword : Identifer -> (Syntaxof Keyword)
  (define (identifier->keyword id)
(datum->syntax id (string->keyword (symbol->string (syntax-e id))) id id))

which does what I need.

-- 
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] Idiomatic way to include numbers in a map?

2017-03-03 Thread Matthew Butterick

> On Mar 2, 2017, at 9:17 AM, David Storrs  wrote:
> 
> I could, it's just extremely more verbose and therefore obfuscates what's 
> actually going on as compared to the 'map' form.


Why not turn it into a macro that preserves your preferred notation:


#lang racket
(struct foo (a b c) #:transparent)
(define lst-A '(a b))
(define lst-B '(d e))

(require (for-syntax syntax/parse))
(define-syntax (map-index stx)
  (syntax-parse stx
#:datum-literals (current-index)
[(_ proc xs ... current-index ys ...)
 (with-syntax ([(x-it ...) (generate-temporaries #'(xs ...))]
   [(y-it ...) (generate-temporaries #'(ys ...))])
   #'(for/list ([x-it (in-list xs)] ... [y-it (in-list ys)] ...
[index (in-naturals)])
   (proc x-it ... index y-it ...)))]))

(map-index 
 foo
 lst-A
 lst-B
 current-index) ; ; (list (foo 'a 'd 0) (foo 'b 'e 1))

(map-index 
 foo
 current-index
 lst-A
 lst-B) ; (list (foo 0 'a 'd) (foo 1 'b 'e))

-- 
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] create keyword in syntax

2017-03-03 Thread Dan Liebgold
Is there something like format-id that can create a keyword in a syntax 
transformer?

Thanks,
Dan

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


Re: [racket-users] change 'random' contract to allow zero in first position?

2017-03-03 Thread 'John Clements' via Racket Users

> On Mar 3, 2017, at 12:02 PM, Daniel Prager  wrote:
> 
> 
> 
> On Sat, Mar 4, 2017 at 6:21 AM, John Clements  
> wrote:
> 
> > On Mar 2, 2017, at 3:00 PM, Daniel Prager  wrote:
> >
> > While we're at it, please allow negative arguments too, to allow for cases 
> > such as
> >
> > (random -100 100)
> 
> Well, that’s different; that’s actually changing the implementation. I’m not 
> proposing that…
> 
> 
> The implementation looks fine to me. In pre-base.rkt the relevant lines 
> should work fine with -ve arguments as long as the inequality constraint 
> holds. E.g.
> 
> (+ x (random (- y x)))  with x=-100, y=100
> -> (+ -100 (random 200))

Sure, sounds good to me; want to submit a pull request?

(NB: I speak for no one but myself, here.)

John


-- 
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] change 'random' contract to allow zero in first position?

2017-03-03 Thread Daniel Prager
On Sat, Mar 4, 2017 at 6:21 AM, John Clements 
wrote:

>
> > On Mar 2, 2017, at 3:00 PM, Daniel Prager 
> wrote:
> >
> > While we're at it, please allow negative arguments too, to allow for
> cases such as
> >
> > (random -100 100)
>
> Well, that’s different; that’s actually changing the implementation. I’m
> not proposing that…
>
>
The implementation looks fine to me. In pre-base.rkt the relevant lines
should work fine with -ve arguments as long as the inequality constraint
holds. E.g.

(+ x (random (- y x)))  with x=-100, y=100
-> (+ -100 (random 200))

Dan

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


Re: [racket-users] change 'random' contract to allow zero in first position?

2017-03-03 Thread 'John Clements' via Racket Users

> On Mar 2, 2017, at 2:06 PM, Jay McCarthy  wrote:
> 
> I think that the contract is overly specific on the 2 argument case.
> But on the 1 argument case, I don't think 0 makes sense:
> 
> "When called with an integer argument k, returns a random exact
> integer in the range 0 to k-1."[k <- 0]
> =_v
> "When called with an integer argument 0, returns a random exact
> integer in the range 0 to -1.”

Right; I’m not proposing a change to the one-argument case, only to the 
two-argument case.

John



-- 
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] change 'random' contract to allow zero in first position?

2017-03-03 Thread 'John Clements' via Racket Users

> On Mar 2, 2017, at 3:00 PM, Daniel Prager  wrote:
> 
> While we're at it, please allow negative arguments too, to allow for cases 
> such as
> 
> (random -100 100)

Well, that’s different; that’s actually changing the implementation. I’m not 
proposing that…

John



-- 
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 about how to number equations under scribble-math module

2017-03-03 Thread Matthew Flatt
There's not currently a direct way to do what you want, as far as I
know. There's a relevant library in `scriblib/private/counter`, which
is used to implement the counters for `scriblib/footnote` and
`scriblib/figure`. As "private" in the module name suggests, however,
it was never turned into something intended for public use.

You might want to look at that for ideas, or even use it despite the
fact that it's private and subject to change, or (best of all) help
create a public and documented version of the library.

At Fri, 24 Feb 2017 17:09:16 -0800 (PST), tachlithavayati wrote:
> Thanks to the writers of the scribble-math package.
> 
> It's great to have ready the commands for writing math with LaTeX under 
> Scribble.
> 
> My question: is there a practical way to add numbering to the equations in a 
> Scribble document with the support of the scribble.math package, and later to 
> be able to refer the equations with their corresponding number.
> 
> Thank you very much in advance.
> 
> Sincerely,
> 
> E. Cómer

-- 
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] raco test: 0 tests run, 1 test passed

2017-03-03 Thread Jay McCarthy
Hi Alex,

It is a bit confusing. There's a lot of history to the message.

It used to be that rackunit only had the test-suites, test-cases, and
the checks. It tries very hard to NOT count the checks as "tests".
Later, the checks were exposed so you didn't have to but them in
test-suites and test-cases, which always felt like painful boilerplate
to me.

Because of that history, the 3 successes message comes from "raco
test" which tracks how many "tests" were run. Since rackunit tries to
hide the checks, there's only the three test cases you wrote. The
second message about checks comes from rackunit which does it own
counting of checks.

My advice is to totally ignore the test-suite/test-case system of
rackunit and just write check-* forms in your (module+ test ...)
module.

Jay

On Thu, Mar 2, 2017 at 10:34 PM, Alex Harsanyi  wrote:
> On Friday, March 3, 2017 at 7:18:27 AM UTC+8, schuster wrote:
>> The problem is that a test-case expression runs a test immediately; it does 
>> not return a test object to be run later. In your case, the test runs while 
>> my-test-case is being defined, then no test at all actually runs 
>> (my-test-case is just #).
>
> I did figure out that I need to wrap test-cases in test-suites soon after I 
> posted the message, as it is usually the case :-).  Thanks for clarifying 
> that test-case runs immediately. In my case, the tests are in a separate file 
> and I only run the file when I want to run the tests, so it is hard to tell 
> the difference.
>
> I still think the output from "rack test" is somewhat confusing.  In one of 
> my test files the output is:
>
> raco test: (submod "test/df-test.rkt" test)
> 3 success(es) 0 failure(s) 0 error(s) 3 test(s) run
> 0
> 75 tests passed
>
> What the above means is that 3 test suites were run and there were 75 checks 
> in total (not sure what the line with the single 0 means).  However, the way 
> the message is printed out implies that 3 tests were run and 75 passed.  
> Perhaps the message could be updated to say:
>
>
> raco test: (submod "test/df-test.rkt" test)
> 3 success(es) 0 failure(s) 0 error(s) 3 test suite(s) run
> 0
> 75 checks passed
>
> Best Regards,
> Alex.
>
> --
> 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.



-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

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